leave accept

leave accept

Post by Markus Wenk » Wed, 23 Apr 2003 18:54:34



Hi,

In my prog a accept-thread is listening for incomminc tcp-connections.
If I end this prog, a "shutdown() (2)" let accept() return.
But with Kernel 2.2 I get the following error:

errno: 107 (Transport endpoint is not connected)

Is there another chance to leave the accept-function?

thanks in advance

Markus Wenke

 
 
 

leave accept

Post by Markus Csern » Wed, 23 Apr 2003 22:23:59



> Hi,

> In my prog a accept-thread is listening for incomminc tcp-connections.
> If I end this prog, a "shutdown() (2)" let accept() return.
> But with Kernel 2.2 I get the following error:

> errno: 107 (Transport endpoint is not connected)

> Is there another chance to leave the accept-function?

Use select() to check if the socket has data ready to read and call accept()
afterwards. In this case, accept() will never block and you won't get into
the situation you mention above.

Bye
Markus

 
 
 

leave accept

Post by Kevin Easto » Wed, 23 Apr 2003 23:03:04




>> Hi,

>> In my prog a accept-thread is listening for incomminc tcp-connections.
>> If I end this prog, a "shutdown() (2)" let accept() return.
>> But with Kernel 2.2 I get the following error:

>> errno: 107 (Transport endpoint is not connected)

>> Is there another chance to leave the accept-function?

> Use select() to check if the socket has data ready to read and call accept()
> afterwards. In this case, accept() will never block and you won't get into
> the situation you mention above.

Be aware that there exists a race condition between select() and
accept().  This sequence of events is possible:

    Server calls listen(fd).

    Server calls select({fd}).  Blocks.

    Client connects.

    Server returns from select, with 'fd' marked readable.

    Client resets connection.

    Server calls accept(fd), and because there's no longer a connection to
    accept, blocks.

To avoid this, you need to mark listening sockets as nonblocking.

        - Kevin.

 
 
 

leave accept

Post by Markus Csern » Thu, 24 Apr 2003 00:03:06



> Be aware that there exists a race condition between select() and
> accept().  This sequence of events is possible:

>     Server calls listen(fd).

>     Server calls select({fd}).  Blocks.

>     Client connects.

>     Server returns from select, with 'fd' marked readable.

>     Client resets connection.

>     Server calls accept(fd), and because there's no longer a connection to
>     accept, blocks.

> To avoid this, you need to mark listening sockets as nonblocking.

> - Kevin.

Good point, never thought about this! And it's even there on the man page of
accept()... *cry*

Bye
Markus

 
 
 

1. leave accept

Hi,

In my prog a accept-thread is listening for incomminc tcp-connections.
If I end this prog, a "shutdown() (2)" let accept() return.
But with Kernel 2.2 I get the following error:

errno: 107 (Transport endpoint is not connected)

Is there another chance to leave the accept-function?

thanks in advance

Markus Wenke

2. intel 815 chipset

3. Left vs. Ctl-Left vs. Alt-Left

4. patching rpm database?

5. Help: Left-Handed user needs left-handed X

6. Has Linux for PowerMac been completed ?

7. vi: !}fmt to flush left, left/right, right, middle

8. FREE OFFER-YOUR ONE NUMBER!!!

9. how to make the linux accept 8-bit?

10. accept()-like wait for semaphore AND socket?

11. asynchronous listen/accept

12. Apache error_log: socket error: accept failed

13. SNMP : Accept access only from ...