cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: connect failed if set socket non-blocking,why?

From: Andy Hobbs <andy_at_hobbs.uk.net>
Date: Mon, 25 Oct 2004 10:45:44 +0100

Hi,

connect returns instantly when the socket is non-blocking, you need to
call select() and wait for the connect to complete.

Andy

On Mon, 2004-10-25 at 09:57, 黄志军 wrote:
> I link my program with static library libcurl.a and find it always
> return CURLE_COULDNT_CONNECT.
>
> if i ignore function Curl_nonblock() in connect.c( curl-7.12.2), the
> curl_easy_perform return success and works fine.
>
> But if set socket to non-blocking, the connect() return -1(rc = -1)
>
> and i got the following info: "errno in curl=0" and "errno out
> curl=150", why?
>
>
> /*../lib/connect.c*/
> /* set socket non-blocking */
> Curl_nonblock(sockfd, TRUE);
>
> rc = connect(sockfd, ai->ai_addr, ai->ai_addrlen);
>
> fprintf(stderr, "errno in curl=%d\n", errno);
>
> if(-1 == rc) {
> error = Curl_ourerrno();
> fprintf(stderr, "errno in curl=%d\n", errno);
>
>
> /*my multi-thread program:*/
> curl_easy_perform(curl);
> fprintf(stderr, "errno out curl=%d\n", errno);
>

-- 
Andy Hobbs <andy_at_hobbs.uk.net>
Received on 2004-10-25