Skip to content

Commit c16449b

Browse files
authored
Merge branch 'master' into master
2 parents b548abc + 5f107e7 commit c16449b

File tree

11 files changed

+362
-215
lines changed

11 files changed

+362
-215
lines changed

.github/stale.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Configuration for probot-stale - https://github.com/probot/stale
2+
3+
daysUntilStale: 60
4+
daysUntilClose: 14
5+
limitPerRun: 30
6+
staleLabel: stale
7+
exemptLabels:
8+
- pinned
9+
- security
10+
- "to be implemented"
11+
- "for reference"
12+
- "move to PR"
13+
- "enhancement"
14+
15+
only: issues
16+
onlyLabels: []
17+
exemptProjects: false
18+
exemptMilestones: false
19+
exemptAssignees: false
20+
21+
markComment: >
22+
[STALE_SET] This issue has been automatically marked as stale because it has not had
23+
recent activity. It will be closed in 14 days if no further activity occurs. Thank you
24+
for your contributions.
25+
26+
unmarkComment: >
27+
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.
28+
29+
closeComment: >
30+
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.
31+

.github/workflows/main.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Async TCP CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- release/*
8+
pull_request:
9+
10+
jobs:
11+
12+
build-arduino:
13+
name: Build Arduino
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v1
17+
- name: Build Tests
18+
env:
19+
TRAVIS_BUILD_DIR: ${{ github.workspace }}
20+
run: bash $TRAVIS_BUILD_DIR/travis/build.sh
21+
22+
build-pio:
23+
name: Build PlatformIO
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v1
27+
- name: Install Python Wheel
28+
run: pip install wheel
29+
- name: Build Tests
30+
env:
31+
TRAVIS_BUILD_DIR: ${{ github.workspace }}
32+
run: bash $TRAVIS_BUILD_DIR/travis/build-pio.sh

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.DS_Store

.travis.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
sudo: false
2-
32
language: python
4-
python:
5-
- "2.7"
6-
73
os:
84
- linux
95

10-
dist:
11-
- xenial
6+
git:
7+
depth: false
8+
9+
stages:
10+
- build
11+
12+
jobs:
13+
include:
14+
15+
- name: "Arduino Build"
16+
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
17+
stage: build
18+
script: bash $TRAVIS_BUILD_DIR/travis/build.sh
1219

13-
script:
14-
- bash $TRAVIS_BUILD_DIR/travis/build.sh
20+
- name: "PlatformIO Build"
21+
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
22+
stage: build
23+
script: bash $TRAVIS_BUILD_DIR/travis/build-pio.sh
1524

1625
notifications:
1726
email:
@@ -22,4 +31,4 @@ notifications:
2231
- https://webhooks.gitter.im/e/60e65d0c78ea0a920347
2332
on_success: change # options: [always|never|change] default: always
2433
on_failure: always # options: [always|never|change] default: always
25-
on_start: never # options: [always|never|change] default: always
34+
on_start: false # default: false

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(COMPONENT_SRCDIRS
2+
"src"
3+
)
4+
5+
set(COMPONENT_ADD_INCLUDEDIRS
6+
"src"
7+
)
8+
9+
set(COMPONENT_REQUIRES
10+
"arduino-esp32"
11+
)
12+
13+
register_component()
14+
15+
target_compile_options(${COMPONENT_TARGET} PRIVATE -fno-rtti)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Async TCP Library for ESP32 Arduino
33

44
[![Join the chat at https://gitter.im/me-no-dev/ESPAsyncWebServer](https://badges.gitter.im/me-no-dev/ESPAsyncWebServer.svg)](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
55

6+
[![Build Status](https://travis-ci.org/me-no-dev/AsyncTCP.svg?branch=master)](https://travis-ci.org/me-no-dev/AsyncTCP)
7+
68
This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP32 MCUs.
79

810
This library is the base for [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer)

src/AsyncTCP.cpp

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ typedef struct {
7878

7979
static xQueueHandle _async_queue;
8080
static TaskHandle_t _async_service_task_handle = NULL;
81+
static tcp_pcb * pcb_recently_closed = NULL;
8182

8283
static inline bool _init_async_event_queue(){
8384
if(!_async_queue){
@@ -297,10 +298,15 @@ static void _tcp_error(void * arg, int8_t err) {
297298

298299
static void _tcp_dns_found(const char * name, struct ip_addr * ipaddr, void * arg) {
299300
lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t));
301+
//ets_printf("+DNS: name=%s ipaddr=0x%08x arg=%x\n", name, ipaddr, arg);
300302
e->event = LWIP_TCP_DNS;
301303
e->arg = arg;
302304
e->dns.name = name;
303-
memcpy(&e->dns.addr, ipaddr, sizeof(struct ip_addr));
305+
if (ipaddr) {
306+
memcpy(&e->dns.addr, ipaddr, sizeof(struct ip_addr));
307+
} else {
308+
memset(&e->dns.addr, 0, sizeof(e->dns.addr));
309+
}
304310
if (!_send_async_event(&e)) {
305311
free((void*)(e));
306312
}
@@ -327,7 +333,6 @@ static int8_t _tcp_accept(void * arg, AsyncClient * client) {
327333
typedef struct {
328334
struct tcpip_api_call_data call;
329335
tcp_pcb * pcb;
330-
AsyncClient * client;
331336
int8_t err;
332337
union {
333338
struct {
@@ -352,39 +357,39 @@ typedef struct {
352357
static err_t _tcp_output_api(struct tcpip_api_call_data *api_call_msg){
353358
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
354359
msg->err = ERR_CONN;
355-
if(msg->client && msg->client->pcb() == msg->pcb){
360+
if(msg->pcb != pcb_recently_closed) {
356361
msg->err = tcp_output(msg->pcb);
357362
}
363+
pcb_recently_closed = NULL;
358364
return msg->err;
359365
}
360366

361-
static esp_err_t _tcp_output(tcp_pcb * pcb, AsyncClient * client) {
367+
static esp_err_t _tcp_output(tcp_pcb * pcb) {
362368
if(!pcb){
363369
return ERR_CONN;
364370
}
365371
tcp_api_call_t msg;
366372
msg.pcb = pcb;
367-
msg.client = client;
368373
tcpip_api_call(_tcp_output_api, (struct tcpip_api_call_data*)&msg);
369374
return msg.err;
370375
}
371376

372377
static err_t _tcp_write_api(struct tcpip_api_call_data *api_call_msg){
373378
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
374379
msg->err = ERR_CONN;
375-
if(msg->client && msg->client->pcb() == msg->pcb){
380+
if(msg->pcb != pcb_recently_closed) {
376381
msg->err = tcp_write(msg->pcb, msg->write.data, msg->write.size, msg->write.apiflags);
377382
}
383+
pcb_recently_closed = NULL;
378384
return msg->err;
379385
}
380386

381-
static esp_err_t _tcp_write(tcp_pcb * pcb, const char* data, size_t size, uint8_t apiflags, AsyncClient * client) {
387+
static esp_err_t _tcp_write(tcp_pcb * pcb, const char* data, size_t size, uint8_t apiflags) {
382388
if(!pcb){
383389
return ERR_CONN;
384390
}
385391
tcp_api_call_t msg;
386392
msg.pcb = pcb;
387-
msg.client = client;
388393
msg.write.data = data;
389394
msg.write.size = size;
390395
msg.write.apiflags = apiflags;
@@ -395,20 +400,20 @@ static esp_err_t _tcp_write(tcp_pcb * pcb, const char* data, size_t size, uint8_
395400
static err_t _tcp_recved_api(struct tcpip_api_call_data *api_call_msg){
396401
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
397402
msg->err = ERR_CONN;
398-
if(msg->client && msg->client->pcb() == msg->pcb){
403+
if(msg->pcb != pcb_recently_closed) {
399404
msg->err = 0;
400405
tcp_recved(msg->pcb, msg->received);
401406
}
407+
pcb_recently_closed = NULL;
402408
return msg->err;
403409
}
404410

405-
static esp_err_t _tcp_recved(tcp_pcb * pcb, size_t len, AsyncClient * client) {
411+
static esp_err_t _tcp_recved(tcp_pcb * pcb, size_t len) {
406412
if(!pcb){
407413
return ERR_CONN;
408414
}
409415
tcp_api_call_t msg;
410416
msg.pcb = pcb;
411-
msg.client = client;
412417
msg.received = len;
413418
tcpip_api_call(_tcp_recved_api, (struct tcpip_api_call_data*)&msg);
414419
return msg.err;
@@ -417,39 +422,39 @@ static esp_err_t _tcp_recved(tcp_pcb * pcb, size_t len, AsyncClient * client) {
417422
static err_t _tcp_close_api(struct tcpip_api_call_data *api_call_msg){
418423
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
419424
msg->err = ERR_CONN;
420-
if(!msg->client || msg->client->pcb() == msg->pcb){
425+
if(msg->pcb != pcb_recently_closed) {
421426
msg->err = tcp_close(msg->pcb);
422427
}
428+
pcb_recently_closed = NULL;
423429
return msg->err;
424430
}
425431

426-
static esp_err_t _tcp_close(tcp_pcb * pcb, AsyncClient * client) {
432+
static esp_err_t _tcp_close(tcp_pcb * pcb) {
427433
if(!pcb){
428434
return ERR_CONN;
429435
}
430436
tcp_api_call_t msg;
431437
msg.pcb = pcb;
432-
msg.client = client;
433438
tcpip_api_call(_tcp_close_api, (struct tcpip_api_call_data*)&msg);
434439
return msg.err;
435440
}
436441

437442
static err_t _tcp_abort_api(struct tcpip_api_call_data *api_call_msg){
438443
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
439444
msg->err = ERR_CONN;
440-
if(!msg->client || msg->client->pcb() == msg->pcb){
445+
if(msg->pcb != pcb_recently_closed) {
441446
tcp_abort(msg->pcb);
442447
}
448+
pcb_recently_closed = NULL;
443449
return msg->err;
444450
}
445451

446-
static esp_err_t _tcp_abort(tcp_pcb * pcb, AsyncClient * client) {
452+
static esp_err_t _tcp_abort(tcp_pcb * pcb) {
447453
if(!pcb){
448454
return ERR_CONN;
449455
}
450456
tcp_api_call_t msg;
451457
msg.pcb = pcb;
452-
msg.client = client;
453458
tcpip_api_call(_tcp_abort_api, (struct tcpip_api_call_data*)&msg);
454459
return msg.err;
455460
}
@@ -697,14 +702,14 @@ bool AsyncClient::connect(const char* host, uint16_t port){
697702

698703
void AsyncClient::close(bool now){
699704
if(_pcb){
700-
_tcp_recved(_pcb, _rx_ack_len, this);
705+
_tcp_recved(_pcb, _rx_ack_len);
701706
}
702707
_close();
703708
}
704709

705710
int8_t AsyncClient::abort(){
706711
if(_pcb) {
707-
_tcp_abort(_pcb, this);
712+
_tcp_abort(_pcb);
708713
_pcb = NULL;
709714
}
710715
return ERR_ABRT;
@@ -727,7 +732,7 @@ size_t AsyncClient::add(const char* data, size_t size, uint8_t apiflags) {
727732
}
728733
size_t will_send = (room < size) ? room : size;
729734
int8_t err = ERR_OK;
730-
err = _tcp_write(_pcb, data, will_send, apiflags, this);
735+
err = _tcp_write(_pcb, data, will_send, apiflags);
731736
if(err != ERR_OK) {
732737
return 0;
733738
}
@@ -736,7 +741,7 @@ size_t AsyncClient::add(const char* data, size_t size, uint8_t apiflags) {
736741

737742
bool AsyncClient::send(){
738743
int8_t err = ERR_OK;
739-
err = _tcp_output(_pcb, this);
744+
err = _tcp_output(_pcb);
740745
if(err == ERR_OK){
741746
_pcb_busy = true;
742747
_pcb_sent_at = millis();
@@ -749,7 +754,7 @@ size_t AsyncClient::ack(size_t len){
749754
if(len > _rx_ack_len)
750755
len = _rx_ack_len;
751756
if(len){
752-
_tcp_recved(_pcb, len, this);
757+
_tcp_recved(_pcb, len);
753758
}
754759
_rx_ack_len -= len;
755760
return len;
@@ -759,7 +764,7 @@ void AsyncClient::ackPacket(struct pbuf * pb){
759764
if(!pb){
760765
return;
761766
}
762-
_tcp_recved(_pcb, pb->len, this);
767+
_tcp_recved(_pcb, pb->len);
763768
pbuf_free(pb);
764769
}
765770

@@ -778,7 +783,7 @@ int8_t AsyncClient::_close(){
778783
tcp_err(_pcb, NULL);
779784
tcp_poll(_pcb, NULL, 0);
780785
_tcp_clear_events(this);
781-
err = _tcp_close(_pcb, this);
786+
err = _tcp_close(_pcb);
782787
if(err != ERR_OK) {
783788
err = abort();
784789
}
@@ -840,6 +845,7 @@ int8_t AsyncClient::_lwip_fin(tcp_pcb* pcb, int8_t err) {
840845
if(tcp_close(_pcb) != ERR_OK) {
841846
tcp_abort(_pcb);
842847
}
848+
pcb_recently_closed = _pcb;
843849
_pcb = NULL;
844850
return ERR_OK;
845851
}
@@ -880,7 +886,7 @@ int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) {
880886
if(!_ack_pcb) {
881887
_rx_ack_len += b->len;
882888
} else if(_pcb) {
883-
_tcp_recved(_pcb, b->len, this);
889+
_tcp_recved(_pcb, b->len);
884890
}
885891
pbuf_free(b);
886892
}
@@ -922,7 +928,7 @@ int8_t AsyncClient::_poll(tcp_pcb* pcb){
922928
}
923929

924930
void AsyncClient::_dns_found(struct ip_addr *ipaddr){
925-
if(ipaddr){
931+
if(ipaddr && ipaddr->u_addr.ip4.addr){
926932
connect(IPAddress(ipaddr->u_addr.ip4.addr), _connect_port);
927933
} else {
928934
if(_error_cb) {
@@ -1227,7 +1233,7 @@ void AsyncServer::begin(){
12271233
err = _tcp_bind(_pcb, &local_addr, _port);
12281234

12291235
if (err != ERR_OK) {
1230-
_tcp_close(_pcb, NULL);
1236+
_tcp_close(_pcb);
12311237
log_e("bind error: %d", err);
12321238
return;
12331239
}

0 commit comments

Comments
 (0)