Skip to main content
GameDev.net gamedev.net
🔒 Locked

Non-blocking connect()?

Started by peter_b Sep 15, 2006 at 3:39 AM 2 replies 1.7k views
Original Post
peter_b
peter_b
Hello. Is there anything i can do to know when a non-blocking connect finishes? I need to know when the connection is accepted or if it times out. Im using berkely socket functions only, not winsock asyncronus functions. So i guess there must be a way to poll the socket with select() or something. But how do i know if the connection was accepted, timedout, or rejected? Thanks in advance.
Shields up! Rrrrred alert!
TUna
TUna
Use "select" to determine if the socket is write ready or in an error state.
zppz
zppz
It's also possible to use non-blocking sockets. Just keep calling connect() and handle the errors appropriately:
The first call will probably return WOULDBLOCK or INPROGRESS which is fine, after that you will get INVAL or ALREADY which can be ignored. When the connection succeeds you will get ISCONN, then you can stop calling connect() and start using the socket.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.