3
3
4
4
#include " AsyncTCP.h"
5
5
6
+ #ifndef LIBRETINY
6
7
#include < esp_log.h>
7
8
8
9
#ifdef ARDUINO
@@ -22,6 +23,18 @@ static unsigned long millis() {
22
23
return (unsigned long )(esp_timer_get_time () / 1000ULL );
23
24
}
24
25
#endif
26
+ #endif
27
+
28
+ #ifdef LIBRETINY
29
+ #include < Arduino.h>
30
+ // LibreTiny does not support IDF - disable code that expects it to be available
31
+ #define ESP_IDF_VERSION_MAJOR (0 )
32
+ // xTaskCreatePinnedToCore is not available, force single-core operation
33
+ #define CONFIG_FREERTOS_UNICORE 1
34
+ // ESP watchdog is not available
35
+ #undef CONFIG_ASYNC_TCP_USE_WDT
36
+ #define CONFIG_ASYNC_TCP_USE_WDT 0
37
+ #endif
25
38
26
39
extern " C" {
27
40
#include " lwip/dns.h"
@@ -837,7 +850,11 @@ bool AsyncClient::connect(ip_addr_t addr, uint16_t port) {
837
850
tcp_pcb *pcb;
838
851
{
839
852
tcp_core_guard tcg;
853
+ #if LWIP_IPV4 && LWIP_IPV6
840
854
pcb = tcp_new_ip_type (addr.type );
855
+ #else
856
+ pcb = tcp_new_ip_type (IPADDR_TYPE_V4);
857
+ #endif
841
858
if (!pcb) {
842
859
log_e (" pcb == NULL" );
843
860
return false ;
@@ -857,8 +874,13 @@ bool AsyncClient::connect(ip_addr_t addr, uint16_t port) {
857
874
bool AsyncClient::connect (const IPAddress &ip, uint16_t port) {
858
875
ip_addr_t addr;
859
876
#if ESP_IDF_VERSION_MAJOR < 5
877
+ #if LWIP_IPV4 && LWIP_IPV6
878
+ // if both IPv4 and IPv6 are enabled, ip_addr_t has a union field and the address type
860
879
addr.u_addr .ip4 .addr = ip;
861
880
addr.type = IPADDR_TYPE_V4;
881
+ #else
882
+ addr.addr = ip;
883
+ #endif
862
884
#else
863
885
ip.to_ip_addr_t (&addr);
864
886
#endif
@@ -1343,19 +1365,33 @@ uint16_t AsyncClient::getLocalPort() const {
1343
1365
}
1344
1366
1345
1367
ip4_addr_t AsyncClient::getRemoteAddress4 () const {
1368
+ #if LWIP_IPV4 && LWIP_IPV6
1346
1369
if (_pcb && _pcb->remote_ip .type == IPADDR_TYPE_V4) {
1347
1370
return _pcb->remote_ip .u_addr .ip4 ;
1348
- } else {
1371
+ }
1372
+ #else
1373
+ if (_pcb) {
1374
+ return _pcb->remote_ip ;
1375
+ }
1376
+ #endif
1377
+ else {
1349
1378
ip4_addr_t nulladdr;
1350
1379
ip4_addr_set_zero (&nulladdr);
1351
1380
return nulladdr;
1352
1381
}
1353
1382
}
1354
1383
1355
1384
ip4_addr_t AsyncClient::getLocalAddress4 () const {
1385
+ #if LWIP_IPV4 && LWIP_IPV6
1356
1386
if (_pcb && _pcb->local_ip .type == IPADDR_TYPE_V4) {
1357
1387
return _pcb->local_ip .u_addr .ip4 ;
1358
- } else {
1388
+ }
1389
+ #else
1390
+ if (_pcb) {
1391
+ return _pcb->local_ip ;
1392
+ }
1393
+ #endif
1394
+ else {
1359
1395
ip4_addr_t nulladdr;
1360
1396
ip4_addr_set_zero (&nulladdr);
1361
1397
return nulladdr;
@@ -1486,24 +1522,34 @@ AsyncServer::AsyncServer(ip_addr_t addr, uint16_t port)
1486
1522
#ifdef ARDUINO
1487
1523
AsyncServer::AsyncServer (IPAddress addr, uint16_t port) : _port (port), _noDelay (false ), _pcb (0 ), _connect_cb (0 ), _connect_cb_arg (0 ) {
1488
1524
#if ESP_IDF_VERSION_MAJOR < 5
1525
+ #if LWIP_IPV4 && LWIP_IPV6
1489
1526
_addr.type = IPADDR_TYPE_V4;
1490
1527
_addr.u_addr .ip4 .addr = addr;
1528
+ #else
1529
+ _addr.addr = addr;
1530
+ #endif
1491
1531
#else
1492
1532
addr.to_ip_addr_t (&_addr);
1493
1533
#endif
1494
1534
}
1495
- #if ESP_IDF_VERSION_MAJOR < 5
1535
+ #if ESP_IDF_VERSION_MAJOR < 5 && __has_include(<IPv6Address.h>) && LWIP_IPV6
1496
1536
AsyncServer::AsyncServer (IPv6Address addr, uint16_t port) : _port (port), _noDelay (false ), _pcb (0 ), _connect_cb (0 ), _connect_cb_arg (0 ) {
1537
+ #if LWIP_IPV4 && LWIP_IPV6
1497
1538
_addr.type = IPADDR_TYPE_V6;
1539
+ #endif
1498
1540
auto ipaddr = static_cast <const uint32_t *>(addr);
1499
1541
_addr = IPADDR6_INIT (ipaddr[0 ], ipaddr[1 ], ipaddr[2 ], ipaddr[3 ]);
1500
1542
}
1501
1543
#endif
1502
1544
#endif
1503
1545
1504
1546
AsyncServer::AsyncServer (uint16_t port) : _port (port), _noDelay (false ), _pcb (0 ), _connect_cb (0 ), _connect_cb_arg (0 ) {
1547
+ #if LWIP_IPV4 && LWIP_IPV6
1505
1548
_addr.type = IPADDR_TYPE_ANY;
1506
1549
_addr.u_addr .ip4 .addr = INADDR_ANY;
1550
+ #else
1551
+ _addr.addr = INADDR_ANY;
1552
+ #endif
1507
1553
}
1508
1554
1509
1555
AsyncServer::~AsyncServer () {
@@ -1527,7 +1573,11 @@ void AsyncServer::begin() {
1527
1573
int8_t err;
1528
1574
{
1529
1575
tcp_core_guard tcg;
1576
+ #if LWIP_IPV4 && LWIP_IPV6
1530
1577
_pcb = tcp_new_ip_type (_addr.type );
1578
+ #else
1579
+ _pcb = tcp_new_ip_type (IPADDR_TYPE_ANY);
1580
+ #endif
1531
1581
}
1532
1582
if (!_pcb) {
1533
1583
log_e (" _pcb == NULL" );
0 commit comments