Archived

This topic is now archived and is closed to further replies.

stodge

Asynchronous connect question in winsock

Recommended Posts

If a client tries to connect() to a server that isn''t running, will the connect() call return EWOULDBLOCK? If so, do I call connect() again to try to establish the connection, or will I get notification from using the write socket set with select()? Thanks

Share this post


Link to post
Share on other sites
I would have thought that it would return ECONNREFUSED.

Edit: Or ETIMEDOUT.

[edited by - SiCrane on November 6, 2002 10:19:16 PM]

Share this post


Link to post
Share on other sites
Me too.

The problem I have is that I''m using select() to determine when the connection is established asynchronously (i.e. ready for write). However, I presume because the server never accepts the connection, select() doesn''t detect that the socket is ready for writing.

I hope that makes sense!

Share this post


Link to post
Share on other sites
Here''s the bad news, AFAIK, there is no good way to determine if a socket failed to connect using standard BSD socket calls. On *NIX systems you can poll to see if there was a connection by using repeated connect() calls and seeing if the result was EALRADY or EISCONN, but the problem with that is that polling in that manner will just try to initiate another connection request. More workable is just to assign a timeout and if the socket hasn''t returned writable on select() in that time, give up on the connection. On Windows you can use WSAAsyncSelect or WSAEventSelect to check for failed connections because they both return FD_CONNECT when the call is completed either with success or failure. On the other hand, I believe the XTI API on *NIX platforms will also return a notification when a connection is failed. (Grain of salt on that one, I haven''t used XTI in over two years.) Or just use blocking socket operations for the connect().

Share this post


Link to post
Share on other sites
Damn, that''s not what I want to hear.

I''m not using MFC (this is WSAAsyncSelect right?), so I guess I''m screwed.

Share this post


Link to post
Share on other sites
quote:
Original post by stodge
I'm not using MFC (this is WSAAsyncSelect right?), so I guess I'm screwed.

the mouse cursor must be using MFC, so i guess i'm screwed if i want to have it move fast.

oh wait, did i forget to check whether everything was MFC or only some code was?

edit: hmm, maybe only things that start with a capital letter are MFC?

[edited by - niyaw on November 6, 2002 11:25:54 PM]

Share this post


Link to post
Share on other sites
WSAAsyncSelect and WSAEventSelect are Winsock functions; no MFC required. I think WSAEventSelect is only Winsock 2 though. In any case select() is almost broken in the windows implementation, so you''d be better off using either of those functions in general principle anyways.

Share this post


Link to post
Share on other sites