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



Hello,


Anybody know how to set time out on recv()? (connection Oriented).


Two ways:  Signals and Select().

With signals, you call an API prior to calling recv() that will send you a signal in a few seconds. For example, if you want recv() to time out after 5 seconds, you say "send me a SIGALRM signal after 5 seconds".

Then you call recv().

If the signal gets received before any data does, the recv() API will return -1 and errno will be set to EINTR to indicate that it was interrupted by a signal.

I've demonstrated this with the connect() API in the following program. The same technique should work for recv() as well.
http://www.iseriesnetwork.com/noderesources/code/clubtechcode/ChkSvr.zip

An updated copy of the SIGNAL_H member that works with V5R1 can be found here:
http://www.scottklement.com/rpg/signal_h.rpgle


The SELECT() method:

The idea here is that you always call select() prior to calling recv(). Select() will tell you if there's any data to read, and can wait until some arrives.

So, you create a "read set" for select() containing only the one socket. You call select() specifying that read set, and a timeout value. It'll wait until data has arrived, or until the timeout occurs.

If data WAS received, you then go ahead and call recv() to load that data into a variable. If not, you do whatever you plan to do when something times out.

There are samples of this in the RPG400-L archives.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.