【修复】ESP8266 上 socket 关闭失败问题

Signed-off-by: chenyong <1521761801@qq.com>
This commit is contained in:
chenyong 2018-07-20 20:38:38 +08:00
parent 91e3b7c7ac
commit 5b6a3cca40

View File

@ -95,13 +95,17 @@ static int esp8266_socket_close(int socket)
return -RT_ENOMEM; return -RT_ENOMEM;
} }
rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
if (rt_at_exec_cmd(resp, "AT+CIPCLOSE=%d", socket) < 0) if (rt_at_exec_cmd(resp, "AT+CIPCLOSE=%d", socket) < 0)
{ {
LOG_E("socket(%d) close failed.", socket); LOG_E("socket(%d) close failed.", socket);
rt_at_delete_resp(resp); goto __exit;
return -RT_ERROR;
} }
__exit:
rt_mutex_release(at_event_lock);
if (resp) if (resp)
{ {
rt_at_delete_resp(resp); rt_at_delete_resp(resp);
@ -140,8 +144,9 @@ static int esp8266_socket_connect(int socket, char *ip, int32_t port, enum at_so
return -RT_ENOMEM; return -RT_ENOMEM;
} }
__retry: rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
__retry:
if (is_client) if (is_client)
{ {
switch (type) switch (type)
@ -170,7 +175,7 @@ __retry:
if (result != RT_EOK && !retryed) if (result != RT_EOK && !retryed)
{ {
LOG_D("udp socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry.", socket); LOG_D("socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry.", socket);
if (esp8266_socket_close(socket) < 0) if (esp8266_socket_close(socket) < 0)
{ {
goto __exit; goto __exit;
@ -181,6 +186,7 @@ __retry:
} }
__exit: __exit:
rt_mutex_release(at_event_lock);
if (result != RT_EOK) if (result != RT_EOK)
{ {