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 "AsyncTCP.h"
extern "C" {
#include "lwip/opt.h"
#include "lwip/tcp.h"
#include "lwip/inet.h"
#include "lwip/dns.h"
#include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/opt.h"
#include "lwip/tcp.h"
}
#if CONFIG_ASYNC_TCP_USE_WDT
#include "esp_task_wdt.h"
#endif
@@ -64,7 +66,15 @@ extern "C"{
* */
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;
typedef struct {
@@ -107,7 +117,6 @@ typedef struct {
static QueueHandle_t _async_queue;
static TaskHandle_t _async_service_task_handle = NULL;
SemaphoreHandle_t _slots_lock;
const int _number_of_closed_slots = CONFIG_LWIP_MAX_ACTIVE_TCP;
static uint32_t _closed_slots[_number_of_closed_slots];
@@ -120,7 +129,6 @@ static uint32_t _closed_index = []() {
return 1;
}();
static inline bool _init_async_event_queue() {
if (!_async_queue) {
_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;
}
/*
Async TCP Client
*/
AsyncClient::AsyncClient(tcp_pcb* pcb)
: _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(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) {
_pcb = pcb;
_closed_slot = INVALID_CLOSED_SLOT;
if (_pcb) {
@@ -1301,7 +1285,6 @@ IPAddress AsyncClient::localIP() {
#endif
}
uint16_t AsyncClient::localPort() {
return getLocalPort();
}
@@ -1354,41 +1337,71 @@ bool AsyncClient::canSend(){
const char* AsyncClient::errorToString(int8_t error) {
switch (error) {
case ERR_OK: return "OK";
case ERR_MEM: return "Out of memory error";
case ERR_BUF: return "Buffer error";
case ERR_TIMEOUT: return "Timeout";
case ERR_RTE: return "Routing problem";
case ERR_INPROGRESS: return "Operation in progress";
case ERR_VAL: return "Illegal value";
case ERR_WOULDBLOCK: return "Operation would block";
case ERR_USE: 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";
case ERR_OK:
return "OK";
case ERR_MEM:
return "Out of memory error";
case ERR_BUF:
return "Buffer error";
case ERR_TIMEOUT:
return "Timeout";
case ERR_RTE:
return "Routing problem";
case ERR_INPROGRESS:
return "Operation in progress";
case ERR_VAL:
return "Illegal value";
case ERR_WOULDBLOCK:
return "Operation would block";
case ERR_USE:
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() {
switch (state()) {
case 0: return "Closed";
case 1: return "Listen";
case 2: return "SYN Sent";
case 3: return "SYN Received";
case 4: return "Established";
case 5: 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";
case 0:
return "Closed";
case 1:
return "Listen";
case 2:
return "SYN Sent";
case 3:
return "SYN Received";
case 4:
return "Established";
case 5:
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)
: _port(port)
#if ESP_IDF_VERSION_MAJOR < 5
, _bind4(true)
, _bind6(false)
,
_bind4(true), _bind6(false)
#else
, _bind4(addr.type() != IPType::IPv6)
, _bind6(addr.type() == IPType::IPv6)
,
_bind4(addr.type() != IPType::IPv6), _bind6(addr.type() == IPType::IPv6)
#endif
, _addr(addr)
, _noDelay(false)
, _pcb(0)
, _connect_cb(0)
, _connect_cb_arg(0)
{}
,
_addr(addr), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
}
#if ESP_IDF_VERSION_MAJOR < 5
AsyncServer::AsyncServer(IPv6Address addr, uint16_t port)
: _port(port)
, _bind4(false)
, _bind6(true)
, _addr6(addr)
, _noDelay(false)
, _pcb(0)
, _connect_cb(0)
, _connect_cb_arg(0)
{}
: _port(port), _bind4(false), _bind6(true), _addr6(addr), _noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {}
#endif
AsyncServer::AsyncServer(uint16_t port)
: _port(port)
, _bind4(true)
, _bind6(false)
, _addr((uint32_t) IPADDR_ANY)
: _port(port), _bind4(true), _bind6(false), _addr((uint32_t)IPADDR_ANY)
#if ESP_IDF_VERSION_MAJOR < 5
, _addr6()
,
_addr6()
#endif
, _noDelay(false)
, _pcb(0)
, _connect_cb(0)
, _connect_cb_arg(0)
{}
,
_noDelay(false), _pcb(0), _connect_cb(0), _connect_cb_arg(0) {
}
AsyncServer::~AsyncServer() {
end();

View File

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