Issue with netconn_close() closing connection before netconn_write()'s have completed

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Issue with netconn_close() closing connection before netconn_write()'s have completed

Terry Barnaby
I am using Lwip on an STM32F7 system along with FreeRTOS and our own
system harness ode. Lwip is generally working very well supporting a
number of TCPIP services and client functions. However we have one small

If we call netconn_close() shortly after a netconn_write() the remote
host often does not get data from the netconn_write() unless we put in a
short delay before netconn_close() is called. An example is in a simple
HTTP server like:

         // Accept any incoming connection
         accept_err = netconn_accept(osocketListen, &osocket);
         if(accept_err == ERR_OK){
             dl4printf("Listen: accept connection\n");
             netconn_set_recvtimeout(osocket, 10000);

             // Serve connection
             err = processRequest();

             // We shouldn't need this but TCP write packets can be lost
if we don't for some reason

             // Close connection

             // Delete connection
             osocket = 0;

In this case, depending on how much is written by netconn_write(), a WEB
browser will display a window stating that the client has closed the
connection unless the 1 ms delay is included. The processRequest()
function uses netconn_recv() and netconn_write() with the flag
NETCONN_COPY. All of the netconn HTTP processing is within one thread.

I am unclear from the documentation and code if netconn_close() will
wait for the TCPIP write buffers to be sent before closing or not. I
have tried setting the lwip config option LWIP_SO_LINGER in case that
was needed but this didn't have any effect. Any info on if
netconn_close() should wait for the write buffers to be sent and if so
what config options may be needed to provide this behaviour or ideas on
what may be going wrong ?


lwip-users mailing list
[hidden email]