winhttp(1/2): Implement connect timeout (try 2)

Alexandre Julliard julliard at winehq.org
Thu Jul 23 04:41:54 CDT 2009


Juan Lang <juan.lang at gmail.com> writes:

> -BOOL netconn_connect( netconn_t *conn, const struct sockaddr *sockaddr, unsigned int addr_len )
> +BOOL netconn_connect( netconn_t *conn, const struct sockaddr *sockaddr, unsigned int addr_len, int timeout )
>  {
> -    if (connect( conn->socket, sockaddr, addr_len ) == -1)
> +    int res, state;
> +
> +    if (timeout > 0)
> +    {
> +        state = 1;
> +        res = ioctlsocket( conn->socket, FIONBIO, &state );
> +    }
> +    res = connect( conn->socket, sockaddr, addr_len );
> +    if (res == -1 && (errno == EINPROGRESS || errno == EAGAIN))
> +    {
> +        struct pollfd pfd;
> +
> +        pfd.fd = conn->socket;
> +        pfd.events = POLLOUT;
> +        res = poll( &pfd, 1, timeout );
> +    }

You also need to replace the errno check with the equivalent winsock
errors, and you need to correctly check the result of the poll.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list