lwip: fix the bug that failed to create socket
Fix the bug that failed to create nonblocking TCP or UDP socket after several times socket create/close
This commit is contained in:
parent
fcf9c3d882
commit
5f56d65405
2 changed files with 23 additions and 31 deletions
|
@ -945,17 +945,13 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM SIG_CLO
|
||||||
#endif /* LWIP_SO_LINGER */
|
#endif /* LWIP_SO_LINGER */
|
||||||
} else {
|
} else {
|
||||||
if (err == ERR_MEM) {
|
if (err == ERR_MEM) {
|
||||||
/* Closing failed because of memory shortage */
|
/* Closing failed because of memory shortage, try again later. Even for
|
||||||
if (netconn_is_nonblocking(conn)) {
|
nonblocking netconns, we have to wait since no standard socket application
|
||||||
/* Nonblocking close failed */
|
is prepared for close failing because of resource shortage.
|
||||||
close_finished = 1;
|
Check the timeout: this is kind of an lwip addition to the standard sockets:
|
||||||
err = ERR_WOULDBLOCK;
|
we wait for some time when failing to allocate a segment for the FIN */
|
||||||
} else {
|
|
||||||
/* Blocking close, check the timeout */
|
|
||||||
#if LWIP_SO_SNDTIMEO || LWIP_SO_LINGER
|
#if LWIP_SO_SNDTIMEO || LWIP_SO_LINGER
|
||||||
s32_t close_timeout = LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT;
|
s32_t close_timeout = LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT;
|
||||||
/* this is kind of an lwip addition to the standard sockets: we wait
|
|
||||||
for some time when failing to allocate a segment for the FIN */
|
|
||||||
#if LWIP_SO_SNDTIMEO
|
#if LWIP_SO_SNDTIMEO
|
||||||
if (conn->send_timeout > 0) {
|
if (conn->send_timeout > 0) {
|
||||||
close_timeout = conn->send_timeout;
|
close_timeout = conn->send_timeout;
|
||||||
|
@ -978,7 +974,6 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM SIG_CLO
|
||||||
err = ERR_OK;
|
err = ERR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* Closing failed for a non-memory error: give up */
|
/* Closing failed for a non-memory error: give up */
|
||||||
close_finished = 1;
|
close_finished = 1;
|
||||||
|
|
|
@ -266,11 +266,11 @@ do{\
|
||||||
}\
|
}\
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
#define LWIP_SET_CLOSE_FLAG(_flag) \
|
#define LWIP_SET_CLOSE_FLAG() \
|
||||||
do{\
|
do{\
|
||||||
LWIP_SOCK_LOCK(__sock);\
|
LWIP_SOCK_LOCK(__sock);\
|
||||||
LWIP_DEBUGF(ESP_THREAD_SAFE_DEBUG, ("mark sock closing\n"));\
|
LWIP_DEBUGF(ESP_THREAD_SAFE_DEBUG, ("mark sock closing\n"));\
|
||||||
__sock->state = (_flag);\
|
__sock->state = LWIP_SOCK_CLOSING;\
|
||||||
LWIP_SOCK_UNLOCK(__sock);\
|
LWIP_SOCK_UNLOCK(__sock);\
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
|
@ -3312,11 +3312,8 @@ int
|
||||||
lwip_close_r(int s)
|
lwip_close_r(int s)
|
||||||
{
|
{
|
||||||
LWIP_API_LOCK();
|
LWIP_API_LOCK();
|
||||||
LWIP_SET_CLOSE_FLAG(LWIP_SOCK_CLOSING);
|
LWIP_SET_CLOSE_FLAG();
|
||||||
__ret = lwip_close(s);
|
__ret = lwip_close(s);
|
||||||
if (EWOULDBLOCK == __sock->err) {
|
|
||||||
LWIP_SET_CLOSE_FLAG(LWIP_SOCK_OPEN);
|
|
||||||
}
|
|
||||||
LWIP_API_UNLOCK();
|
LWIP_API_UNLOCK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue