From 036ea44f8a3f5442a506fd2704f26335ba9c32ad Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 16 Oct 2017 22:26:41 +0300 Subject: [PATCH 01/11] Fix compilation errors Fixes: https://github.com/me-no-dev/ESPAsyncTCP/issues/57 Fixes: https://github.com/me-no-dev/ESPAsyncTCP/pull/56 Closes: https://github.com/me-no-dev/ESPAsyncTCP/pull/56 --- src/ESPAsyncTCP.cpp | 24 ++++++++++++------------ src/ESPAsyncTCP.h | 32 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index 728d85e..ba19776 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -281,7 +281,7 @@ size_t AsyncClient::ack(size_t len){ // Private Callbacks -int8_t AsyncClient::_connected(void* pcb, int8_t err){ +long AsyncClient::_connected(void* pcb, long err){ _pcb = reinterpret_cast(pcb); if(_pcb){ _pcb_busy = false; @@ -334,7 +334,7 @@ int8_t AsyncClient::_close(){ return err; } -void AsyncClient::_error(int8_t err) { +void AsyncClient::_error(long err) { if(_pcb){ #if ASYNC_TCP_SSL_ENABLED if(_pcb_secure){ @@ -361,7 +361,7 @@ void AsyncClient::_ssl_error(int8_t err){ } #endif -int8_t AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) { +long AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) { _rx_last_packet = millis(); ASYNC_TCP_DEBUG("_sent: %u\n", len); _tx_unacked_len -= len; @@ -375,7 +375,7 @@ int8_t AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) { return ERR_OK; } -int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) { +long AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, long err) { if(pb == NULL){ ASYNC_TCP_DEBUG("_recv: pb == NULL! Closing... %d\n", err); return _close(); @@ -414,7 +414,7 @@ int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) { return ERR_OK; } -int8_t AsyncClient::_poll(tcp_pcb* pcb){ +long AsyncClient::_poll(tcp_pcb* pcb){ // Close requested if(_close_pcb){ _close_pcb = false; @@ -469,23 +469,23 @@ void AsyncClient::_s_dns_found(const char *name, ip_addr_t *ipaddr, void *arg){ reinterpret_cast(arg)->_dns_found(ipaddr); } -int8_t AsyncClient::_s_poll(void *arg, struct tcp_pcb *tpcb) { +long AsyncClient::_s_poll(void *arg, struct tcp_pcb *tpcb) { return reinterpret_cast(arg)->_poll(tpcb); } -int8_t AsyncClient::_s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, int8_t err) { +long AsyncClient::_s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err) { return reinterpret_cast(arg)->_recv(tpcb, pb, err); } -void AsyncClient::_s_error(void *arg, int8_t err) { +void AsyncClient::_s_error(void *arg, long err) { reinterpret_cast(arg)->_error(err); } -int8_t AsyncClient::_s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len) { +long AsyncClient::_s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len) { return reinterpret_cast(arg)->_sent(tpcb, len); } -int8_t AsyncClient::_s_connected(void* arg, void* tpcb, int8_t err){ +long AsyncClient::_s_connected(void* arg, void* tpcb, long err){ return reinterpret_cast(arg)->_connected(tpcb, err); } @@ -896,7 +896,7 @@ uint8_t AsyncServer::status(){ return _pcb->state; } -int8_t AsyncServer::_accept(tcp_pcb* pcb, int8_t err){ +long AsyncServer::_accept(tcp_pcb* pcb, long err){ if(_connect_cb){ #if ASYNC_TCP_SSL_ENABLED if (_noDelay || _ssl_ctx) @@ -964,7 +964,7 @@ int8_t AsyncServer::_accept(tcp_pcb* pcb, int8_t err){ return ERR_OK; } - int8_t AsyncServer::_s_accept(void *arg, tcp_pcb* pcb, int8_t err){ + long AsyncServer::_s_accept(void *arg, tcp_pcb* pcb, long err){ return reinterpret_cast(arg)->_accept(pcb, err); } diff --git a/src/ESPAsyncTCP.h b/src/ESPAsyncTCP.h index bd08b87..d031c4e 100644 --- a/src/ESPAsyncTCP.h +++ b/src/ESPAsyncTCP.h @@ -84,19 +84,19 @@ class AsyncClient { uint16_t _connect_port; int8_t _close(); - int8_t _connected(void* pcb, int8_t err); - void _error(int8_t err); + long _connected(void* pcb, long err); + void _error(long err); #if ASYNC_TCP_SSL_ENABLED void _ssl_error(int8_t err); #endif - int8_t _poll(tcp_pcb* pcb); - int8_t _sent(tcp_pcb* pcb, uint16_t len); + long _poll(tcp_pcb* pcb); + long _sent(tcp_pcb* pcb, uint16_t len); void _dns_found(struct ip_addr *ipaddr); - static int8_t _s_poll(void *arg, struct tcp_pcb *tpcb); - static int8_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, int8_t err); - static void _s_error(void *arg, int8_t err); - static int8_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); - static int8_t _s_connected(void* arg, void* tpcb, int8_t err); + static long _s_poll(void *arg, struct tcp_pcb *tpcb); + static long _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err); + static void _s_error(void *arg, long err); + static long _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); + static long _s_connected(void* arg, void* tpcb, long err); static void _s_dns_found(const char *name, struct ip_addr *ipaddr, void *arg); #if ASYNC_TCP_SSL_ENABLED static void _s_data(void *arg, struct tcp_pcb *tcp, uint8_t * data, size_t len); @@ -184,7 +184,7 @@ class AsyncClient { const char * errorToString(int8_t error); const char * stateToString(); - int8_t _recv(tcp_pcb* pcb, pbuf* pb, int8_t err); + long _recv(tcp_pcb* pcb, pbuf* pb, long err); }; #if ASYNC_TCP_SSL_ENABLED @@ -224,15 +224,15 @@ class AsyncServer { uint8_t status(); protected: - int8_t _accept(tcp_pcb* newpcb, int8_t err); - static int8_t _s_accept(void *arg, tcp_pcb* newpcb, int8_t err); + long _accept(tcp_pcb* newpcb, long err); + static long _s_accept(void *arg, tcp_pcb* newpcb, long err); #if ASYNC_TCP_SSL_ENABLED int _cert(const char *filename, uint8_t **buf); - int8_t _poll(tcp_pcb* pcb); - int8_t _recv(tcp_pcb *pcb, struct pbuf *pb, int8_t err); + long _poll(tcp_pcb* pcb); + long _recv(tcp_pcb *pcb, struct pbuf *pb, long err); static int _s_cert(void *arg, const char *filename, uint8_t **buf); - static int8_t _s_poll(void *arg, struct tcp_pcb *tpcb); - static int8_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, int8_t err); + static long _s_poll(void *arg, struct tcp_pcb *tpcb); + static long _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err); #endif }; From 3795e162419cf412cc983e8b58954b79e710dc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 25 Oct 2017 00:10:15 +0200 Subject: [PATCH 02/11] Fix compilation errors when ASYNC_TCP_SSL_ENABLED (#58) --- src/ESPAsyncTCP.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index ba19776..ed0e70d 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -969,7 +969,7 @@ long AsyncServer::_accept(tcp_pcb* pcb, long err){ } #if ASYNC_TCP_SSL_ENABLED -int8_t AsyncServer::_poll(tcp_pcb* pcb){ +long AsyncServer::_poll(tcp_pcb* pcb){ if(!tcp_ssl_has_client() && _pending){ struct pending_pcb * p = _pending; if(p->pcb == pcb){ @@ -995,7 +995,7 @@ int8_t AsyncServer::_poll(tcp_pcb* pcb){ return ERR_OK; } -int8_t AsyncServer::_recv(struct tcp_pcb *pcb, struct pbuf *pb, int8_t err){ +long AsyncServer::_recv(struct tcp_pcb *pcb, struct pbuf *pb, long err){ if(!_pending) return ERR_OK; @@ -1047,11 +1047,11 @@ int AsyncServer::_s_cert(void *arg, const char *filename, uint8_t **buf){ return reinterpret_cast(arg)->_cert(filename, buf); } -int8_t AsyncServer::_s_poll(void *arg, struct tcp_pcb *pcb){ +long AsyncServer::_s_poll(void *arg, struct tcp_pcb *pcb){ return reinterpret_cast(arg)->_poll(pcb); } -int8_t AsyncServer::_s_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, int8_t err){ +long AsyncServer::_s_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, long err){ return reinterpret_cast(arg)->_recv(pcb, pb, err); } #endif From 94c7dfe1449274681680a9a1b890defde891d95c Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Wed, 1 Nov 2017 18:23:58 +0200 Subject: [PATCH 03/11] Jump version for PIO --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index a229f92..71d9da7 100644 --- a/library.json +++ b/library.json @@ -12,7 +12,7 @@ "type": "git", "url": "https://github.com/me-no-dev/ESPAsyncTCP.git" }, - "version": "1.1.0", + "version": "1.1.1", "license": "LGPL-3.0", "frameworks": "arduino", "platforms":"espressif8266" From f1b79ef306659256bf642613c4ce6a90102b9748 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 3 Nov 2017 19:30:58 +0200 Subject: [PATCH 04/11] Add fix for LwIP2 --- src/ESPAsyncTCP.cpp | 15 ++++++++++++--- src/ESPAsyncTCP.h | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index ed0e70d..593d6d6 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -27,6 +27,7 @@ extern "C"{ #include "lwip/tcp.h" #include "lwip/inet.h" #include "lwip/dns.h" + #include "lwip/init.h" } #include @@ -110,11 +111,12 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){ return false; ip_addr_t addr; addr.addr = ip; +#if LWIP_VERSION_MAJOR == 1 netif* interface = ip_route(&addr); if (!interface){ //no route to host return false; } - +#endif tcp_pcb* pcb = tcp_new(); if (!pcb){ //could not allocate pcb return false; @@ -448,7 +450,11 @@ long AsyncClient::_poll(tcp_pcb* pcb){ return ERR_OK; } -void AsyncClient::_dns_found(ip_addr_t *ipaddr){ +#if LWIP_VERSION_MAJOR == 1 +void AsyncClient::_dns_found(struct ip_addr *ipaddr){ +#else +void AsyncClient::_dns_found(const ip_addr *ipaddr){ +#endif if(ipaddr){ #if ASYNC_TCP_SSL_ENABLED connect(IPAddress(ipaddr->addr), _connect_port, _pcb_secure); @@ -464,8 +470,11 @@ void AsyncClient::_dns_found(ip_addr_t *ipaddr){ } // lWIP Callbacks - +#if LWIP_VERSION_MAJOR == 1 void AsyncClient::_s_dns_found(const char *name, ip_addr_t *ipaddr, void *arg){ +#else +void AsyncClient::_s_dns_found(const char *name, const ip_addr *ipaddr, void *arg){ +#endif reinterpret_cast(arg)->_dns_found(ipaddr); } diff --git a/src/ESPAsyncTCP.h b/src/ESPAsyncTCP.h index d031c4e..232f85f 100644 --- a/src/ESPAsyncTCP.h +++ b/src/ESPAsyncTCP.h @@ -91,13 +91,21 @@ class AsyncClient { #endif long _poll(tcp_pcb* pcb); long _sent(tcp_pcb* pcb, uint16_t len); +#if LWIP_VERSION_MAJOR == 1 void _dns_found(struct ip_addr *ipaddr); +#else + void _dns_found(const ip_addr *ipaddr); +#endif static long _s_poll(void *arg, struct tcp_pcb *tpcb); static long _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err); static void _s_error(void *arg, long err); static long _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); static long _s_connected(void* arg, void* tpcb, long err); +#if LWIP_VERSION_MAJOR == 1 static void _s_dns_found(const char *name, struct ip_addr *ipaddr, void *arg); +#else + static void _s_dns_found(const char *name, const ip_addr *ipaddr, void *arg); +#endif #if ASYNC_TCP_SSL_ENABLED static void _s_data(void *arg, struct tcp_pcb *tcp, uint8_t * data, size_t len); static void _s_handshake(void *arg, struct tcp_pcb *tcp, SSL *ssl); From 934f7c41a25e350ceaf603f0cfa77dc9edd5c7e1 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 3 Nov 2017 22:25:35 +0200 Subject: [PATCH 05/11] Add missing include --- src/ESPAsyncTCP.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ESPAsyncTCP.h b/src/ESPAsyncTCP.h index 232f85f..1e72dfd 100644 --- a/src/ESPAsyncTCP.h +++ b/src/ESPAsyncTCP.h @@ -25,6 +25,7 @@ #include #include "IPAddress.h" #include +#include "lwip/init.h" class AsyncClient; From 4033fc690fb7ea78a67faa1ae44d02350abd2d01 Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 8 Nov 2017 09:58:47 +0100 Subject: [PATCH 06/11] Support staging platform (#69) --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 71d9da7..56d2b29 100644 --- a/library.json +++ b/library.json @@ -15,5 +15,5 @@ "version": "1.1.1", "license": "LGPL-3.0", "frameworks": "arduino", - "platforms":"espressif8266" + "platforms": ["espressif8266", "espressif8266_stage"] } From 289a68155111892fc54ce9d8b23950ba5444f910 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Wed, 8 Nov 2017 10:59:35 +0200 Subject: [PATCH 07/11] bump pio version --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 56d2b29..6f93411 100644 --- a/library.json +++ b/library.json @@ -12,7 +12,7 @@ "type": "git", "url": "https://github.com/me-no-dev/ESPAsyncTCP.git" }, - "version": "1.1.1", + "version": "1.1.2", "license": "LGPL-3.0", "frameworks": "arduino", "platforms": ["espressif8266", "espressif8266_stage"] From a57560d977602145cfadae84ae28f2ec69b361f5 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 20 Nov 2017 00:00:19 +0100 Subject: [PATCH 08/11] use err_t for compatibility Fixes: https://github.com/me-no-dev/ESPAsyncTCP/issues/60 --- src/ESPAsyncTCP.cpp | 32 ++++++++++++++++---------------- src/ESPAsyncTCP.h | 38 +++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index 593d6d6..0c91d58 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -283,7 +283,7 @@ size_t AsyncClient::ack(size_t len){ // Private Callbacks -long AsyncClient::_connected(void* pcb, long err){ +err_t AsyncClient::_connected(void* pcb, err_t err){ _pcb = reinterpret_cast(pcb); if(_pcb){ _pcb_busy = false; @@ -336,7 +336,7 @@ int8_t AsyncClient::_close(){ return err; } -void AsyncClient::_error(long err) { +void AsyncClient::_error(err_t err) { if(_pcb){ #if ASYNC_TCP_SSL_ENABLED if(_pcb_secure){ @@ -363,7 +363,7 @@ void AsyncClient::_ssl_error(int8_t err){ } #endif -long AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) { +err_t AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) { _rx_last_packet = millis(); ASYNC_TCP_DEBUG("_sent: %u\n", len); _tx_unacked_len -= len; @@ -377,7 +377,7 @@ long AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) { return ERR_OK; } -long AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, long err) { +err_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, err_t err) { if(pb == NULL){ ASYNC_TCP_DEBUG("_recv: pb == NULL! Closing... %d\n", err); return _close(); @@ -416,7 +416,7 @@ long AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, long err) { return ERR_OK; } -long AsyncClient::_poll(tcp_pcb* pcb){ +err_t AsyncClient::_poll(tcp_pcb* pcb){ // Close requested if(_close_pcb){ _close_pcb = false; @@ -478,23 +478,23 @@ void AsyncClient::_s_dns_found(const char *name, const ip_addr *ipaddr, void *ar reinterpret_cast(arg)->_dns_found(ipaddr); } -long AsyncClient::_s_poll(void *arg, struct tcp_pcb *tpcb) { +err_t AsyncClient::_s_poll(void *arg, struct tcp_pcb *tpcb) { return reinterpret_cast(arg)->_poll(tpcb); } -long AsyncClient::_s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err) { +err_t AsyncClient::_s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err) { return reinterpret_cast(arg)->_recv(tpcb, pb, err); } -void AsyncClient::_s_error(void *arg, long err) { +void AsyncClient::_s_error(void *arg, err_t err) { reinterpret_cast(arg)->_error(err); } -long AsyncClient::_s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len) { +err_t AsyncClient::_s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len) { return reinterpret_cast(arg)->_sent(tpcb, len); } -long AsyncClient::_s_connected(void* arg, void* tpcb, long err){ +err_t AsyncClient::_s_connected(void* arg, void* tpcb, err_t err){ return reinterpret_cast(arg)->_connected(tpcb, err); } @@ -905,7 +905,7 @@ uint8_t AsyncServer::status(){ return _pcb->state; } -long AsyncServer::_accept(tcp_pcb* pcb, long err){ +err_t AsyncServer::_accept(tcp_pcb* pcb, err_t err){ if(_connect_cb){ #if ASYNC_TCP_SSL_ENABLED if (_noDelay || _ssl_ctx) @@ -973,12 +973,12 @@ long AsyncServer::_accept(tcp_pcb* pcb, long err){ return ERR_OK; } - long AsyncServer::_s_accept(void *arg, tcp_pcb* pcb, long err){ + err_t AsyncServer::_s_accept(void *arg, tcp_pcb* pcb, err_t err){ return reinterpret_cast(arg)->_accept(pcb, err); } #if ASYNC_TCP_SSL_ENABLED -long AsyncServer::_poll(tcp_pcb* pcb){ +err_t AsyncServer::_poll(tcp_pcb* pcb){ if(!tcp_ssl_has_client() && _pending){ struct pending_pcb * p = _pending; if(p->pcb == pcb){ @@ -1004,7 +1004,7 @@ long AsyncServer::_poll(tcp_pcb* pcb){ return ERR_OK; } -long AsyncServer::_recv(struct tcp_pcb *pcb, struct pbuf *pb, long err){ +err_t AsyncServer::_recv(struct tcp_pcb *pcb, struct pbuf *pb, err_t err){ if(!_pending) return ERR_OK; @@ -1056,11 +1056,11 @@ int AsyncServer::_s_cert(void *arg, const char *filename, uint8_t **buf){ return reinterpret_cast(arg)->_cert(filename, buf); } -long AsyncServer::_s_poll(void *arg, struct tcp_pcb *pcb){ +err_t AsyncServer::_s_poll(void *arg, struct tcp_pcb *pcb){ return reinterpret_cast(arg)->_poll(pcb); } -long AsyncServer::_s_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, long err){ +err_t AsyncServer::_s_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, err_t err){ return reinterpret_cast(arg)->_recv(pcb, pb, err); } #endif diff --git a/src/ESPAsyncTCP.h b/src/ESPAsyncTCP.h index 1e72dfd..0c04721 100644 --- a/src/ESPAsyncTCP.h +++ b/src/ESPAsyncTCP.h @@ -25,7 +25,11 @@ #include #include "IPAddress.h" #include -#include "lwip/init.h" + +extern "C" { + #include "lwip/init.h" + #include "lwip/err.h" +}; class AsyncClient; @@ -85,23 +89,23 @@ class AsyncClient { uint16_t _connect_port; int8_t _close(); - long _connected(void* pcb, long err); - void _error(long err); + err_t _connected(void* pcb, err_t err); + void _error(err_t err); #if ASYNC_TCP_SSL_ENABLED void _ssl_error(int8_t err); #endif - long _poll(tcp_pcb* pcb); - long _sent(tcp_pcb* pcb, uint16_t len); + err_t _poll(tcp_pcb* pcb); + err_t _sent(tcp_pcb* pcb, uint16_t len); #if LWIP_VERSION_MAJOR == 1 void _dns_found(struct ip_addr *ipaddr); #else void _dns_found(const ip_addr *ipaddr); #endif - static long _s_poll(void *arg, struct tcp_pcb *tpcb); - static long _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err); - static void _s_error(void *arg, long err); - static long _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); - static long _s_connected(void* arg, void* tpcb, long err); + static err_t _s_poll(void *arg, struct tcp_pcb *tpcb); + static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err); + static void _s_error(void *arg, err_t err); + static err_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); + static err_t _s_connected(void* arg, void* tpcb, err_t err); #if LWIP_VERSION_MAJOR == 1 static void _s_dns_found(const char *name, struct ip_addr *ipaddr, void *arg); #else @@ -193,7 +197,7 @@ class AsyncClient { const char * errorToString(int8_t error); const char * stateToString(); - long _recv(tcp_pcb* pcb, pbuf* pb, long err); + err_t _recv(tcp_pcb* pcb, pbuf* pb, err_t err); }; #if ASYNC_TCP_SSL_ENABLED @@ -233,15 +237,15 @@ class AsyncServer { uint8_t status(); protected: - long _accept(tcp_pcb* newpcb, long err); - static long _s_accept(void *arg, tcp_pcb* newpcb, long err); + err_t _accept(tcp_pcb* newpcb, err_t err); + static err_t _s_accept(void *arg, tcp_pcb* newpcb, err_t err); #if ASYNC_TCP_SSL_ENABLED int _cert(const char *filename, uint8_t **buf); - long _poll(tcp_pcb* pcb); - long _recv(tcp_pcb *pcb, struct pbuf *pb, long err); + err_t _poll(tcp_pcb* pcb); + err_t _recv(tcp_pcb *pcb, struct pbuf *pb, err_t err); static int _s_cert(void *arg, const char *filename, uint8_t **buf); - static long _s_poll(void *arg, struct tcp_pcb *tpcb); - static long _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err); + static err_t _s_poll(void *arg, struct tcp_pcb *tpcb); + static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err); #endif }; From eadb1be14480a26d20ccf64b85955bce585b934b Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sun, 26 Nov 2017 00:52:19 +0200 Subject: [PATCH 09/11] Check for compatible framework and dev/platform before build (#71) --- library.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 6f93411..76816d0 100644 --- a/library.json +++ b/library.json @@ -12,8 +12,11 @@ "type": "git", "url": "https://github.com/me-no-dev/ESPAsyncTCP.git" }, - "version": "1.1.2", + "version": "1.1.3", "license": "LGPL-3.0", "frameworks": "arduino", - "platforms": ["espressif8266", "espressif8266_stage"] + "platforms": "espressif8266", + "build": { + "libCompatMode": 2 + } } From 084eb0bc5fd615254542fc8e2958ac7857774edd Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Tue, 28 Nov 2017 10:58:37 +0100 Subject: [PATCH 10/11] Update ESPAsyncTCP.cpp --- src/ESPAsyncTCP.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index 0c91d58..6f80e21 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -864,7 +864,6 @@ void AsyncServer::beginSecure(const char *cert, const char *key, const char *pas void AsyncServer::end(){ if(_pcb){ //cleanup all connections? - tcp_abort(_pcb); tcp_arg(_pcb, NULL); tcp_accept(_pcb, NULL); if(tcp_close(_pcb) != ERR_OK){ From 55cd520add92ee588fbfea88755a602ace0ad915 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 19 Jan 2018 23:36:18 +0200 Subject: [PATCH 11/11] Add posibility to handle packet buffers directly --- src/ESPAsyncTCP.cpp | 35 +++++++++++++++++++++++++++-------- src/ESPAsyncTCP.h | 22 ++++++++++++++-------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index 6f80e21..c3fc6e7 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -50,6 +50,8 @@ AsyncClient::AsyncClient(tcp_pcb* pcb): , _error_cb_arg(0) , _recv_cb(0) , _recv_cb_arg(0) + , _pb_cb(0) + , _pb_cb_arg(0) , _timeout_cb(0) , _timeout_cb_arg(0) , _pcb_busy(false) @@ -402,16 +404,20 @@ err_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, err_t err) { //we should not ack before we assimilate the data _ack_pcb = true; pbuf *b = pb; - ASYNC_TCP_DEBUG("_recv: %d\n", b->len); - if(_recv_cb) - _recv_cb(_recv_cb_arg, this, b->payload, b->len); - if(!_ack_pcb) - _rx_ack_len += b->len; - else - tcp_recved(pcb, b->len); pb = b->next; b->next = NULL; - pbuf_free(b); + ASYNC_TCP_DEBUG("_recv: %d\n", b->len); + if(_pb_cb){ + _pb_cb(_pb_cb_arg, this, b); + } else { + if(_recv_cb) + _recv_cb(_recv_cb_arg, this, b->payload, b->len); + if(!_ack_pcb) + _rx_ack_len += b->len; + else + tcp_recved(pcb, b->len); + pbuf_free(b); + } } return ERR_OK; } @@ -690,6 +696,11 @@ void AsyncClient::onData(AcDataHandler cb, void* arg){ _recv_cb_arg = arg; } +void AsyncClient::onPacket(AcPacketHandler cb, void* arg){ + _pb_cb = cb; + _pb_cb_arg = arg; +} + void AsyncClient::onTimeout(AcTimeoutHandler cb, void* arg){ _timeout_cb = cb; _timeout_cb_arg = arg; @@ -724,6 +735,14 @@ size_t AsyncClient::space(){ return 0; } +void AsyncClient::ackPacket(struct pbuf * pb){ + if(!pb){ + return; + } + tcp_recved(_pcb, pb->len); + pbuf_free(pb); +} + const char * AsyncClient::errorToString(int8_t error){ switch(error){ case 0: return "OK"; diff --git a/src/ESPAsyncTCP.h b/src/ESPAsyncTCP.h index 0c04721..c1803b4 100644 --- a/src/ESPAsyncTCP.h +++ b/src/ESPAsyncTCP.h @@ -29,6 +29,7 @@ extern "C" { #include "lwip/init.h" #include "lwip/err.h" + #include "lwip/pbuf.h" }; class AsyncClient; @@ -37,14 +38,7 @@ class AsyncClient; #define ASYNC_WRITE_FLAG_COPY 0x01 //will allocate new buffer to hold the data while sending (else will hold reference to the data given) #define ASYNC_WRITE_FLAG_MORE 0x02 //will not send PSH flag, meaning that there should be more data to be sent before the application should react. -typedef std::function AcConnectHandler; -typedef std::function AcAckHandler; -typedef std::function AcErrorHandler; -typedef std::function AcDataHandler; -typedef std::function AcTimeoutHandler; - struct tcp_pcb; -struct pbuf; struct ip_addr; #if ASYNC_TCP_SSL_ENABLED struct SSL_; @@ -53,6 +47,13 @@ struct SSL_CTX_; typedef struct SSL_CTX_ SSL_CTX; #endif +typedef std::function AcConnectHandler; +typedef std::function AcAckHandler; +typedef std::function AcErrorHandler; +typedef std::function AcDataHandler; +typedef std::function AcPacketHandler; +typedef std::function AcTimeoutHandler; + class AsyncClient { protected: friend class AsyncTCPbuffer; @@ -67,6 +68,8 @@ class AsyncClient { void* _error_cb_arg; AcDataHandler _recv_cb; void* _recv_cb_arg; + AcPacketHandler _pb_cb; + void* _pb_cb_arg; AcTimeoutHandler _timeout_cb; void* _timeout_cb_arg; AcConnectHandler _poll_cb; @@ -190,10 +193,13 @@ class AsyncClient { void onDisconnect(AcConnectHandler cb, void* arg = 0); //disconnected void onAck(AcAckHandler cb, void* arg = 0); //ack received void onError(AcErrorHandler cb, void* arg = 0); //unsuccessful connect or error - void onData(AcDataHandler cb, void* arg = 0); //data received + void onData(AcDataHandler cb, void* arg = 0); //data received (called if onPacket is not used) + void onPacket(AcPacketHandler cb, void* arg = 0); //data received void onTimeout(AcTimeoutHandler cb, void* arg = 0); //ack timeout void onPoll(AcConnectHandler cb, void* arg = 0); //every 125ms when connected + void ackPacket(struct pbuf * pb); + const char * errorToString(int8_t error); const char * stateToString();