From be067d9c0a30ed211b92bae9ebbf46b0bbf48454 Mon Sep 17 00:00:00 2001
From: Philippe Coval
Date: Fri, 4 Jan 2019 11:14:14 +0100
Subject: [PATCH 1/2] client: Fix bool operator on init and ongoing use
When iterating we make sure client's socket is not closing
since _tcp_client remains after close.
This was tested on nuleo-f767zi using project webthing-arduino
Change-Id: Ie465fe59009c33957dad97f1c70b4dc3af3b2ebe
Forwarded: https://github.com/stm32duino/STM32Ethernet/pull/17
Signed-off-by: Philippe Coval
---
src/EthernetClient.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/EthernetClient.cpp b/src/EthernetClient.cpp
index f02c486..349ffb6 100644
--- a/src/EthernetClient.cpp
+++ b/src/EthernetClient.cpp
@@ -9,12 +9,14 @@ extern "C" {
#include "EthernetServer.h"
#include "Dns.h"
-EthernetClient::EthernetClient() {
+EthernetClient::EthernetClient()
+ :_tcp_client(NULL) {
}
/* Deprecated constructor. Keeps compatibility with W5100 architecture
sketches but sock is ignored. */
-EthernetClient::EthernetClient(uint8_t sock) {
+EthernetClient::EthernetClient(uint8_t sock)
+ :_tcp_client(NULL) {
UNUSED(sock);
}
@@ -181,7 +183,7 @@ uint8_t EthernetClient::status() {
// EthernetServer::available() as the condition in an if-statement.
EthernetClient::operator bool() {
- return _tcp_client != NULL;
+ return (_tcp_client && (_tcp_client->state != TCP_CLOSING));
}
bool EthernetClient::operator==(const EthernetClient& rhs) {
From a443221fb53d196cdd399d5193ec6f05177aa18a Mon Sep 17 00:00:00 2001
From: Philippe Coval
Date: Fri, 4 Jan 2019 13:59:40 +0100
Subject: [PATCH 2/2] server: Initialize class member on dynamic alloc
Also replace default constructor to use port 80 by default.
I noticed that server worked on global instance.
but not if used in class (allocated with new).
This change makes both use cases working.
Forwarded: https://github.com/stm32duino/STM32Ethernet/pull/17
Relate-to: https://github.com/rzr/webthing-iotjs/wiki/MCU
Change-Id: I2e21e34a43f3cadb7981f2e359a5960735daa5d3
Signed-off-by: Philippe Coval
---
src/EthernetServer.cpp | 2 ++
src/EthernetServer.h | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/EthernetServer.cpp b/src/EthernetServer.cpp
index f5353d8..18ff147 100644
--- a/src/EthernetServer.cpp
+++ b/src/EthernetServer.cpp
@@ -9,6 +9,8 @@ extern "C" {
EthernetServer::EthernetServer(uint16_t port)
{
_port = port;
+ _tcp_client[MAX_CLIENT] = {};
+ _tcp_server = {};
}
void EthernetServer::begin()
diff --git a/src/EthernetServer.h b/src/EthernetServer.h
index 317bf41..fb42c43 100644
--- a/src/EthernetServer.h
+++ b/src/EthernetServer.h
@@ -14,7 +14,7 @@ public Server {
void accept(void);
public:
- EthernetServer(uint16_t);
+ EthernetServer(uint16_t port = 80);
EthernetClient available();
virtual void begin();
virtual size_t write(uint8_t);