Skip to content

Commit a41f55c

Browse files
d-a-vigrr
authored andcommitted
prepare lwip2 (#3129)
* minimum changes for libraries to compile with lwip2 * add WiFiClient::availableForWrite() (similar to Serial::) which indicates how much data can be sent without buffering
1 parent a922426 commit a41f55c

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern "C" {
3838
#include "lwip/opt.h"
3939
#include "lwip/err.h"
4040
#include "lwip/dns.h"
41+
#include "lwip/init.h" // LWIP_VERSION_
4142
}
4243

4344
#include "WiFiClient.h"
@@ -419,7 +420,11 @@ bool ESP8266WiFiGenericClass::forceSleepWake() {
419420
// ------------------------------------------------ Generic Network function ---------------------------------------------
420421
// -----------------------------------------------------------------------------------------------------------------------
421422

423+
#if LWIP_VERSION_MAJOR == 1
422424
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg);
425+
#else
426+
void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
427+
#endif
423428

424429
/**
425430
* Resolve the given hostname to an IP address.
@@ -465,7 +470,12 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
465470
* @param ipaddr
466471
* @param callback_arg
467472
*/
468-
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg) {
473+
#if LWIP_VERSION_MAJOR == 1
474+
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg)
475+
#else
476+
void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *callback_arg)
477+
#endif
478+
{
469479
(void) name;
470480
if(ipaddr) {
471481
(*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->addr;

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extern "C" {
3636
#include "smartconfig.h"
3737
#include "lwip/err.h"
3838
#include "lwip/dns.h"
39+
#include "lwip/init.h" // LWIP_VERSION_
3940
}
4041

4142
#include "debug.h"
@@ -400,8 +401,13 @@ IPAddress ESP8266WiFiSTAClass::gatewayIP() {
400401
* @return IPAddress DNS Server IP
401402
*/
402403
IPAddress ESP8266WiFiSTAClass::dnsIP(uint8_t dns_no) {
404+
#if LWIP_VERSION_MAJOR == 1
403405
ip_addr_t dns_ip = dns_getserver(dns_no);
404406
return IPAddress(dns_ip.addr);
407+
#else
408+
const ip_addr_t* dns_ip = dns_getserver(dns_no);
409+
return IPAddress(dns_ip->addr);
410+
#endif
405411
}
406412

407413

libraries/ESP8266WiFi/src/WiFiClient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
106106
// if the default interface is down, tcp_connect exits early without
107107
// ever calling tcp_err
108108
// http://lists.gnu.org/archive/html/lwip-devel/2010-05/msg00001.html
109+
#if LWIP_VERSION_MAJOR == 1
109110
netif* interface = ip_route(&addr);
110111
if (!interface) {
111112
DEBUGV("no route to host\r\n");
112113
return 0;
113114
}
115+
#endif
114116

115117
tcp_pcb* pcb = tcp_new();
116118
if (!pcb)
@@ -163,6 +165,11 @@ bool WiFiClient::getNoDelay() {
163165
return _client->getNoDelay();
164166
}
165167

168+
size_t WiFiClient::availableForWrite ()
169+
{
170+
return _client->availableForWrite();
171+
}
172+
166173
size_t WiFiClient::write(uint8_t b)
167174
{
168175
return write(&b, 1);

libraries/ESP8266WiFi/src/WiFiClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class WiFiClient : public Client, public SList<WiFiClient> {
7575
void setNoDelay(bool nodelay);
7676
static void setLocalPortStart(uint16_t port) { _localPort = port; }
7777

78+
size_t availableForWrite();
79+
7880
friend class WiFiServer;
7981

8082
using Print::write;

libraries/ESP8266WiFi/src/include/ClientContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ class ClientContext
124124
}
125125
}
126126

127+
size_t availableForWrite ()
128+
{
129+
return _pcb? tcp_sndbuf(_pcb): 0;
130+
}
131+
127132
void setNoDelay(bool nodelay)
128133
{
129134
if(!_pcb) {

libraries/ESP8266WiFi/src/include/UdpContext.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323

2424
class UdpContext;
2525

26-
extern "C" void esp_yield();
27-
extern "C" void esp_schedule();
26+
extern "C" {
27+
void esp_yield();
28+
void esp_schedule();
29+
#include "lwip/init.h" // LWIP_VERSION_
30+
}
31+
2832

2933
#define GET_IP_HDR(pb) reinterpret_cast<ip_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN - IP_HLEN);
3034
#define GET_UDP_HDR(pb) reinterpret_cast<udp_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN);
@@ -104,10 +108,17 @@ class UdpContext
104108
udp_disconnect(_pcb);
105109
}
106110

111+
#if LWIP_VERSION_MAJOR == 1
107112
void setMulticastInterface(ip_addr_t addr)
108113
{
109114
udp_set_multicast_netif_addr(_pcb, addr);
110115
}
116+
#else
117+
void setMulticastInterface(const ip_addr_t& addr)
118+
{
119+
udp_set_multicast_netif_addr(_pcb, &addr);
120+
}
121+
#endif
111122

112123
void setMulticastTTL(int ttl)
113124
{
@@ -328,7 +339,7 @@ class UdpContext
328339
}
329340

330341
void _recv(udp_pcb *upcb, pbuf *pb,
331-
ip_addr_t *addr, u16_t port)
342+
const ip_addr_t *addr, u16_t port)
332343
{
333344
(void) upcb;
334345
(void) addr;
@@ -353,9 +364,15 @@ class UdpContext
353364
}
354365

355366

367+
#if LWIP_VERSION_MAJOR == 1
356368
static void _s_recv(void *arg,
357369
udp_pcb *upcb, pbuf *p,
358370
ip_addr_t *addr, u16_t port)
371+
#else
372+
static void _s_recv(void *arg,
373+
udp_pcb *upcb, pbuf *p,
374+
const ip_addr_t *addr, u16_t port)
375+
#endif
359376
{
360377
reinterpret_cast<UdpContext*>(arg)->_recv(upcb, p, addr, port);
361378
}

0 commit comments

Comments
 (0)