[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Closing TCP connections
From: |
Sergio R. Caprile |
Subject: |
Re: [lwip-users] Closing TCP connections |
Date: |
Mon, 04 Aug 2014 10:19:59 -0300 |
User-agent: |
Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
Hi,
if you do need to detect a particular situation on tcp_err(), then you
can use the arg parameter. You are not getting the pcb because, afaik,
it no longer exists; it has been removed and freed before calling the
callback function; see tcp.c line 393 for example
The tcp_err() callback that will be called is the one you provided as a
parameter when you set the environment for that pcb. How come you don't
know what you setup ?
tcp_err(mypcb, myerr);
If you will reuse one tcp_err() function for many connections, you will
use the arg parameter, as shown in every example application:
tcp_arg(mypcb, myapplicationstructurepointer);
A closure action is something like this:
static void myclose(struct tcp_pcb* pcb)
{
state = myCLOSING;
if(tcp_close(pcb) == ERR_OK){
tcp_recv(pcb, NULL);
state = myCLOSED;
}
}
You need to have a state (or equivalent) and try to do close later if
the call to tcp_close() fails for low memory or whatever. If the other
host sends RST, you are going to close anyway.
To try later, you can use tcp_poll():
tcp_poll(mypcb, mypoll, POLL_TIME);
static err_t mypoll(void *arg, struct tcp_pcb* pcb)
{
if(state == myCLOSING){
// Retry closing the connection
myclose(pcb);
} else {
// Retry sending data we couldn't send before
mysend(pcb);
}
return ERR_OK;
}
--
- Re: [lwip-users] Closing TCP connections,
Sergio R. Caprile <=