lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] lwip_close(), keep getting new socket (index) on subsequent


From: Bergman Johan
Subject: [lwip-users] lwip_close(), keep getting new socket (index) on subsequent lwip_socket() call
Date: Thu, 3 May 2018 16:20:37 +0000

I am using lwip-2.0.2 (socket api) and have an issue which has started after attempting to upgrade from lwip-1.4.1 to lwip-2.0.2.

 

In our server application a socket is setup and receive commands from a client.

The problem is if we close the client interface and start it up again what happens in the Server application code is that we call lwip_close() and start over with a call to socket() and we can again receive commands from the client. But this can only be repeated a few times until we run into the max number of sockets in lwip, NUM_SOCKETS.

 

When we used lwip-1.4.1 this problem does not exist, we can keep repeating the scenario and calling socket() after lwip_close and it will not run into the problem where the socket() call fails due to reaching NUM_SOCKETS in lwip.

 

As I understand it the issue comes from sockets not getting fully destroyed in lwip-2.0.2. Since at every call to socket I can verify that socket index is incremented in

 

lwip_socket(), that is “i” variable returned from call to

 

i = alloc_socket()

 

keeps incrementing for every call to lwip_socket, even if there is the lwip_close call before, until it reaches NUM_SOCKET.

 

Running the same scenario but using lwip-1.4.1 I have verified that we do not get this value incremented for each lwip_socket() call.

 

 

 

Here is how the call to create the socket and set socket options look:

 

sockFd = lwip_socket( AF_INET, SOCK_STREAM, IPPROTO_IP)

If ( sockFd < 0 )

{

    return -1;

}

 

timeout  = 10000; // 10 seconds

setsockopt( sockFd, SOL_SOCKET, SO_RCVTIMEO, (const char*) &timeout, sizeof( uint32_t ) );

 

nodelay = 1; // non zero means TCP_NODELAY is on = nagle is off

setsockopt( sockFd, IPPROTO_TCP, TCP_NODELAY, (const char*) &nodelay, sizeof( uint32_t ) );

 

 

I have found some info where it seems there is a modified lwip possibly (esp32 espressif related) where there is a wrapper function lwip_close_r()

which sets a flag LWIP_SET_CLOSE_FLAG and then performs the call to lwip_close(s) but this does not seem to be in the

official lwip distribution. But looking at the discussion it seems to be aimed at solving my exact issue.

( https://www.esp32.com/viewtopic.php?t=5506 )

 

Any input on this issue appreciated.

 

Johan Bergman

Development Engineering Consultant

Combitech AB

Sweden

 

 


reply via email to

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