mirror of
https://github.com/me-no-dev/AsyncTCP.git
synced 2025-09-25 22:00:54 +02:00
Code reformat according to clang file
This commit is contained in:
802
src/AsyncTCP.cpp
802
src/AsyncTCP.cpp
File diff suppressed because it is too large
Load Diff
127
src/AsyncTCP.h
127
src/AsyncTCP.h
@@ -30,59 +30,59 @@
|
|||||||
|
|
||||||
#include "IPAddress.h"
|
#include "IPAddress.h"
|
||||||
#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"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "lwip/pbuf.h"
|
#include "lwip/pbuf.h"
|
||||||
}
|
}
|
||||||
#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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//If core is not defined, then we are running in Arduino or PIO
|
// If core is not defined, then we are running in Arduino or PIO
|
||||||
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
|
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
|
||||||
#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 1 //if enabled, adds between 33us and 200us per event
|
#define CONFIG_ASYNC_TCP_USE_WDT 1 // if enabled, adds between 33us and 200us per event
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_STACK_SIZE
|
#ifndef CONFIG_ASYNC_TCP_STACK_SIZE
|
||||||
#define CONFIG_ASYNC_TCP_STACK_SIZE 8192 * 2
|
#define CONFIG_ASYNC_TCP_STACK_SIZE 8192 * 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_PRIORITY
|
#ifndef CONFIG_ASYNC_TCP_PRIORITY
|
||||||
#define CONFIG_ASYNC_TCP_PRIORITY 10
|
#define CONFIG_ASYNC_TCP_PRIORITY 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_QUEUE_SIZE
|
#ifndef CONFIG_ASYNC_TCP_QUEUE_SIZE
|
||||||
#define CONFIG_ASYNC_TCP_QUEUE_SIZE 64
|
#define CONFIG_ASYNC_TCP_QUEUE_SIZE 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_ASYNC_TCP_MAX_ACK_TIME
|
#ifndef CONFIG_ASYNC_TCP_MAX_ACK_TIME
|
||||||
#define CONFIG_ASYNC_TCP_MAX_ACK_TIME 5000
|
#define CONFIG_ASYNC_TCP_MAX_ACK_TIME 5000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class AsyncClient;
|
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_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.
|
#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<void(void*, AsyncClient*)> AcConnectHandler;
|
typedef std::function<void(void*, AsyncClient*)> AcConnectHandler;
|
||||||
typedef std::function<void(void*, AsyncClient*, size_t len, uint32_t time)> AcAckHandler;
|
typedef std::function<void(void*, AsyncClient*, size_t len, uint32_t time)> AcAckHandler;
|
||||||
typedef std::function<void(void*, AsyncClient*, int8_t error)> AcErrorHandler;
|
typedef std::function<void(void*, AsyncClient*, int8_t error)> AcErrorHandler;
|
||||||
typedef std::function<void(void*, AsyncClient*, void *data, size_t len)> AcDataHandler;
|
typedef std::function<void(void*, AsyncClient*, void* data, size_t len)> AcDataHandler;
|
||||||
typedef std::function<void(void*, AsyncClient*, struct pbuf *pb)> AcPacketHandler;
|
typedef std::function<void(void*, AsyncClient*, struct pbuf* pb)> AcPacketHandler;
|
||||||
typedef std::function<void(void*, AsyncClient*, uint32_t time)> AcTimeoutHandler;
|
typedef std::function<void(void*, AsyncClient*, uint32_t time)> AcTimeoutHandler;
|
||||||
|
|
||||||
struct tcp_pcb;
|
struct tcp_pcb;
|
||||||
@@ -93,47 +93,47 @@ class AsyncClient {
|
|||||||
AsyncClient(tcp_pcb* pcb = 0);
|
AsyncClient(tcp_pcb* pcb = 0);
|
||||||
~AsyncClient();
|
~AsyncClient();
|
||||||
|
|
||||||
AsyncClient & operator=(const AsyncClient &other);
|
AsyncClient& operator=(const AsyncClient& other);
|
||||||
AsyncClient & operator+=(const AsyncClient &other);
|
AsyncClient& operator+=(const AsyncClient& other);
|
||||||
|
|
||||||
bool operator==(const AsyncClient &other);
|
bool operator==(const AsyncClient& other);
|
||||||
|
|
||||||
bool operator!=(const AsyncClient &other) {
|
bool operator!=(const AsyncClient& other) {
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
bool connect(const IPAddress& ip, uint16_t port);
|
bool connect(const IPAddress& ip, uint16_t port);
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
#if ESP_IDF_VERSION_MAJOR < 5
|
||||||
bool connect(const IPv6Address& ip, uint16_t port);
|
bool connect(const IPv6Address& ip, uint16_t port);
|
||||||
#endif
|
#endif
|
||||||
bool connect(const char *host, uint16_t port);
|
bool connect(const char* host, uint16_t port);
|
||||||
void close(bool now = false);
|
void close(bool now = false);
|
||||||
void stop();
|
void stop();
|
||||||
int8_t abort();
|
int8_t abort();
|
||||||
bool free();
|
bool free();
|
||||||
|
|
||||||
bool canSend();//ack is not pending
|
bool canSend(); // ack is not pending
|
||||||
size_t space();//space available in the TCP window
|
size_t space(); // space available in the TCP window
|
||||||
size_t add(const char* data, size_t size, uint8_t apiflags=ASYNC_WRITE_FLAG_COPY);//add for sending
|
size_t add(const char* data, size_t size, uint8_t apiflags = ASYNC_WRITE_FLAG_COPY); // add for sending
|
||||||
bool send();//send all data added with the method above
|
bool send(); // send all data added with the method above
|
||||||
|
|
||||||
//write equals add()+send()
|
// write equals add()+send()
|
||||||
size_t write(const char* data);
|
size_t write(const char* data);
|
||||||
size_t write(const char* data, size_t size, uint8_t apiflags=ASYNC_WRITE_FLAG_COPY); //only when canSend() == true
|
size_t write(const char* data, size_t size, uint8_t apiflags = ASYNC_WRITE_FLAG_COPY); // only when canSend() == true
|
||||||
|
|
||||||
uint8_t state();
|
uint8_t state();
|
||||||
bool connecting();
|
bool connecting();
|
||||||
bool connected();
|
bool connected();
|
||||||
bool disconnecting();
|
bool disconnecting();
|
||||||
bool disconnected();
|
bool disconnected();
|
||||||
bool freeable();//disconnected or disconnecting
|
bool freeable(); // disconnected or disconnecting
|
||||||
|
|
||||||
uint16_t getMss();
|
uint16_t getMss();
|
||||||
|
|
||||||
uint32_t getRxTimeout();
|
uint32_t getRxTimeout();
|
||||||
void setRxTimeout(uint32_t timeout);//no RX data timeout for the connection in seconds
|
void setRxTimeout(uint32_t timeout); // no RX data timeout for the connection in seconds
|
||||||
|
|
||||||
uint32_t getAckTimeout();
|
uint32_t getAckTimeout();
|
||||||
void setAckTimeout(uint32_t timeout);//no ACK timeout for the last sent packet in milliseconds
|
void setAckTimeout(uint32_t timeout); // no ACK timeout for the last sent packet in milliseconds
|
||||||
|
|
||||||
void setNoDelay(bool nodelay);
|
void setNoDelay(bool nodelay);
|
||||||
bool getNoDelay();
|
bool getNoDelay();
|
||||||
@@ -147,49 +147,49 @@ class AsyncClient {
|
|||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
ip6_addr_t getRemoteAddress6();
|
ip6_addr_t getRemoteAddress6();
|
||||||
ip6_addr_t getLocalAddress6();
|
ip6_addr_t getLocalAddress6();
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
#if ESP_IDF_VERSION_MAJOR < 5
|
||||||
IPv6Address remoteIP6();
|
IPv6Address remoteIP6();
|
||||||
IPv6Address localIP6();
|
IPv6Address localIP6();
|
||||||
#else
|
#else
|
||||||
IPAddress remoteIP6();
|
IPAddress remoteIP6();
|
||||||
IPAddress localIP6();
|
IPAddress localIP6();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//compatibility
|
// compatibility
|
||||||
IPAddress remoteIP();
|
IPAddress remoteIP();
|
||||||
uint16_t remotePort();
|
uint16_t remotePort();
|
||||||
IPAddress localIP();
|
IPAddress localIP();
|
||||||
uint16_t localPort();
|
uint16_t localPort();
|
||||||
|
|
||||||
void onConnect(AcConnectHandler cb, void* arg = 0); //on successful connect
|
void onConnect(AcConnectHandler cb, void* arg = 0); // on successful connect
|
||||||
void onDisconnect(AcConnectHandler cb, void* arg = 0); //disconnected
|
void onDisconnect(AcConnectHandler cb, void* arg = 0); // disconnected
|
||||||
void onAck(AcAckHandler cb, void* arg = 0); //ack received
|
void onAck(AcAckHandler cb, void* arg = 0); // ack received
|
||||||
void onError(AcErrorHandler cb, void* arg = 0); //unsuccessful connect or error
|
void onError(AcErrorHandler cb, void* arg = 0); // unsuccessful connect or error
|
||||||
void onData(AcDataHandler cb, void* arg = 0); //data received (called if onPacket is not used)
|
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 onPacket(AcPacketHandler cb, void* arg = 0); // data received
|
||||||
void onTimeout(AcTimeoutHandler cb, void* arg = 0); //ack timeout
|
void onTimeout(AcTimeoutHandler cb, void* arg = 0); // ack timeout
|
||||||
void onPoll(AcConnectHandler cb, void* arg = 0); //every 125ms when connected
|
void onPoll(AcConnectHandler cb, void* arg = 0); // every 125ms when connected
|
||||||
|
|
||||||
void ackPacket(struct pbuf * pb);//ack pbuf from onPacket
|
void ackPacket(struct pbuf* pb); // ack pbuf from onPacket
|
||||||
size_t ack(size_t len); //ack data that you have not acked using the method below
|
size_t ack(size_t len); // ack data that you have not acked using the method below
|
||||||
void ackLater(){ _ack_pcb = false; } //will not ack the current packet. Call from onData
|
void ackLater() { _ack_pcb = false; } // will not ack the current packet. Call from onData
|
||||||
|
|
||||||
const char * errorToString(int8_t error);
|
const char* errorToString(int8_t error);
|
||||||
const char * stateToString();
|
const char* stateToString();
|
||||||
|
|
||||||
//Do not use any of the functions below!
|
// Do not use any of the functions below!
|
||||||
static int8_t _s_poll(void *arg, struct tcp_pcb *tpcb);
|
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 int8_t _s_recv(void* arg, struct tcp_pcb* tpcb, struct pbuf* pb, int8_t err);
|
||||||
static int8_t _s_fin(void *arg, struct tcp_pcb *tpcb, int8_t err);
|
static int8_t _s_fin(void* arg, struct tcp_pcb* tpcb, int8_t err);
|
||||||
static int8_t _s_lwip_fin(void *arg, struct tcp_pcb *tpcb, int8_t err);
|
static int8_t _s_lwip_fin(void* arg, struct tcp_pcb* tpcb, int8_t err);
|
||||||
static void _s_error(void *arg, 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_sent(void* arg, struct tcp_pcb* tpcb, uint16_t len);
|
||||||
static int8_t _s_connected(void* arg, struct tcp_pcb *tpcb, int8_t err);
|
static int8_t _s_connected(void* arg, struct tcp_pcb* tpcb, int8_t err);
|
||||||
static void _s_dns_found(const char *name, struct ip_addr *ipaddr, void *arg);
|
static void _s_dns_found(const char* name, struct ip_addr* ipaddr, void* arg);
|
||||||
|
|
||||||
int8_t _recv(tcp_pcb* pcb, pbuf* pb, int8_t err);
|
int8_t _recv(tcp_pcb* pcb, pbuf* pb, int8_t err);
|
||||||
tcp_pcb * pcb(){ return _pcb; }
|
tcp_pcb* pcb() { return _pcb; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _connect(ip_addr_t addr, uint16_t port);
|
bool _connect(ip_addr_t addr, uint16_t port);
|
||||||
@@ -232,7 +232,7 @@ class AsyncClient {
|
|||||||
int8_t _sent(tcp_pcb* pcb, uint16_t len);
|
int8_t _sent(tcp_pcb* pcb, uint16_t len);
|
||||||
int8_t _fin(tcp_pcb* pcb, int8_t err);
|
int8_t _fin(tcp_pcb* pcb, int8_t err);
|
||||||
int8_t _lwip_fin(tcp_pcb* pcb, int8_t err);
|
int8_t _lwip_fin(tcp_pcb* pcb, int8_t err);
|
||||||
void _dns_found(struct ip_addr *ipaddr);
|
void _dns_found(struct ip_addr* ipaddr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AsyncClient* prev;
|
AsyncClient* prev;
|
||||||
@@ -254,9 +254,9 @@ class AsyncServer {
|
|||||||
bool getNoDelay();
|
bool getNoDelay();
|
||||||
uint8_t status();
|
uint8_t status();
|
||||||
|
|
||||||
//Do not use any of the functions below!
|
// Do not use any of the functions below!
|
||||||
static int8_t _s_accept(void *arg, tcp_pcb* newpcb, int8_t err);
|
static int8_t _s_accept(void* arg, tcp_pcb* newpcb, int8_t err);
|
||||||
static int8_t _s_accepted(void *arg, AsyncClient* client);
|
static int8_t _s_accepted(void* arg, AsyncClient* client);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16_t _port;
|
uint16_t _port;
|
||||||
@@ -275,5 +275,4 @@ class AsyncServer {
|
|||||||
int8_t _accepted(AsyncClient* client);
|
int8_t _accepted(AsyncClient* client);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* ASYNCTCP_H_ */
|
#endif /* ASYNCTCP_H_ */
|
||||||
|
Reference in New Issue
Block a user