Code reformat according to clang file

This commit is contained in:
Mathieu Carbou
2024-12-11 19:55:13 +01:00
parent 362beab638
commit 31b3452efb
2 changed files with 1218 additions and 1221 deletions

View File

@@ -22,13 +22,15 @@
#include "Arduino.h" #include "Arduino.h"
#include "AsyncTCP.h" #include "AsyncTCP.h"
extern "C" { extern "C" {
#include "lwip/opt.h"
#include "lwip/tcp.h"
#include "lwip/inet.h"
#include "lwip/dns.h" #include "lwip/dns.h"
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/opt.h"
#include "lwip/tcp.h"
} }
#if CONFIG_ASYNC_TCP_USE_WDT #if CONFIG_ASYNC_TCP_USE_WDT
#include "esp_task_wdt.h" #include "esp_task_wdt.h"
#endif #endif
@@ -64,7 +66,15 @@ extern "C"{
* */ * */
typedef enum { typedef enum {
LWIP_TCP_SENT, LWIP_TCP_RECV, LWIP_TCP_FIN, LWIP_TCP_ERROR, LWIP_TCP_POLL, LWIP_TCP_CLEAR, LWIP_TCP_ACCEPT, LWIP_TCP_CONNECTED, LWIP_TCP_DNS LWIP_TCP_SENT,
LWIP_TCP_RECV,
LWIP_TCP_FIN,
LWIP_TCP_ERROR,
LWIP_TCP_POLL,
LWIP_TCP_CLEAR,
LWIP_TCP_ACCEPT,
LWIP_TCP_CONNECTED,
LWIP_TCP_DNS
} lwip_event_t; } lwip_event_t;
typedef struct { typedef struct {
@@ -107,7 +117,6 @@ typedef struct {
static QueueHandle_t _async_queue; static QueueHandle_t _async_queue;
static TaskHandle_t _async_service_task_handle = NULL; static TaskHandle_t _async_service_task_handle = NULL;
SemaphoreHandle_t _slots_lock; SemaphoreHandle_t _slots_lock;
const int _number_of_closed_slots = CONFIG_LWIP_MAX_ACTIVE_TCP; const int _number_of_closed_slots = CONFIG_LWIP_MAX_ACTIVE_TCP;
static uint32_t _closed_slots[_number_of_closed_slots]; static uint32_t _closed_slots[_number_of_closed_slots];
@@ -120,7 +129,6 @@ static uint32_t _closed_index = []() {
return 1; return 1;
}(); }();
static inline bool _init_async_event_queue() { static inline bool _init_async_event_queue() {
if (!_async_queue) { if (!_async_queue) {
_async_queue = xQueueCreate(CONFIG_ASYNC_TCP_QUEUE_SIZE, sizeof(lwip_event_packet_t*)); _async_queue = xQueueCreate(CONFIG_ASYNC_TCP_QUEUE_SIZE, sizeof(lwip_event_packet_t*));
@@ -590,36 +598,12 @@ static tcp_pcb * _tcp_listen_with_backlog(tcp_pcb * pcb, uint8_t backlog) {
return msg.pcb; return msg.pcb;
} }
/* /*
Async TCP Client Async TCP Client
*/ */
AsyncClient::AsyncClient(tcp_pcb* pcb) AsyncClient::AsyncClient(tcp_pcb* pcb)
: _connect_cb(0) : _connect_cb(0), _connect_cb_arg(0), _discard_cb(0), _discard_cb_arg(0), _sent_cb(0), _sent_cb_arg(0), _error_cb(0), _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), _ack_pcb(true), _tx_last_packet(0), _rx_timeout(0), _rx_last_ack(0), _ack_timeout(CONFIG_ASYNC_TCP_MAX_ACK_TIME), _connect_port(0), prev(NULL), next(NULL) {
, _connect_cb_arg(0)
, _discard_cb(0)
, _discard_cb_arg(0)
, _sent_cb(0)
, _sent_cb_arg(0)
, _error_cb(0)
, _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)
, _ack_pcb(true)
, _tx_last_packet(0)
, _rx_timeout(0)
, _rx_last_ack(0)
, _ack_timeout(CONFIG_ASYNC_TCP_MAX_ACK_TIME)
, _connect_port(0)
, prev(NULL)
, next(NULL)
{
_pcb = pcb; _pcb = pcb;
_closed_slot = INVALID_CLOSED_SLOT; _closed_slot = INVALID_CLOSED_SLOT;
if (_pcb) { if (_pcb) {
@@ -1301,7 +1285,6 @@ IPAddress AsyncClient::localIP() {
#endif #endif
} }
uint16_t AsyncClient::localPort() { uint16_t AsyncClient::localPort() {
return getLocalPort(); return getLocalPort();
} }
@@ -1354,41 +1337,71 @@ bool AsyncClient::canSend(){
const char* AsyncClient::errorToString(int8_t error) { const char* AsyncClient::errorToString(int8_t error) {
switch (error) { switch (error) {
case ERR_OK: return "OK"; case ERR_OK:
case ERR_MEM: return "Out of memory error"; return "OK";
case ERR_BUF: return "Buffer error"; case ERR_MEM:
case ERR_TIMEOUT: return "Timeout"; return "Out of memory error";
case ERR_RTE: return "Routing problem"; case ERR_BUF:
case ERR_INPROGRESS: return "Operation in progress"; return "Buffer error";
case ERR_VAL: return "Illegal value"; case ERR_TIMEOUT:
case ERR_WOULDBLOCK: return "Operation would block"; return "Timeout";
case ERR_USE: return "Address in use"; case ERR_RTE:
case ERR_ALREADY: return "Already connected"; return "Routing problem";
case ERR_CONN: return "Not connected"; case ERR_INPROGRESS:
case ERR_IF: return "Low-level netif error"; return "Operation in progress";
case ERR_ABRT: return "Connection aborted"; case ERR_VAL:
case ERR_RST: return "Connection reset"; return "Illegal value";
case ERR_CLSD: return "Connection closed"; case ERR_WOULDBLOCK:
case ERR_ARG: return "Illegal argument"; return "Operation would block";
case -55: return "DNS failed"; case ERR_USE:
default: return "UNKNOWN"; return "Address in use";
case ERR_ALREADY:
return "Already connected";
case ERR_CONN:
return "Not connected";
case ERR_IF:
return "Low-level netif error";
case ERR_ABRT:
return "Connection aborted";
case ERR_RST:
return "Connection reset";
case ERR_CLSD:
return "Connection closed";
case ERR_ARG:
return "Illegal argument";
case -55:
return "DNS failed";
default:
return "UNKNOWN";
} }
} }
const char* AsyncClient::stateToString() { const char* AsyncClient::stateToString() {
switch (state()) { switch (state()) {
case 0: return "Closed"; case 0:
case 1: return "Listen"; return "Closed";
case 2: return "SYN Sent"; case 1:
case 3: return "SYN Received"; return "Listen";
case 4: return "Established"; case 2:
case 5: return "FIN Wait 1"; return "SYN Sent";
case 6: return "FIN Wait 2"; case 3:
case 7: return "Close Wait"; return "SYN Received";
case 8: return "Closing"; case 4:
case 9: return "Last ACK"; return "Established";
case 10: return "Time Wait"; case 5:
default: return "UNKNOWN"; return "FIN Wait 1";
case 6:
return "FIN Wait 2";
case 7:
return "Close Wait";
case 8:
return "Closing";
case 9:
return "Last ACK";
case 10:
return "Time Wait";
default:
return "UNKNOWN";
} }
} }
@@ -1435,45 +1448,30 @@ int8_t AsyncClient::_s_connected(void * arg, struct tcp_pcb * pcb, int8_t err){
AsyncServer::AsyncServer(IPAddress addr, uint16_t port) AsyncServer::AsyncServer(IPAddress addr, uint16_t port)
: _port(port) : _port(port)
#if ESP_IDF_VERSION_MAJOR < 5 #if ESP_IDF_VERSION_MAJOR < 5
, _bind4(true) ,
, _bind6(false) _bind4(true), _bind6(false)
#else #else
, _bind4(addr.type() != IPType::IPv6) ,
, _bind6(addr.type() == IPType::IPv6) _bind4(addr.type() != IPType::IPv6), _bind6(addr.type() == IPType::IPv6)
#endif #endif
, _addr(addr) ,
, _noDelay(false) _addr(addr), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
, _pcb(0) }
, _connect_cb(0)
, _connect_cb_arg(0)
{}
#if ESP_IDF_VERSION_MAJOR < 5 #if ESP_IDF_VERSION_MAJOR < 5
AsyncServer::AsyncServer(IPv6Address addr, uint16_t port) AsyncServer::AsyncServer(IPv6Address addr, uint16_t port)
: _port(port) : _port(port), _bind4(false), _bind6(true), _addr6(addr), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {}
, _bind4(false)
, _bind6(true)
, _addr6(addr)
, _noDelay(false)
, _pcb(0)
, _connect_cb(0)
, _connect_cb_arg(0)
{}
#endif #endif
AsyncServer::AsyncServer(uint16_t port) AsyncServer::AsyncServer(uint16_t port)
: _port(port) : _port(port), _bind4(true), _bind6(false), _addr((uint32_t)IPADDR_ANY)
, _bind4(true)
, _bind6(false)
, _addr((uint32_t) IPADDR_ANY)
#if ESP_IDF_VERSION_MAJOR < 5 #if ESP_IDF_VERSION_MAJOR < 5
, _addr6() ,
_addr6()
#endif #endif
, _noDelay(false) ,
, _pcb(0) _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
, _connect_cb(0) }
, _connect_cb_arg(0)
{}
AsyncServer::~AsyncServer() { AsyncServer::~AsyncServer() {
end(); end();

View File

@@ -32,9 +32,9 @@
#if ESP_IDF_VERSION_MAJOR < 5 #if ESP_IDF_VERSION_MAJOR < 5
#include "IPv6Address.h" #include "IPv6Address.h"
#endif #endif
#include <functional>
#include "lwip/ip_addr.h"
#include "lwip/ip6_addr.h" #include "lwip/ip6_addr.h"
#include "lwip/ip_addr.h"
#include <functional>
#ifndef LIBRETINY #ifndef LIBRETINY
#include "sdkconfig.h" #include "sdkconfig.h"
@@ -44,8 +44,8 @@ extern "C" {
} }
#else #else
extern "C" { extern "C" {
#include <semphr.h>
#include <lwip/pbuf.h> #include <lwip/pbuf.h>
#include <semphr.h>
} }
#define CONFIG_ASYNC_TCP_RUNNING_CORE -1 // any available core #define CONFIG_ASYNC_TCP_RUNNING_CORE -1 // any available core
#define CONFIG_ASYNC_TCP_USE_WDT 0 #define CONFIG_ASYNC_TCP_USE_WDT 0
@@ -275,5 +275,4 @@ class AsyncServer {
int8_t _accepted(AsyncClient* client); int8_t _accepted(AsyncClient* client);
}; };
#endif /* ASYNCTCP_H_ */ #endif /* ASYNCTCP_H_ */