Re: How do I know ECONNREFUSED from non-blocking connect?
From: Steve (postmaster_at_127.0.0.1)
Date: 11/07/03
- Next message: Maurizio Loreti: "Re: History of gettext() et al?"
- Previous message: Barry Margolin: "Re: library for whois ???"
- In reply to: Grant Taylor: "Re: How do I know ECONNREFUSED from non-blocking connect?"
- Next in thread: Grant Taylor: "Re: How do I know ECONNREFUSED from non-blocking connect?"
- Reply: Grant Taylor: "Re: How do I know ECONNREFUSED from non-blocking connect?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 07 Nov 2003 22:08:23 GMT
On 7/11/03 7:39 pm, in article uc65hwdl2v.fsf@habanero.picante.com, "Grant
Taylor" <gtaylor+cup_cdgie110703@picante.com> wrote:
> Steve <postmaster@127.0.0.1> writes:
>
>> If I try a connect() on a non-blocking socket; how can I determine the error
>> ECONNREFUSED or ETIMEDOUT.
>>
>> Should I get the socket option SO_ERROR after my select() call tells me
>> something has happened?
>
> Yes, exactly.
>
> Note that, on Linux at least, you should not check the error value
> before the socket is reported as writable. Before the socket reports
> as writable, reading the error value gives no error, not even
> EINPROGRESS as you might expect. This is in fact indistiguishable
> from "happy connect", even when in fact the socket is not connected.
It'll be Mac OS X, actually.
> Similarly most any other socket operations will destroy the value, so
> don't go reading or writing if you really want to know what the
> connect result was.
OK.
> IMHO, this interface is slightly irritating; if your event reporter is
> in fact any sort of edge-triggered completion notification (such as
> pre-2.6 linux epoll, or most of the signal-based schemes) it is
> necessary to plug the socket fd into your interest set *between* the
> socket() and connect() calls - something many higher-level libraries
> make painful, since traditionally one does select or poll, where it
> doesn't matter.
I am actually writing a higher-level library! :)
The connect() is done in one thread, and the blocking select() is done in
another thread, so I can't guarantee that select() will be called before or
after connect().
Hmmm ... I hope the socket API is thread safe?
Steve.
- Next message: Maurizio Loreti: "Re: History of gettext() et al?"
- Previous message: Barry Margolin: "Re: library for whois ???"
- In reply to: Grant Taylor: "Re: How do I know ECONNREFUSED from non-blocking connect?"
- Next in thread: Grant Taylor: "Re: How do I know ECONNREFUSED from non-blocking connect?"
- Reply: Grant Taylor: "Re: How do I know ECONNREFUSED from non-blocking connect?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|