mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
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
This commit is contained in:
parent
a9224266f3
commit
a41f55c469
@ -38,6 +38,7 @@ extern "C" {
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/init.h" // LWIP_VERSION_
|
||||
}
|
||||
|
||||
#include "WiFiClient.h"
|
||||
@ -419,7 +420,11 @@ bool ESP8266WiFiGenericClass::forceSleepWake() {
|
||||
// ------------------------------------------------ Generic Network function ---------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg);
|
||||
#else
|
||||
void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Resolve the given hostname to an IP address.
|
||||
@ -465,7 +470,12 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
|
||||
* @param ipaddr
|
||||
* @param callback_arg
|
||||
*/
|
||||
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg) {
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg)
|
||||
#else
|
||||
void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *callback_arg)
|
||||
#endif
|
||||
{
|
||||
(void) name;
|
||||
if(ipaddr) {
|
||||
(*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->addr;
|
||||
|
@ -36,6 +36,7 @@ extern "C" {
|
||||
#include "smartconfig.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/init.h" // LWIP_VERSION_
|
||||
}
|
||||
|
||||
#include "debug.h"
|
||||
@ -400,8 +401,13 @@ IPAddress ESP8266WiFiSTAClass::gatewayIP() {
|
||||
* @return IPAddress DNS Server IP
|
||||
*/
|
||||
IPAddress ESP8266WiFiSTAClass::dnsIP(uint8_t dns_no) {
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
ip_addr_t dns_ip = dns_getserver(dns_no);
|
||||
return IPAddress(dns_ip.addr);
|
||||
#else
|
||||
const ip_addr_t* dns_ip = dns_getserver(dns_no);
|
||||
return IPAddress(dns_ip->addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,11 +106,13 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
|
||||
// if the default interface is down, tcp_connect exits early without
|
||||
// ever calling tcp_err
|
||||
// http://lists.gnu.org/archive/html/lwip-devel/2010-05/msg00001.html
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
netif* interface = ip_route(&addr);
|
||||
if (!interface) {
|
||||
DEBUGV("no route to host\r\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
tcp_pcb* pcb = tcp_new();
|
||||
if (!pcb)
|
||||
@ -163,6 +165,11 @@ bool WiFiClient::getNoDelay() {
|
||||
return _client->getNoDelay();
|
||||
}
|
||||
|
||||
size_t WiFiClient::availableForWrite ()
|
||||
{
|
||||
return _client->availableForWrite();
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(uint8_t b)
|
||||
{
|
||||
return write(&b, 1);
|
||||
|
@ -75,6 +75,8 @@ public:
|
||||
void setNoDelay(bool nodelay);
|
||||
static void setLocalPortStart(uint16_t port) { _localPort = port; }
|
||||
|
||||
size_t availableForWrite();
|
||||
|
||||
friend class WiFiServer;
|
||||
|
||||
using Print::write;
|
||||
|
@ -124,6 +124,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
size_t availableForWrite ()
|
||||
{
|
||||
return _pcb? tcp_sndbuf(_pcb): 0;
|
||||
}
|
||||
|
||||
void setNoDelay(bool nodelay)
|
||||
{
|
||||
if(!_pcb) {
|
||||
|
@ -23,8 +23,12 @@
|
||||
|
||||
class UdpContext;
|
||||
|
||||
extern "C" void esp_yield();
|
||||
extern "C" void esp_schedule();
|
||||
extern "C" {
|
||||
void esp_yield();
|
||||
void esp_schedule();
|
||||
#include "lwip/init.h" // LWIP_VERSION_
|
||||
}
|
||||
|
||||
|
||||
#define GET_IP_HDR(pb) reinterpret_cast<ip_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN - IP_HLEN);
|
||||
#define GET_UDP_HDR(pb) reinterpret_cast<udp_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN);
|
||||
@ -104,10 +108,17 @@ public:
|
||||
udp_disconnect(_pcb);
|
||||
}
|
||||
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
void setMulticastInterface(ip_addr_t addr)
|
||||
{
|
||||
udp_set_multicast_netif_addr(_pcb, addr);
|
||||
}
|
||||
#else
|
||||
void setMulticastInterface(const ip_addr_t& addr)
|
||||
{
|
||||
udp_set_multicast_netif_addr(_pcb, &addr);
|
||||
}
|
||||
#endif
|
||||
|
||||
void setMulticastTTL(int ttl)
|
||||
{
|
||||
@ -328,7 +339,7 @@ private:
|
||||
}
|
||||
|
||||
void _recv(udp_pcb *upcb, pbuf *pb,
|
||||
ip_addr_t *addr, u16_t port)
|
||||
const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
(void) upcb;
|
||||
(void) addr;
|
||||
@ -353,9 +364,15 @@ private:
|
||||
}
|
||||
|
||||
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
static void _s_recv(void *arg,
|
||||
udp_pcb *upcb, pbuf *p,
|
||||
ip_addr_t *addr, u16_t port)
|
||||
#else
|
||||
static void _s_recv(void *arg,
|
||||
udp_pcb *upcb, pbuf *p,
|
||||
const ip_addr_t *addr, u16_t port)
|
||||
#endif
|
||||
{
|
||||
reinterpret_cast<UdpContext*>(arg)->_recv(upcb, p, addr, port);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user