comp.lang.ada
 help / color / mirror / Atom feed
* Gnat.Sockets and non-blocking connects
@ 2003-06-29 12:26 Jano
  2003-06-29 13:42 ` Florian Weimer
  0 siblings, 1 reply; 12+ messages in thread
From: Jano @ 2003-06-29 12:26 UTC (permalink / raw)


Hello!

I posted some time ago about non-blocking connects, and all went well. 
However, I have faced a new necessity I'm not sure how to address.

I'm trying to determine if a asynchronous connect has failed. When it 
ends successfully, I detect it with a select checking for writeability. 
However, it seems I must check the exception set to detect failure. 

The problem is that Gnat.Sockets doesn't implement the exception 
selector in its Select.

Any workarounds? I can't figure one right now.

TIA,

-- 
-------------------------
Jano
402450.at.cepsz.unizar.es
-------------------------



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 12:26 Gnat.Sockets and non-blocking connects Jano
@ 2003-06-29 13:42 ` Florian Weimer
  2003-06-29 14:17   ` Samuel Tardieu
  0 siblings, 1 reply; 12+ messages in thread
From: Florian Weimer @ 2003-06-29 13:42 UTC (permalink / raw)


Jano <nono@celes.unizar.es> writes:

> I'm trying to determine if a asynchronous connect has failed. When it 
> ends successfully, I detect it with a select checking for writeability. 
> However, it seems I must check the exception set to detect failure. 

No, this is a misunderstanding.  The exception set is not for error
reporting, but for exceptional situations.

Errors are reported by the R/W selectors.  However, nonblocking
connect error reporting is not portable, see Steven's UNIX Network
Programming.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 13:42 ` Florian Weimer
@ 2003-06-29 14:17   ` Samuel Tardieu
  2003-06-29 14:29     ` Florian Weimer
  0 siblings, 1 reply; 12+ messages in thread
From: Samuel Tardieu @ 2003-06-29 14:17 UTC (permalink / raw)


>>>>> "Florian" == Florian Weimer <fw@deneb.enyo.de> writes:

Florian> Errors are reported by the R/W selectors.  However,
Florian> nonblocking connect error reporting is not portable, see
Florian> Steven's UNIX Network Programming.

In practice, it *is* portable.

Jano, you need to check the write set, and try to connect again. You
will get an error. If the error is EISCONN, you *are* connected. If
this is anything else, you *aren't*.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 14:17   ` Samuel Tardieu
@ 2003-06-29 14:29     ` Florian Weimer
  2003-06-29 18:07       ` Jano
  0 siblings, 1 reply; 12+ messages in thread
From: Florian Weimer @ 2003-06-29 14:29 UTC (permalink / raw)
  Cc: sam

Samuel Tardieu <sam@rfc1149.net> writes:

>>>>>> "Florian" == Florian Weimer <fw@deneb.enyo.de> writes:
>
> Florian> Errors are reported by the R/W selectors.  However,
> Florian> nonblocking connect error reporting is not portable, see
> Florian> Steven's UNIX Network Programming.
>
> In practice, it *is* portable.

The SO_ERROR socket option is implemented in two different ways.

> Jano, you need to check the write set,

Correct.

> and try to connect again. You will get an error. If the error is
> EISCONN, you *are* connected. If this is anything else, you
> *aren't*.

Unfortunately, you don't get the error code in this case.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 14:29     ` Florian Weimer
@ 2003-06-29 18:07       ` Jano
  2003-06-29 20:50         ` Florian Weimer
  0 siblings, 1 reply; 12+ messages in thread
From: Jano @ 2003-06-29 18:07 UTC (permalink / raw)


Florian Weimer dice...
> Samuel Tardieu <sam@rfc1149.net> writes:
> 
> >>>>>> "Florian" == Florian Weimer <fw@deneb.enyo.de> writes:
> >
> > Florian> Errors are reported by the R/W selectors.  However,
> > Florian> nonblocking connect error reporting is not portable, see
> > Florian> Steven's UNIX Network Programming.
> >
> > In practice, it *is* portable.
> 
> The SO_ERROR socket option is implemented in two different ways.
> 
> > Jano, you need to check the write set,
> 
> Correct.
> 
> > and try to connect again. You will get an error. If the error is
> > EISCONN, you *are* connected. If this is anything else, you
> > *aren't*.
> 
> Unfortunately, you don't get the error code in this case.

Mmm, I've found two workarounds for Windows:

* Trying to connect again will give an error while connecting, or will 
return again Operation_would_block (that means you have failed and are 
trying again, so it's kinda lame solution).

* Getting the remote address of the socket gives two different errors 
when connecting and failed.

Remember, I have no problem detecting the connection is successful. (My 
comments about the exception set were taken directly from the Windows 
help for Select).

However, I suppose that will not work in Linux. Oh well, really I hope 
these folks can get right a nice networking package for 0Y.

-- 
-------------------------
Jano
402450.at.cepsz.unizar.es
-------------------------



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 18:07       ` Jano
@ 2003-06-29 20:50         ` Florian Weimer
  2003-06-29 21:13           ` Samuel Tardieu
  2003-06-29 23:00           ` Jano
  0 siblings, 2 replies; 12+ messages in thread
From: Florian Weimer @ 2003-06-29 20:50 UTC (permalink / raw)


Jano <nono@celes.unizar.es> writes:

>> Unfortunately, you don't get the error code in this case.
>
> Mmm, I've found two workarounds for Windows:
>
> * Trying to connect again will give an error while connecting, or will 
> return again Operation_would_block (that means you have failed and are 
> trying again, so it's kinda lame solution).
>
> * Getting the remote address of the socket gives two different errors 
> when connecting and failed.

Even on Windows, you can use getsockopt(2) and SO_ERROR.  No need to
jump through hoops. 8-)



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 20:50         ` Florian Weimer
@ 2003-06-29 21:13           ` Samuel Tardieu
  2003-06-29 21:27             ` Florian Weimer
  2003-06-29 23:00           ` Jano
  1 sibling, 1 reply; 12+ messages in thread
From: Samuel Tardieu @ 2003-06-29 21:13 UTC (permalink / raw)


>>>>> "Florian" == Florian Weimer <fw@deneb.enyo.de> writes:

Florian> Even on Windows, you can use getsockopt(2) and SO_ERROR.  No
Florian> need to jump through hoops. 8-)

Even on Windows, you do not need to use SO_ERROR :) Just test
connect() return code.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 21:13           ` Samuel Tardieu
@ 2003-06-29 21:27             ` Florian Weimer
  2003-06-29 22:38               ` Samuel Tardieu
  0 siblings, 1 reply; 12+ messages in thread
From: Florian Weimer @ 2003-06-29 21:27 UTC (permalink / raw)


Samuel Tardieu <sam@rfc1149.net> writes:

>>>>>> "Florian" == Florian Weimer <fw@deneb.enyo.de> writes:
>
> Florian> Even on Windows, you can use getsockopt(2) and SO_ERROR.  No
> Florian> need to jump through hoops. 8-)
>
> Even on Windows, you do not need to use SO_ERROR :) Just test
> connect() return code.

It's EINPROGRESS.  Pretty informative, isn't it?

BTW, "Cc: sam@rfc1149.net" deliberately bounces.  You might want to
fix your mail/news setup.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 21:27             ` Florian Weimer
@ 2003-06-29 22:38               ` Samuel Tardieu
  2003-06-29 23:00                 ` Jano
  0 siblings, 1 reply; 12+ messages in thread
From: Samuel Tardieu @ 2003-06-29 22:38 UTC (permalink / raw)


>>>>> "Florian" == Florian Weimer <fw@deneb.enyo.de> writes:

Florian> It's EINPROGRESS.  Pretty informative, isn't it?

It's never EINPROGRESS if you wait until the corresponding bit is set
by select in the write set.

Florian> BTW, "Cc: sam@rfc1149.net" deliberately bounces.  You might
Florian> want to fix your mail/news setup.

It doesn't bounce.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 20:50         ` Florian Weimer
  2003-06-29 21:13           ` Samuel Tardieu
@ 2003-06-29 23:00           ` Jano
  2003-06-30 15:07             ` Jano
  1 sibling, 1 reply; 12+ messages in thread
From: Jano @ 2003-06-29 23:00 UTC (permalink / raw)


Florian Weimer dice...
> Jano <nono@celes.unizar.es> writes:
> 

> Even on Windows, you can use getsockopt(2) and SO_ERROR.  No need to
> jump through hoops. 8-)

I must look at that!



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 22:38               ` Samuel Tardieu
@ 2003-06-29 23:00                 ` Jano
  0 siblings, 0 replies; 12+ messages in thread
From: Jano @ 2003-06-29 23:00 UTC (permalink / raw)


Samuel Tardieu dice...
> >>>>> "Florian" == Florian Weimer <fw@deneb.enyo.de> writes:
> 
> Florian> It's EINPROGRESS.  Pretty informative, isn't it?
> 
> It's never EINPROGRESS if you wait until the corresponding bit is set
> by select in the write set.

It's never EINPROGRESS in my experience: the first time is "would 
block", following times is another one (invalid parameter I seem to 
remember but I'm not sure; certainly nothing like "in progress").

Checking for writing is ok for connects that succeed. For failed ones, 
you must check another thing. The windows SDK says to check for 
exception condition in select. Checking for reading or writing doesn't 
reveal the failure.

-- 
-------------------------
Jano
402450.at.cepsz.unizar.es
-------------------------



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Gnat.Sockets and non-blocking connects
  2003-06-29 23:00           ` Jano
@ 2003-06-30 15:07             ` Jano
  0 siblings, 0 replies; 12+ messages in thread
From: Jano @ 2003-06-30 15:07 UTC (permalink / raw)


Jano dice...
> Florian Weimer dice...
> > Jano <nono@celes.unizar.es> writes:
> > 
> 
> > Even on Windows, you can use getsockopt(2) and SO_ERROR.  No need to
> > jump through hoops. 8-)
> 
> I must look at that!

It reports Connection_Refused, a much cleaner solution. Thanks!

-- 
-------------------------
Jano
402450.at.cepsz.unizar.es
-------------------------



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2003-06-30 15:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-29 12:26 Gnat.Sockets and non-blocking connects Jano
2003-06-29 13:42 ` Florian Weimer
2003-06-29 14:17   ` Samuel Tardieu
2003-06-29 14:29     ` Florian Weimer
2003-06-29 18:07       ` Jano
2003-06-29 20:50         ` Florian Weimer
2003-06-29 21:13           ` Samuel Tardieu
2003-06-29 21:27             ` Florian Weimer
2003-06-29 22:38               ` Samuel Tardieu
2003-06-29 23:00                 ` Jano
2003-06-29 23:00           ` Jano
2003-06-30 15:07             ` Jano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox