× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jane,
I found 2 ways of implementing a timeout check with sockets.
One is to set up a signal handler and an alarm(timeout_delay) then issue
the recv() and have an alarm signaled when timeout occurs.
The other way is pass the socket descriptor and timeout delay to the poll()
API, then check poll's return code, if there is data waiting, issue the
recv().

There are samples of the signal handler and alarm on the internet.

I did not find any samples of poll's use on the internet so I will include
mine here.
Here is my /copy prototype for poll(), it has a code snip in comments.

***Code begin

*- Poll() - Wait for Events on Multiple Descriptors - alternative to
select()
*

* int poll(struct pollfd fds[], * pointer to array of data
structures
* nfds_t nfds, 10i 0 number of elements in array

* int timeout) 10i 0 timeout (in milliseconds)

*

*

* following is sample code for how to use and check a single socket

* /free

*

* //- set poll() parameters

* fds.fd = SD; //-- socket descriptor

* fds.req_events = POLLIN; //- something to read?

* fds.rtn_events = 0;

* //- poll_timeout is defaulted to 5 seconds (5000ms)

*

* //- use poll() to check if socket has anything waiting to be read.

* RC = Poll( fds_ptr : fds_index : timeout_ms );

* if RC < 0;

* //- connection error or other unexpected error

* elseif RC = 0;

* //-- connection timeout

* else;

* //-- RC > 0 means there is something waiting to be read

* //-- for this instance this should always be 1 since we

* //-- only have 1 socket descriptor open

* endif;

*

* /end-free

*



D Poll PR 10i 0 ExtProc('poll')

D fds_ptr * Value

D fds_index 10i 0 Value

D poll_timeout 10i 0 Value



D fds DS Qualified Inz

D FD 10i 0

D req_events 5i 0

D rtn_events 5i 0



D fds_ptr S * Inz(%addr(fds))

D fds_index S 10i 0 Inz(1)
check only 1 SD
D poll_timeout S 10i 0 Inz(5000) 5
second timeout


* following constants were found in /usr/include/sys/poll.h

D POLLIN C const(x'0001')
ready for reading
D POLLOUT C const(x'0002')
ready for writing
D POLLERR C const(x'4000')
error occured
D POLLNVAL C const(x'8000')
invalid descriptor



***Code end

Charlie



-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Jane Taubman
Sent: Wednesday, September 18, 2013 5:51 PM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: TCP/IP Buffer to variable in Scott Klement's sample

Sounds promising if you can find it, I would appreciate a sample


On 18 September 2013 20:53, Charles Brewster
<charles.m.brewster@xxxxxxxxx>wrote:

Jane,

I had the same issue of wanting to know if there was anything to read
before I actually committed to reading the socket descriptor. Since
the read does not have a timeout parm, if you commit to read and there
is nothing there, you are stuck.

I used the API called poll() to check the status of the descriptor
before I issued the recv()

Poll() is a little tricky because it expects a pointer to an array of
descriptors and the status of each descriptor you want to check,
rather than a single descriptor and status. Then it return the number
of descriptor that match the status you ask for.


If you think it will work for you I can track down my prototype and a
snip of code.

Charlie




-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Jane Taubman
Sent: Wednesday, September 18, 2013 2:57 AM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: TCP/IP Buffer to variable in Scott Klement's sample

Thanks all, I ended up using the %SUBST on the recbuf field and used
it's length to eval the data into the Q field and that seemed to fix
the problem,

I have a second problem if anyone knows a quick answer. The readln()
function waits for data to arrive, but I need to be able to check for
data arriving with out waiting, eg


While socket open do
if data in buffer then
readline
else
read down data Queue don't wait
if data then send down socket
end
end

Does anyone know how I can check for data with out reading it.

Thanks again for the help
--
Jane.
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/rpg400-l.


--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/rpg400-l.




--
Jane.

Jane Taubman | www.rjt.org.uk | www.taubman.org.uk |www.fhug.org.uk
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.