[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] TCP Callback
From: |
Robert |
Subject: |
Re: [lwip-users] TCP Callback |
Date: |
Mon, 2 Jun 2003 18:58:17 -0400 (EDT) |
On Mon, 2 Jun 2003, David Haas wrote:
> >How can I get callbacks when the other side of the connection closes the tcp
> >socket?
the "recv" callback is called with the next to last parm (struct pbuf*) ==
NULL when the far end closes the connection.
For example, here is the callback function I use for a telnet server:
------------------------------------------------------------------------
static err_t telnet_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
err_t err)
{
FILE *file;
int i;
unsigned char *c;
struct pbuf *q;
debug( 2, ("telnet_recv called\n"));
file = arg;
if(p == NULL) { // this means the remote end closed the connection
debug( 2, ("telnet_recv p is NULL\n"));
close_conn(pcb, file);
return ERR_OK;
}
do {
q = p;
p = pbuf_dechain(q);
for(i=0, c=q->payload; i < q->len; i++, c++) {
cfifo_add( file->fifo, *c );
}
tcp_recved(pcb, q->len); // indicate data has been received
pbuf_free(q); // free up the buffer
} while( p );
return ERR_OK;
}
-------------------------------------------------------------------
--
Best Regards,
Robert