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