2002-08-07 01:24:36

by Vasisht Tadigotla

[permalink] [raw]
Subject: multiple connect on a socket


Hi,

i'm doing the following steps,

1. open a socket on some remote server
2. set it to be non-blocking
3. connect to that socket
4. do a select on the socket
5. read from the socket
6. connect to the socket again
7. read from the socket

and as expected a EINPROGRESS error is thrown on step 3. After I do a
select() and read from that socket, I try to connect to it again and it
connects without throwing an EISCONN error in linux, though if I try to
read from it it throws a EAGAIN error. Shouldn't it throw an error when I
try to connect to it a second time ? Am I missing something here.


Vasisht




2002-08-07 02:02:08

by Vasisht Tadigotla

[permalink] [raw]
Subject: Re: multiple connect on a socket


sorry, for replying to my own mail. the kernel version is 2.4.18

vasisht

On Tue, 6 Aug 2002, Vasisht Tadigotla wrote:

>
> Hi,
>
> i'm doing the following steps,
>
> 1. open a socket on some remote server
> 2. set it to be non-blocking
> 3. connect to that socket
> 4. do a select on the socket
> 5. read from the socket
> 6. connect to the socket again
> 7. read from the socket
>
> and as expected a EINPROGRESS error is thrown on step 3. After I do a
> select() and read from that socket, I try to connect to it again and it
> connects without throwing an EISCONN error in linux, though if I try to
> read from it it throws a EAGAIN error. Shouldn't it throw an error when I
> try to connect to it a second time ? Am I missing something here.
>
>
> Vasisht
>
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

---------------------------------------------------------------------
ce .sig n'est pas une .sig

2002-08-07 02:07:34

by Alexey Kuznetsov

[permalink] [raw]
Subject: Re: multiple connect on a socket

Hello!

> Shouldn't it throw an error when I
> try to connect to it a second time ? Am I missing something here.

Yes, it used to return success once upon connection is complete.

When the connection is in progress, it returns EALREADY,
after this it returns EISCONN, but success is indicated when it goes
from unconnected to connected state. Maybe, this is wrong but it used
to work in this way.

Alexey

2002-08-07 04:33:36

by Vasisht Tadigotla

[permalink] [raw]
Subject: Re: multiple connect on a socket

>
> > Shouldn't it throw an error when I
> > try to connect to it a second time ? Am I missing something here.
>
> Yes, it used to return success once upon connection is complete.
>
> When the connection is in progress, it returns EALREADY,
> after this it returns EISCONN, but success is indicated when it goes
> from unconnected to connected state. Maybe, this is wrong but it used
> to work in this way.

since O_NONBLOCK is set for the socket fd, the initial connect will fail
with an EINPROGRESS, and the connection request is established
asynchronously. If there is another connect during this period before the
connection is established, as you said it returns EALREADY. This is after
the connection is established and I read data from the socket. Since the
connection is already established, a further connect attempt should return
EISCONN. This is the behaviour on SunOS and IRIX.

On Linux if I attempt to connect to the same socket after the connection
has been established, connect() returns 0. I'm not sure if this is the
correct behaviour.


thanks,

vasisht