× 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.



I have the following code:
// 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 variable)
// 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

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.