|
I have the following code:variable)
// nbrecv(): Receive data on non-blocking socket w/timeout
// using Select()
// sock = (input) socket to receive data from
// buf = (output) buffer to receive into (address of
// size = (input) size of buffer to send (size of variable)//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// secs = (input) seconds to wait before timing out
//
// Returns length received, or -1 upon failure (check errno!)
P nbrecv B export
D nbrecv pi 10i 0
D sock 10i 0 value
D buf * value
D size 10i 0 value
D secs 10p 3 value
D readset s like(fdset)
D timeout ds likeds(timeval)
D err s 10i 0 based(p_err)
D rc s 10i 0
/free
p_err = sys_errno();
dow '1';
rc = recv(sock: buf: size: 0);
if (rc <> -1);
return rc;
endif;
if (err <> EWOULDBLOCK);
return rc;
endif;
// -----------------------------------
// Wait until socket is readable
// -----------------------------------
FD_ZERO(readset);
FD_SET(sock: readset);
timeout.tv_sec = %int(secs);
timeout.tv_usec = (secs - timeout.tv_sec) * 1000000;
rc = select( sock+1 // descriptor count
: %addr(readset) // read set
: *null // write set
: *null // exception set
: %addr(timeout) ); // timeout
select;
when rc = 0;
err = ETIME;
return -1;
when rc = -1;
return -1;
endsl;
enddo;
/end-free
P E
I am passing a value of 60 for the wait time.
Is this routine correct?
shouldn't the set of the wait time come first?
Jeff Young
Sr. Programmer Analyst
--
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 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.