-wxSocketError wxSocketImplUnix::DoHandleConnect(int ret)
-{
- /* We only call EnableEvents() if we know we aren't shutting down the socket.
- * NB: EnableEvents() needs to be called whether the socket is blocking or
- * non-blocking, it just shouldn't be called prior to knowing there is a
- * connection _if_ blocking sockets are being used.
- * If connect above returns 0, we are already connected and need to make the
- * call to EnableEvents() now.
- */
- if ( m_non_blocking || (ret == 0) )
- EnableEvents();
-
- if (ret == -1)
- {
- const int err = errno;
-
- /* If connect failed with EINPROGRESS and the wxSocketImplUnix object
- * is in blocking mode, we select() for the specified timeout
- * checking for writability to see if the connection request
- * completes.
- */
- if ((err == EINPROGRESS) && (!m_non_blocking))
- {
- if ( !BlockForOutputWithTimeout() )
- {
- Close();
- return wxSOCKET_TIMEDOUT;
- }
-
- int error;
- SOCKOPTLEN_T len = sizeof(error);
-
- getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char*) &error, &len);
- EnableEvents();
-
- if (!error)
- return wxSOCKET_NOERROR;
- }
-
- /* If connect failed with EINPROGRESS and the wxSocketImplUnix object
- * is set to nonblocking, we set m_error to wxSOCKET_WOULDBLOCK
- * (and return wxSOCKET_WOULDBLOCK) but we don't close the socket;
- * this way if the connection completes, a wxSOCKET_CONNECTION
- * event will be generated, if enabled.
- */
- if ((err == EINPROGRESS) && (m_non_blocking))
- {
- m_establishing = true;
- m_error = wxSOCKET_WOULDBLOCK;
- return wxSOCKET_WOULDBLOCK;
- }
-
- /* If connect failed with an error other than EINPROGRESS,
- * then the call to Connect has failed.
- */
- Close();
- m_error = wxSOCKET_IOERR;
-
- return wxSOCKET_IOERR;
- }
-
- return wxSOCKET_NOERROR;
-}
-