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



Charlie,

The best way to implement timeouts in socket programming is by

1) Setting your socket to non-blocking mode
2) Using the select() API to wait for data (or to time out.)

The alarm() API also works in most circumstances, but I've found cases where there are conflicts. For example, Apache uses signals and signal handlers, so if you try to use alarm in an Apache instance (alarm is also signal based) Apache will block the signal to your application.

So the select() (or poll) API is the way to go. Can you explain why you think select is only appropriate for server applications? (that is not the case, imho)

I strongly recommend encapsulating your timeout logic into a routine like readWithTimeout() or something like that so that when you want to tweak/improve/change the way the timeout logic works, you have only one place to change it.

Here's an article that demonstrates both ways of timing out (select and alarm). Unfortunately, the formatting has gotten screwed up over the years (today's iProDeveloper is a hot mess)
http://iprodeveloper.com/rpg-programming/timeouts-sockets

Click the "Print" button to improve the code formatting.

-SK


On 1/12/2016 3:22 PM, Charles Guarino wrote:



This is from one of our field programmers.


"We have an interactive socket program that connects to a host system that sends and receives data.

If something happens to the connection while the interactive client program is receiving or waiting to receive data, the program just hangs on the receive api. It never ends. We tried to use the Socket Option SO_RCVTIMEO, but when setting it, it returns an error 3021 - "Value specified for the argument is not correct."



We have found articles saying not the use this method, but to use the alarm signal or select API to perform timeouts on sockets. Since our program is a client side socket program we thought the select API would not be appropriate and proceeded to code the socket program to use the alarm signals.



After researching it and reviewing some code examples, we added the logic to the program. When the program runs with the alarm signal logic, when the time out interval is reached the interactive session is ended and the user is put back to a sign on screen.



Does anyone know the best way to handle a time out while waiting for data to be received by an interactive client socket program, using RPGLE?"



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.