Skip to content

Commit 35c0f1a

Browse files
committed
Merge branch 'bugfix/fix_udp_sync_error_v3.0' into 'master'
Fix UDP sync send error See merge request sdk/ESP8266_RTOS_SDK!442
2 parents 8a73125 + 6477159 commit 35c0f1a

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

components/lwip/port/esp8266/freertos/udp_sync.c

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "esp_log.h"
2424

25-
#if ESP_UDP
25+
#if ESP_UDP && LWIP_NETIF_TX_SINGLE_PBUF
2626

2727
#define UDP_SYNC_MAX MEMP_NUM_NETCONN
2828
#define UDP_SYNC_RETRY_MAX CONFIG_ESP_UDP_SYNC_RETRY_MAX
@@ -40,15 +40,16 @@
4040
typedef struct udp_sync {
4141
struct api_msg *msg;
4242

43-
int ret;
43+
struct netif *netif;
4444

45-
int retry;
45+
int8_t ret;
46+
47+
uint8_t retry;
4648
} udp_sync_t;
4749

4850
static const char *TAG = "udp_sync";
4951
static size_t s_udp_sync_num;
5052
static udp_sync_t s_udp_sync[UDP_SYNC_MAX];
51-
static bool s_register_locked;
5253
static struct api_msg *s_cur_msg;
5354

5455
/*
@@ -57,7 +58,6 @@ static struct api_msg *s_cur_msg;
5758
void udp_sync_init(void)
5859
{
5960
memset(s_udp_sync, 0, sizeof(s_udp_sync));
60-
s_register_locked = false;
6161
s_udp_sync_num = 0;
6262
}
6363

@@ -68,18 +68,13 @@ void udp_sync_regitser(void *in_msg)
6868
{
6969
s_cur_msg = in_msg;
7070

71-
if (s_register_locked == true)
72-
return ;
73-
7471
struct api_msg *msg = (struct api_msg *)in_msg;
7572
int s = msg->conn->socket;
7673

7774
if (s < 0 || s >= UDP_SYNC_MAX) {
7875
ESP_LOGE(TAG, "UDP sync register error, socket is %d", s);
79-
return ;
8076
} else if (s_udp_sync[s].msg) {
8177
ESP_LOGE(TAG, "UDP sync register error, msg is %p", s_udp_sync[s].msg);
82-
return ;
8378
}
8479

8580
s_udp_sync_num++;
@@ -88,6 +83,25 @@ void udp_sync_regitser(void *in_msg)
8883
s_udp_sync[s].msg = msg;
8984
}
9085

86+
static void _udp_sync_ack_ret(int s, struct api_msg *msg)
87+
{
88+
/* Only cache when low-level has no buffer to send packet */
89+
if (s_udp_sync[s].ret != ERR_MEM || s_udp_sync[s].retry >= UDP_SYNC_RETRY_MAX) {
90+
91+
ESP_LOGD(TAG, "UDP sync ret %d retry %d", s_udp_sync[s].ret, s_udp_sync[s].retry);
92+
93+
s_udp_sync[s].msg = NULL;
94+
s_udp_sync[s].retry = 0;
95+
s_udp_sync[s].ret = ERR_OK;
96+
s_udp_sync_num--;
97+
98+
TCPIP_APIMSG_ACK(msg);
99+
} else {
100+
s_udp_sync[s].retry++;
101+
ESP_LOGD(TAG, "UDP sync ack error, errno %d", s_udp_sync[s].ret);
102+
}
103+
}
104+
91105
/*
92106
* @brief ack the message
93107
*/
@@ -98,34 +112,19 @@ void udp_sync_ack(void *in_msg)
98112

99113
if (s < 0 || s >= UDP_SYNC_MAX) {
100114
ESP_LOGE(TAG, "UDP sync ack error, socket is %d", s);
101-
return ;
102115
} else if (!s_udp_sync[s].msg) {
103116
ESP_LOGE(TAG, "UDP sync ack error, msg is NULL");
104-
return ;
105117
}
106118

107-
/* Only cache when low-level has no buffer to send packet */
108-
if (s_udp_sync[s].ret != ERR_MEM || s_udp_sync[s].retry >= UDP_SYNC_RETRY_MAX) {
109-
s_udp_sync[s].msg = NULL;
110-
s_udp_sync[s].retry = 0;
111-
s_udp_sync[s].ret = ERR_OK;
112-
s_udp_sync_num--;
113-
114-
ESP_LOGD(TAG, "UDP sync ret %d", s_udp_sync[s].ret);
115-
116-
TCPIP_APIMSG_ACK(msg);
117-
} else {
118-
s_udp_sync[s].retry++;
119-
ESP_LOGD(TAG, "UDP sync ack error, errno %d", s_udp_sync[s].ret);
120-
}
119+
_udp_sync_ack_ret(s, msg);
121120

122121
s_cur_msg = NULL;
123122
}
124123

125124
/*
126125
* @brief set the current message send result
127126
*/
128-
void udp_sync_set_ret(int ret)
127+
void udp_sync_set_ret(void *netif, int ret)
129128
{
130129
/* Only poll and regitser can set current message */
131130
if (!s_cur_msg) {
@@ -139,15 +138,28 @@ void udp_sync_set_ret(int ret)
139138

140139
if (s < 0 || s >= UDP_SYNC_MAX) {
141140
ESP_LOGE(TAG, "UDP sync ack error, socket is %d", s);
142-
return ;
143141
} else if (!s_udp_sync[s].msg) {
144142
ESP_LOGE(TAG, "UDP sync ack error, msg is NULL");
145-
return ;
146143
}
147144

145+
s_udp_sync[s].netif = netif;
148146
s_udp_sync[s].ret = ret;
149147
}
150148

149+
static void udp_sync_send(struct api_msg *msg)
150+
{
151+
struct pbuf *p = msg->msg.b->p;
152+
int s = msg->conn->socket;
153+
struct netif *netif = s_udp_sync[s].netif;
154+
155+
s_cur_msg = msg;
156+
157+
netif->linkoutput(netif, p);
158+
_udp_sync_ack_ret(s, msg);
159+
160+
s_cur_msg = NULL;
161+
}
162+
151163
/*
152164
* @brief process the sync
153165
*/
@@ -156,19 +168,17 @@ void udp_sync_proc(void)
156168
if (!s_udp_sync_num)
157169
return ;
158170

159-
s_register_locked = true;
160171
for (int i = 0; i < UDP_SYNC_MAX; i++) {
161172
if (!s_udp_sync[i].msg)
162173
continue;
163174

164-
lwip_netconn_do_send(s_udp_sync[i].msg);
175+
udp_sync_send(s_udp_sync[i].msg);
165176
#if 0
166177
//Todo: Add this later
167178
if (s_udp_sync[i].ret != ERR_OK)
168179
break;
169180
#endif
170181
}
171-
s_register_locked = false;
172182
}
173183

174184
#endif /* ESP_UDP */

components/lwip/port/esp8266/include/udp_sync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void udp_sync_ack(void *in_msg);
4343
*
4444
* @param ret current message send result
4545
*/
46-
void udp_sync_set_ret(int ret);
46+
void udp_sync_set_ret(void *netif, int ret);
4747

4848
/*
4949
* @brief process the sync

components/lwip/port/esp8266/netif/ethernetif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static int8_t low_level_output(struct netif* netif, struct pbuf* p)
303303
*/
304304
err = esp_aio_sendto(&aio, NULL, 0);
305305
#if ESP_UDP
306-
udp_sync_set_ret(err);
306+
udp_sync_set_ret(netif, err);
307307
#endif
308308
if (err != ERR_OK) {
309309
if (err == ERR_MEM){

0 commit comments

Comments
 (0)