@@ -76,7 +76,7 @@ typedef enum {
76
76
77
77
typedef struct {
78
78
lwip_tcp_event_t event;
79
- void *arg ;
79
+ AsyncClient *client ;
80
80
union {
81
81
struct {
82
82
tcp_pcb *pcb;
@@ -102,7 +102,7 @@ typedef struct {
102
102
tcp_pcb *pcb;
103
103
} poll;
104
104
struct {
105
- AsyncClient *client ;
105
+ AsyncServer *server ;
106
106
} accept;
107
107
struct {
108
108
const char *name;
@@ -191,7 +191,7 @@ static inline bool _get_async_event(lwip_tcp_event_packet_t **e) {
191
191
lwip_tcp_event_packet_t *next_pkt = NULL ;
192
192
while (xQueuePeek (_async_queue, &next_pkt, 0 ) == pdPASS) {
193
193
// if the next event that will come is a poll event for the same connection, we can discard it and continue
194
- if (next_pkt->arg == (*e)->arg && next_pkt->event == LWIP_TCP_POLL) {
194
+ if (next_pkt->client == (*e)->client && next_pkt->event == LWIP_TCP_POLL) {
195
195
if (xQueueReceive (_async_queue, &next_pkt, 0 ) == pdPASS) {
196
196
free (next_pkt);
197
197
next_pkt = NULL ;
@@ -224,7 +224,7 @@ static inline bool _get_async_event(lwip_tcp_event_packet_t **e) {
224
224
return false ;
225
225
}
226
226
227
- static bool _remove_events_with_arg ( void *arg ) {
227
+ static bool _remove_events_for_client (AsyncClient *client ) {
228
228
if (!_async_queue) {
229
229
return false ;
230
230
}
@@ -238,7 +238,7 @@ static bool _remove_events_with_arg(void *arg) {
238
238
return false ;
239
239
}
240
240
// discard packet if matching
241
- if ((uintptr_t )first_packet->arg == (uintptr_t )arg ) {
241
+ if ((uintptr_t )first_packet->client == (uintptr_t )client ) {
242
242
free (first_packet);
243
243
first_packet = NULL ;
244
244
} else if (xQueueSend (_async_queue, &first_packet, 0 ) != pdPASS) {
@@ -255,7 +255,7 @@ static bool _remove_events_with_arg(void *arg) {
255
255
if (xQueueReceive (_async_queue, &packet, 0 ) != pdPASS) {
256
256
return false ;
257
257
}
258
- if ((uintptr_t )packet->arg == (uintptr_t )arg ) {
258
+ if ((uintptr_t )packet->client == (uintptr_t )client ) {
259
259
// remove matching event
260
260
free (packet);
261
261
packet = NULL ;
@@ -272,35 +272,35 @@ static bool _remove_events_with_arg(void *arg) {
272
272
}
273
273
274
274
void AsyncTCP_detail::handle_async_event (lwip_tcp_event_packet_t *e) {
275
- if (e->arg == NULL ) {
275
+ if (e->client == NULL ) {
276
276
// do nothing when arg is NULL
277
277
// ets_printf("event arg == NULL: 0x%08x\n", e->recv.pcb);
278
278
} else if (e->event == LWIP_TCP_CLEAR) {
279
- _remove_events_with_arg (e->arg );
279
+ _remove_events_for_client (e->client );
280
280
} else if (e->event == LWIP_TCP_RECV) {
281
281
// ets_printf("-R: 0x%08x\n", e->recv.pcb);
282
- reinterpret_cast <AsyncClient *>( e->arg ) ->_recv (e->recv .pcb , e->recv .pb , e->recv .err );
282
+ e->client ->_recv (e->recv .pcb , e->recv .pb , e->recv .err );
283
283
} else if (e->event == LWIP_TCP_FIN) {
284
284
// ets_printf("-F: 0x%08x\n", e->fin.pcb);
285
- reinterpret_cast <AsyncClient *>( e->arg ) ->_fin (e->fin .pcb , e->fin .err );
285
+ e->client ->_fin (e->fin .pcb , e->fin .err );
286
286
} else if (e->event == LWIP_TCP_SENT) {
287
287
// ets_printf("-S: 0x%08x\n", e->sent.pcb);
288
- reinterpret_cast <AsyncClient *>( e->arg ) ->_sent (e->sent .pcb , e->sent .len );
288
+ e->client ->_sent (e->sent .pcb , e->sent .len );
289
289
} else if (e->event == LWIP_TCP_POLL) {
290
290
// ets_printf("-P: 0x%08x\n", e->poll.pcb);
291
- reinterpret_cast <AsyncClient *>( e->arg ) ->_poll (e->poll .pcb );
291
+ e->client ->_poll (e->poll .pcb );
292
292
} else if (e->event == LWIP_TCP_ERROR) {
293
- // ets_printf("-E: 0x%08x %d\n", e->arg , e->error.err);
294
- reinterpret_cast <AsyncClient *>( e->arg ) ->_error (e->error .err );
293
+ // ets_printf("-E: 0x%08x %d\n", e->client , e->error.err);
294
+ e->client ->_error (e->error .err );
295
295
} else if (e->event == LWIP_TCP_CONNECTED) {
296
- // ets_printf("C: 0x%08x 0x%08x %d\n", e->arg , e->connected.pcb, e->connected.err);
297
- reinterpret_cast <AsyncClient *>( e->arg ) ->_connected (e->connected .pcb , e->connected .err );
296
+ // ets_printf("C: 0x%08x 0x%08x %d\n", e->client , e->connected.pcb, e->connected.err);
297
+ e->client ->_connected (e->connected .pcb , e->connected .err );
298
298
} else if (e->event == LWIP_TCP_ACCEPT) {
299
- // ets_printf("A: 0x%08x 0x%08x\n", e->arg , e->accept.client);
300
- reinterpret_cast <AsyncServer *>( e->arg ) ->_accepted (e->accept . client );
299
+ // ets_printf("A: 0x%08x 0x%08x\n", e->client , e->accept.client);
300
+ e->accept . server ->_accepted (e->client );
301
301
} else if (e->event == LWIP_TCP_DNS) {
302
- // ets_printf("D: 0x%08x %s = %s\n", e->arg , e->dns.name, ipaddr_ntoa(&e->dns.addr));
303
- reinterpret_cast <AsyncClient *>( e->arg ) ->_dns_found (&e->dns .addr );
302
+ // ets_printf("D: 0x%08x %s = %s\n", e->client , e->dns.name, ipaddr_ntoa(&e->dns.addr));
303
+ e->client ->_dns_found (&e->dns .addr );
304
304
}
305
305
free ((void *)(e));
306
306
}
@@ -369,14 +369,14 @@ static bool _start_async_task() {
369
369
* LwIP Callbacks
370
370
* */
371
371
372
- static int8_t _tcp_clear_events (void *arg ) {
372
+ static int8_t _tcp_clear_events (AsyncClient *client ) {
373
373
lwip_tcp_event_packet_t *e = (lwip_tcp_event_packet_t *)malloc (sizeof (lwip_tcp_event_packet_t ));
374
374
if (!e) {
375
375
log_e (" Failed to allocate event packet" );
376
376
return ERR_MEM;
377
377
}
378
378
e->event = LWIP_TCP_CLEAR;
379
- e->arg = arg ;
379
+ e->client = client ;
380
380
if (!_prepend_async_event (&e)) {
381
381
free ((void *)(e));
382
382
return ERR_TIMEOUT;
@@ -392,7 +392,7 @@ static int8_t _tcp_connected(void *arg, tcp_pcb *pcb, int8_t err) {
392
392
return ERR_MEM;
393
393
}
394
394
e->event = LWIP_TCP_CONNECTED;
395
- e->arg = arg;
395
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
396
396
e->connected .pcb = pcb;
397
397
e->connected .err = err;
398
398
if (!_prepend_async_event (&e)) {
@@ -417,7 +417,7 @@ int8_t AsyncTCP_detail::tcp_poll(void *arg, struct tcp_pcb *pcb) {
417
417
return ERR_MEM;
418
418
}
419
419
e->event = LWIP_TCP_POLL;
420
- e->arg = arg;
420
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
421
421
e->poll .pcb = pcb;
422
422
// poll events are not critical 'cause those are repetitive, so we may not wait the queue in any case
423
423
if (!_send_async_event (&e, 0 )) {
@@ -433,7 +433,7 @@ int8_t AsyncTCP_detail::tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb
433
433
log_e (" Failed to allocate event packet" );
434
434
return ERR_MEM;
435
435
}
436
- e->arg = arg;
436
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
437
437
if (pb) {
438
438
// ets_printf("+R: 0x%08x\n", pcb);
439
439
e->event = LWIP_TCP_RECV;
@@ -463,7 +463,7 @@ int8_t AsyncTCP_detail::tcp_sent(void *arg, struct tcp_pcb *pcb, uint16_t len) {
463
463
return ERR_MEM;
464
464
}
465
465
e->event = LWIP_TCP_SENT;
466
- e->arg = arg;
466
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
467
467
e->sent .pcb = pcb;
468
468
e->sent .len = len;
469
469
if (!_send_async_event (&e)) {
@@ -495,7 +495,7 @@ void AsyncTCP_detail::tcp_error(void *arg, int8_t err) {
495
495
return ;
496
496
}
497
497
e->event = LWIP_TCP_ERROR;
498
- e->arg = arg ;
498
+ e->client = client ;
499
499
e->error .err = err;
500
500
if (!_send_async_event (&e)) {
501
501
::free ((void *)(e));
@@ -510,7 +510,7 @@ static void _tcp_dns_found(const char *name, struct ip_addr *ipaddr, void *arg)
510
510
}
511
511
// ets_printf("+DNS: name=%s ipaddr=0x%08x arg=%x\n", name, ipaddr, arg);
512
512
e->event = LWIP_TCP_DNS;
513
- e->arg = arg;
513
+ e->client = reinterpret_cast <AsyncClient *>( arg) ;
514
514
e->dns .name = name;
515
515
if (ipaddr) {
516
516
memcpy (&e->dns .addr , ipaddr, sizeof (struct ip_addr ));
@@ -1571,8 +1571,8 @@ int8_t AsyncTCP_detail::tcp_accept(void *arg, tcp_pcb *pcb, int8_t err) {
1571
1571
lwip_tcp_event_packet_t *e = (lwip_tcp_event_packet_t *)malloc (sizeof (lwip_tcp_event_packet_t ));
1572
1572
if (e) {
1573
1573
e->event = LWIP_TCP_ACCEPT;
1574
- e->arg = arg ;
1575
- e->accept . client = c;
1574
+ e->accept . server = server ;
1575
+ e->client = c;
1576
1576
if (_prepend_async_event (&e)) {
1577
1577
return ERR_OK; // success
1578
1578
}
0 commit comments