+#if defined( WIN32 ) || defined( UNDER_CE )
+ if( WSAGetLastError() == WSAEWOULDBLOCK )
+#elif defined( HAVE_ERRNO_H )
+ if( errno == EINPROGRESS )
+#else
+ if( 0 )
+#endif
+ {
+ int i_ret;
+ int i_opt;
+ int i_opt_size = sizeof( i_opt );
+ struct timeval timeout;
+ fd_set fds;
+
+ msg_Dbg( p_this, "connection in progress" );
+ do
+ {
+ if( p_this->b_die )
+ {
+ msg_Dbg( p_this, "connection aborted" );
+ goto error;
+ }
+
+ /* Initialize file descriptor set */
+ FD_ZERO( &fds );
+ FD_SET( i_handle, &fds );
+
+ /* We'll wait 0.1 second if nothing happens */
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000;
+
+ } while( ( i_ret = select( i_handle + 1, NULL, &fds, NULL,
+ &timeout ) ) == 0 ||
+#if defined( WIN32 ) || defined( UNDER_CE )
+ ( i_ret < 0 && WSAGetLastError() == WSAEWOULDBLOCK ) );
+#elif defined( HAVE_ERRNO_H )
+ ( i_ret < 0 && errno == EINTR ) );
+#else
+ ( i_ret < 0 ) );
+#endif
+
+ if( i_ret < 0 )
+ {
+ msg_Warn( p_this, "cannot connect socket (select failed)" );
+ goto error;
+ }
+
+ if( getsockopt( i_handle, SOL_SOCKET, SO_ERROR, (void*)&i_opt,
+ &i_opt_size ) == -1 || i_opt != 0 )
+ {
+ msg_Warn( p_this, "cannot connect socket (SO_ERROR)" );
+ goto error;
+ }
+ }
+ else
+ {
+#if defined( HAVE_ERRNO_H )
+ msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) );
+#else
+ msg_Warn( p_this, "cannot connect socket" );
+#endif
+ goto error;
+ }