From b05c7dfa59da634ef688bc7e6f207c96c4d24447 Mon Sep 17 00:00:00 2001 From: bbx10 Date: Wed, 14 Jun 2017 01:22:16 -0700 Subject: [PATCH] Additions to WiFiClient and WiFiServer (#404) Required for WebServer and/or DNSServer libraries --- libraries/WiFi/src/WiFiClient.cpp | 5 +++++ libraries/WiFi/src/WiFiClient.h | 5 +++++ libraries/WiFi/src/WiFiServer.cpp | 11 ++++++++++- libraries/WiFi/src/WiFiServer.h | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index bcea2bb8..f6f4c300 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -224,6 +224,11 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size) return res; } +size_t WiFiClient::write_P(PGM_P buf, size_t size) +{ + return write(buf, size); +} + int WiFiClient::read(uint8_t *buf, size_t size) { if(!available()) { diff --git a/libraries/WiFi/src/WiFiClient.h b/libraries/WiFi/src/WiFiClient.h index 6d27c3e4..3495bec8 100644 --- a/libraries/WiFi/src/WiFiClient.h +++ b/libraries/WiFi/src/WiFiClient.h @@ -44,6 +44,7 @@ public: int connect(const char *host, uint16_t port); size_t write(uint8_t data); size_t write(const uint8_t *buf, size_t size); + size_t write_P(PGM_P buf, size_t size); int available(); int read(); int read(uint8_t *buf, size_t size); @@ -84,6 +85,10 @@ public: IPAddress remoteIP(int fd) const; uint16_t remotePort() const; uint16_t remotePort(int fd) const; + IPAddress localIP() const; + IPAddress localIP(int fd) const; + uint16_t localPort() const; + uint16_t localPort(int fd) const; IPAddress localIP() const; IPAddress localIP(int fd) const; diff --git a/libraries/WiFi/src/WiFiServer.cpp b/libraries/WiFi/src/WiFiServer.cpp index 2e20d444..d0cce11c 100644 --- a/libraries/WiFi/src/WiFiServer.cpp +++ b/libraries/WiFi/src/WiFiServer.cpp @@ -21,6 +21,7 @@ #include #undef write +#undef close int WiFiServer::setTimeout(uint32_t seconds){ struct timeval tv; @@ -103,8 +104,16 @@ bool WiFiServer::hasClient() { } void WiFiServer::end(){ - close(sockfd); + lwip_close_r(sockfd); sockfd = -1; _listening = false; } +void WiFiServer::close(){ + end(); +} + +void WiFiServer::stop(){ + end(); +} + diff --git a/libraries/WiFi/src/WiFiServer.h b/libraries/WiFi/src/WiFiServer.h index 31fc7e3e..0c3cac95 100644 --- a/libraries/WiFi/src/WiFiServer.h +++ b/libraries/WiFi/src/WiFiServer.h @@ -50,6 +50,8 @@ class WiFiServer : public Server { using Print::write; void end(); + void close(); + void stop(); operator bool(){return _listening;} int setTimeout(uint32_t seconds); void stopAll();