0

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.

Arno
  • 4,994
  • 3
  • 39
  • 63
Igor
  • 5,620
  • 11
  • 51
  • 103
  • 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 Oct 26 '12 at 23:12
  • @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 Oct 27 '12 at 02:23
  • 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 Oct 27 '12 at 07:08
  • @DavidSchwartz, What do you mean? Can you put some code please? Thank you. – Igor Oct 29 '12 at 17:21

1 Answers1

0

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

bobah
  • 18,364
  • 2
  • 37
  • 70
  • Thanks for the answer. Unfortunately I prefer to use native solution without any additional libraries. Besides it might not have compatible license. – Igor Oct 29 '12 at 17:19
  • @Igor - just download it and see how it wraps socket IO on Windows, do not necessarily use it – bobah Oct 29 '12 at 22:51