lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] advice on recovery on a socket send error using tcp_wri


From: Kieran Mansley
Subject: Re: [lwip-users] advice on recovery on a socket send error using tcp_write()
Date: Thu, 19 Aug 2010 09:29:27 +0100

On Wed, 2010-08-18 at 19:11 -0400, shogun wrote:
> I have a couple questions about getting an error on tcp_write() using lwip.
> 
> 
> Sometimes I get an (0xFF) error from the send function:
> 
> //this is sudo code here
> ert = tcp_write(my_pcb, data, size, 0);
> if(ert) 
> {
>       close_socket()
> }
> 
> 
> I do not yet know if the error is on the embedded lwip side (server) or the
> PC side (client). I think it's more likely on the embedded side since I
> usually cannot get the socket to recover until I reset the embedded side.
> 
> My questions are:
> 
> 1) What is recommended to clean up after a error on a socket? I was doing
> something like the example here and calling close_socket() but it doesn't
> work well.  I would like to close the socket and reinitialize it to
> reestablish communication.
> 
> 
> static void close_socket(struct tcp_pcb *pcb)
> {
>       tcp_arg(pcb, NULL);     
>       tcp_sent(pcb, NULL);
>       tcp_close(pcb);
>       socket_init();  //This will re init the socket with tcp_new() etc.
> } //end debug_client_close()
> 
> 
> The above function would be called if a connection is lost, there is an
> error etc.  The
> goal is to keep the communication working between the two systems and if
> necessary have the remote client reestablish the connection.  The function
> socket_init() does the full initialization like it does when the socket is
> first initialized on startup.
> tcp_new();
> tcp_bind();
> tcp_listen();
> tcp_accept();

This all seems a little confused.  You're trying to close a data PCB but
then to re-open it you're creating a listening PCB.  Do you not still
have the bound listening PCB from when you first accepted the
connection?  You should be able to just call tcp_accept() on that to
re-open the data socket (although it will have to wait for the remote
end reconnect).

It might be clearer if we could see your actual code with function
arguments etc.

> 
> 2) My other question is what would be the likely cause of the tcp_write()
> returning 0xFF?

0xff is an odd value for tcp_write() to return.  It would normally
return an error value from the set defined in src/include/lwip/err.h
The error number is signed and the value will be negative so perhaps
that is causing the confusion.

Kieran




reply via email to

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