|
If you REALLY can't use non-blocking through out the app, do it like this: 1) Set socket to non-blocking 2) connect() 3) select() until socket is writable (tells you that connect() is done) or a timeout. 4) Set socket back to blocking. Changing your code from blocking to non-blocking shouldn't be a big deal, though. Here's a quick & dirty way: 1) Set socket to non-blocking at the start 2) Create a recvb() (or whatever) subprocedure that uses select() on a non-blocking socket so that it works the same as recv() would on a blocking socket. 3) Do a sendb() the same way. 4) do a global replace of "recv(" to "recvb(" and "send(" to "sendb(" 5) Now, with the exception of connect(), your non-blocking socket behaves the same was as your blocking socket did. I should add some of these things to my tutorial. People frequently ask me how to make things time out. Clearly, I didn't document that well. On Mon, 4 Mar 2002, David Gibbs wrote: > Folks: > > Does anyone know if it's possible to set a timeout on a TCP/IP connect? > > My research indicates that there is no easy way to do this ... I found > http://www.developerweb.net/sock-faq/detail.php?id=36 which talks about > setting the socket into non-blocking mode, which I really don't want to do > at this point (it would change my applications structure more than I'm > willing to deal with now). > > Thanks! > > david >
As an Amazon Associate we earn from qualifying purchases.
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.