Code Sinnpet:
int CreateaTCPSocket()
{
int iSockID = ACE_OS::socket(......);
ACE_OS::set_flags(iSockID,O_NONBLOCK);
ACE_OS::bind();
if (ACE_OS::connect(iSockID ,....) < 0)
{
if (ACE_OS::select(.....,timeout) <= 0)
{
return INVALID_HANDLE;
}
}
return iSockID;
}
My question is when connect is failed for non-block error and select is called and say select return success then again we need to call connect or select function internal do connect?
For both blocking and non-blocking sockets you only need to call
connect()
once.When the socket is non-blocking and
connect()
returnsEINPROGRESS
it needs to wait till the socket becomes ready for write usingselect()
. Whenselect()
reports that socket is ready for write it can be either thatconnect()
succeeded or failed.To check whether a non-blocking
connect()
succeeded you can callgetsockopt(..., SOL_SOCKET, SO_ERROR, ...)
that reports non-zero error on failure, or callgetpeername()
which only succeeds on a connected socket.