|
Hi Ian, > Does anyone know which (if any) parameter controls the timeout value for the > connect() function in Scott's sockutilr4 server program ? > It currently waits for about a minute (I've not exactly timed it) before > returning an error that the remote host is not answering. > > I want to get it down to about 10 secs. Timeouts in sockets applications are controlled by using the select() API. In the case of connect(), you do the following: 1) Call socket() API 2) Use fcntl() to make the socket non-blocking 3) Call connect(). Usually you'll get an error that tells you that the connection is "in progress" (EINPROGRESS). Make sure that you check errno so that any "real" errors are detected. 4) call select() to wait until the connection is WRITEABLE. (that's the weird thing about connect, the socket has to be writeable) You can set your timeout on the select() call. 5) If a timeout occurred on the select() call, make sure you call close() so that the connection attempt is aborted and the resources are returned to the system. 6) If a timeout did not occur, I usually call connect() again to see if the connection was successful. If so, connect() will return a "already connected" (EISCONN) error. If you'd like to see a working example, take a look at the http_conn() subprocedure of HTTPAPI. (In fact, you could probably just call that routine instead of the one in SOCKUTILR4) http://www.scottklement.com/httpapi/ After you've connected, you can put the socket back into blocking mode if you're worried about it affecting the rest of the application -- though a better idea is to simply call select() before you do any recv() or send() calls. That way you can have timeouts in all aspects of the program, and never have the program "get stuck" if anything goes wrong.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.