Controlling time out for a socket connection
How can I control the timeout for a socket connection? My sockets functions are written in C in a service program. I have tried using signal and alarm, but they kill the AS/400 job without returning control to the socket program.
My assumption is that you are referring to a block receive operation, that is you are trying to receive something from the partner program, but nothing is received and your program waits forever.
In my opinion the most flexible socket option to control your program is using the select API, which allows you to wait for the socket and specify a timeout (you can also issue a non-blocked receive, but it is, in my opinion, the wrong approach).
This page describes the select API very well. It discuss mainly the server, but you can also use it on your client with no problem.
This was first published in June 2005