lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] How to close a listening pcb


From: Kieran Mansley
Subject: Re: [lwip-users] How to close a listening pcb
Date: Mon, 24 Sep 2007 11:57:48 +0100

On Thu, 2007-09-20 at 08:14 -0500, Wilson, Clive wrote:
> Hello,
> 
> I have set a socket to listen for an incoming connection using listen
> () and accept(). Once the connection is made I send data back to the
> now connected client using send(). Straightforward so far. Once the
> data is sent, I want to close the connection. However, on inspecting
> tcp_close() I notice that for listening connections, the only action
> taken is for the pcb to be deleted. So how does the client receiving
> the data know there's no more to come? If it's a blocking connection
> then it'll just wait there for ever. Or should this be a higher layer
> responsibility? Perhaps I'm expecting too much from the sockets API...

There are two sockets involved here:
 - the listening socket 
 - the socket that is returned by accept for your new connection and
data transfer

Note that accept makes a new socket for each connection that arrives,
and you still have the listening socket available for listening on again
if you wish.  The socket that you get from accept is not a listening
one, and so is handled rather differently in tcp_close().  

When you close the data transfer socket (that accept gave you) it will
if you're using TCP send a FIN packet to the other end to notify it that
you've closed.  If the client tries to read more data it will get zero
bytes back from recv() telling it that the connection has been closed. 

lwIP is pretty standard in this respect - it's just the way the sockets
API works rather than being lwIP specific.

Kieran





reply via email to

[Prev in Thread] Current Thread [Next in Thread]