@@ -91,7 +91,7 @@ typedef enum {
91
91
92
92
typedef struct {
93
93
lwip_tcp_event_t event;
94
- void *arg ;
94
+ AsyncClient *client ;
95
95
union {
96
96
struct {
97
97
tcp_pcb *pcb;
@@ -117,7 +117,7 @@ typedef struct {
117
117
tcp_pcb *pcb;
118
118
} poll;
119
119
struct {
120
- AsyncClient *client ;
120
+ AsyncServer *server ;
121
121
} accept;
122
122
struct {
123
123
const char *name;
@@ -206,7 +206,7 @@ static inline bool _get_async_event(lwip_tcp_event_packet_t **e) {
206
206
lwip_tcp_event_packet_t *next_pkt = NULL ;
207
207
while (xQueuePeek (_async_queue, &next_pkt, 0 ) == pdPASS) {
208
208
// if the next event that will come is a poll event for the same connection, we can discard it and continue
209
- if (next_pkt->arg == (*e)->arg && next_pkt->event == LWIP_TCP_POLL) {
209
+ if (next_pkt->client == (*e)->client && next_pkt->event == LWIP_TCP_POLL) {
210
210
if (xQueueReceive (_async_queue, &next_pkt, 0 ) == pdPASS) {
211
211
free (next_pkt);
212
212
next_pkt = NULL ;
@@ -239,7 +239,7 @@ static inline bool _get_async_event(lwip_tcp_event_packet_t **e) {
239
239
return false ;
240
240
}
241
241
242
- static bool _remove_events_with_arg ( void *arg ) {
242
+ static bool _remove_events_for_client (AsyncClient *client ) {
243
243
if (!_async_queue) {
244
244
return false ;
245
245
}
@@ -253,7 +253,7 @@ static bool _remove_events_with_arg(void *arg) {
253
253
return false ;
254
254
}
255
255
// discard packet if matching
256
- if ((uintptr_t )first_packet->arg == (uintptr_t )arg ) {
256
+ if ((uintptr_t )first_packet->client == (uintptr_t )client ) {
257
257
free (first_packet);
258
258
first_packet = NULL ;
259
259
} else if (xQueueSend (_async_queue, &first_packet, 0 ) != pdPASS) {
@@ -270,7 +270,7 @@ static bool _remove_events_with_arg(void *arg) {
270
270
if (xQueueReceive (_async_queue, &packet, 0 ) != pdPASS) {
271
271
return false ;
272
272
}
273
- if ((uintptr_t )packet->arg == (uintptr_t )arg ) {
273
+ if ((uintptr_t )packet->client == (uintptr_t )client ) {
274
274
// remove matching event
275
275
free (packet);
276
276
packet = NULL ;
@@ -287,35 +287,35 @@ static bool _remove_events_with_arg(void *arg) {
287
287
}
288
288
289
289
void AsyncTCP_detail::handle_async_event (lwip_tcp_event_packet_t *e) {
290
- if (e->arg == NULL ) {
290
+ if (e->client == NULL ) {
291
291
// do nothing when arg is NULL
292
292
// ets_printf("event arg == NULL: 0x%08x\n", e->recv.pcb);
293
293
} else if (e->event == LWIP_TCP_CLEAR) {
294
- _remove_events_with_arg (e->arg );
294
+ _remove_events_for_client (e->client );
295
295
} else if (e->event == LWIP_TCP_RECV) {
296
296
// ets_printf("-R: 0x%08x\n", e->recv.pcb);
297
- reinterpret_cast <AsyncClient *>( e->arg ) ->_recv (e->recv .pcb , e->recv .pb , e->recv .err );
297
+ e->client ->_recv (e->recv .pcb , e->recv .pb , e->recv .err );
298
298
} else if (e->event == LWIP_TCP_FIN) {
299
299
// ets_printf("-F: 0x%08x\n", e->fin.pcb);
300
- reinterpret_cast <AsyncClient *>( e->arg ) ->_fin (e->fin .pcb , e->fin .err );
300
+ e->client ->_fin (e->fin .pcb , e->fin .err );
301
301
} else if (e->event == LWIP_TCP_SENT) {
302
302
// ets_printf("-S: 0x%08x\n", e->sent.pcb);
303
- reinterpret_cast <AsyncClient *>( e->arg ) ->_sent (e->sent .pcb , e->sent .len );
303
+ e->client ->_sent (e->sent .pcb , e->sent .len );
304
304
} else if (e->event == LWIP_TCP_POLL) {
305
305
// ets_printf("-P: 0x%08x\n", e->poll.pcb);
306
- reinterpret_cast <AsyncClient *>( e->arg ) ->_poll (e->poll .pcb );
306
+ e->client ->_poll (e->poll .pcb );
307
307
} else if (e->event == LWIP_TCP_ERROR) {
308
- // ets_printf("-E: 0x%08x %d\n", e->arg , e->error.err);
309
- reinterpret_cast <AsyncClient *>( e->arg ) ->_error (e->error .err );
308
+ // ets_printf("-E: 0x%08x %d\n", e->client , e->error.err);
309
+ e->client ->_error (e->error .err );
310
310
} else if (e->event == LWIP_TCP_CONNECTED) {
311
- // ets_printf("C: 0x%08x 0x%08x %d\n", e->arg , e->connected.pcb, e->connected.err);
312
- reinterpret_cast <AsyncClient *>( e->arg ) ->_connected (e->connected .pcb , e->connected .err );
311
+ // ets_printf("C: 0x%08x 0x%08x %d\n", e->client , e->connected.pcb, e->connected.err);
312
+ e->client ->_connected (e->connected .pcb , e->connected .err );
313
313
} else if (e->event == LWIP_TCP_ACCEPT) {
314
- // ets_printf("A: 0x%08x 0x%08x\n", e->arg , e->accept.client);
315
- reinterpret_cast <AsyncServer *>( e->arg ) ->_accepted (e->accept . client );
314
+ // ets_printf("A: 0x%08x 0x%08x\n", e->client , e->accept.client);
315
+ e->accept . server ->_accepted (e->client );
316
316
} else if (e->event == LWIP_TCP_DNS) {
317
- // ets_printf("D: 0x%08x %s = %s\n", e->arg , e->dns.name, ipaddr_ntoa(&e->dns.addr));
318
- reinterpret_cast <AsyncClient *>( e->arg ) ->_dns_found (&e->dns .addr );
317
+ // ets_printf("D: 0x%08x %s = %s\n", e->client , e->dns.name, ipaddr_ntoa(&e->dns.addr));
318
+ e->client ->_dns_found (&e->dns .addr );
319
319
}
320
320
free ((void *)(e));
321
321
}
@@ -384,14 +384,14 @@ static bool _start_async_task() {
384
384
* LwIP Callbacks
385
385
* */
386
386
387
- static int8_t _tcp_clear_events (void *arg ) {
387
+ static int8_t _tcp_clear_events (AsyncClient *client ) {
388
388
lwip_tcp_event_packet_t *e = (lwip_tcp_event_packet_t *)malloc (sizeof (lwip_tcp_event_packet_t ));
389
389
if (!e) {
390
390
log_e (" Failed to allocate event packet" );
391
391
return ERR_MEM;
392
392
}
393
393
e->event = LWIP_TCP_CLEAR;
394
- e->arg = arg ;
394
+ e->client = client ;
395
395
if (!_prepend_async_event (&e)) {
396
396
free ((void *)(e));
397
397
return ERR_TIMEOUT;
@@ -407,7 +407,7 @@ static int8_t _tcp_connected(void *arg, tcp_pcb *pcb, int8_t err) {
407
407
return ERR_MEM;
408
408
}
409
409
e->event = LWIP_TCP_CONNECTED;
410
- e->arg = arg;
410
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
411
411
e->connected .pcb = pcb;
412
412
e->connected .err = err;
413
413
if (!_prepend_async_event (&e)) {
@@ -432,7 +432,7 @@ int8_t AsyncTCP_detail::tcp_poll(void *arg, struct tcp_pcb *pcb) {
432
432
return ERR_MEM;
433
433
}
434
434
e->event = LWIP_TCP_POLL;
435
- e->arg = arg;
435
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
436
436
e->poll .pcb = pcb;
437
437
// poll events are not critical 'cause those are repetitive, so we may not wait the queue in any case
438
438
if (!_send_async_event (&e, 0 )) {
@@ -448,7 +448,7 @@ int8_t AsyncTCP_detail::tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb
448
448
log_e (" Failed to allocate event packet" );
449
449
return ERR_MEM;
450
450
}
451
- e->arg = arg;
451
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
452
452
if (pb) {
453
453
// ets_printf("+R: 0x%08x\n", pcb);
454
454
e->event = LWIP_TCP_RECV;
@@ -478,7 +478,7 @@ int8_t AsyncTCP_detail::tcp_sent(void *arg, struct tcp_pcb *pcb, uint16_t len) {
478
478
return ERR_MEM;
479
479
}
480
480
e->event = LWIP_TCP_SENT;
481
- e->arg = arg;
481
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
482
482
e->sent .pcb = pcb;
483
483
e->sent .len = len;
484
484
if (!_send_async_event (&e)) {
@@ -510,7 +510,7 @@ void AsyncTCP_detail::tcp_error(void *arg, int8_t err) {
510
510
return ;
511
511
}
512
512
e->event = LWIP_TCP_ERROR;
513
- e->arg = arg ;
513
+ e->client = client ;
514
514
e->error .err = err;
515
515
if (!_send_async_event (&e)) {
516
516
::free ((void *)(e));
@@ -525,7 +525,7 @@ static void _tcp_dns_found(const char *name, struct ip_addr *ipaddr, void *arg)
525
525
}
526
526
// ets_printf("+DNS: name=%s ipaddr=0x%08x arg=%x\n", name, ipaddr, arg);
527
527
e->event = LWIP_TCP_DNS;
528
- e->arg = arg;
528
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
529
529
e->dns .name = name;
530
530
if (ipaddr) {
531
531
memcpy (&e->dns .addr , ipaddr, sizeof (struct ip_addr ));
@@ -1581,8 +1581,8 @@ int8_t AsyncTCP_detail::tcp_accept(void *arg, tcp_pcb *pcb, int8_t err) {
1581
1581
lwip_tcp_event_packet_t *e = (lwip_tcp_event_packet_t *)malloc (sizeof (lwip_tcp_event_packet_t ));
1582
1582
if (e) {
1583
1583
e->event = LWIP_TCP_ACCEPT;
1584
- e->arg = arg ;
1585
- e->accept . client = c;
1584
+ e->accept . server = server ;
1585
+ e->client = c;
1586
1586
if (_prepend_async_event (&e)) {
1587
1587
return ERR_OK; // success
1588
1588
}
0 commit comments