0
votes

ALL, I am looking for a simple example of non-blocking socket connection that will run on Windows. I tried to Google, but all samples are either for *nix (POSIX) or blocking sockets on Windows.

Looking thru msdn I see that it is easy to make a socket non-blocking and issue a connect(), but then you need some preparation in order to put the socket back.

So, all in all I need something on a non-blocking socket that will connect and then put it back to be blocking. The read and write operation should be performed on the blocking socket.

The reason for a non-blocking socket is that I need a connection timeout and there is no other way than non-blocking socket. Or is there?

Thank you.

1
That's not the only way. You could also run the connect operation in another thread. Then you can wait or not wait for it however you like for as long as you like. - David Schwartz
@DavidSchwartz, Good solution, but not for me. ;-) I am trying to connect for different devices at the same time each of which will be on its own thread. If I will spawn a thread just for connecting whoever will look at the code after me will be lost. And I might be lost myself. Besides the project target OS is Linux (maybe even QNX - real-time). Winidows will be just for demo. Thank you. - Igor
If the connections are going to be on their own thread anyway, why not have that thread just do the connection operation as well? - David Schwartz
@DavidSchwartz, What do you mean? Can you put some code please? Thank you. - Igor

1 Answers

0
votes

Use ACE socket wrapper facade and apply your Linux knowledge in full.