Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lwip2 updates: no more git sub-sub-module deps, faster checksum, backlog limitation and other fixes #6887

Merged
merged 24 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ jobs:
- name: "Platformio (1)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
install:
- sudo apt-get install python3-pip python3-setuptools
env:
- BUILD_PARITY=even
- name: "Platformio (2)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
install:
- sudo apt-get install python3-pip python3-setuptools
env:
- BUILD_PARITY=odd

Expand Down
35 changes: 24 additions & 11 deletions libraries/ESP8266WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ extern "C" {
#include "lwip/opt.h"
#include "lwip/tcp.h"
#include "lwip/inet.h"
#include "lwip/init.h" // LWIP_VERSION_
#include <include/ClientContext.h>

WiFiServer::WiFiServer(const IPAddress& addr, uint16_t port)
: _port(port)
, _addr(addr)
, _pcb(nullptr)
, _listen_pcb(nullptr)
, _unclaimed(nullptr)
, _discarded(nullptr)
{
Expand All @@ -49,7 +50,7 @@ WiFiServer::WiFiServer(const IPAddress& addr, uint16_t port)
WiFiServer::WiFiServer(uint16_t port)
: _port(port)
, _addr(IP_ANY_TYPE)
, _pcb(nullptr)
, _listen_pcb(nullptr)
, _unclaimed(nullptr)
, _discarded(nullptr)
{
Expand All @@ -59,7 +60,7 @@ void WiFiServer::begin() {
begin(_port);
}

void WiFiServer::begin(uint16_t port) {
void WiFiServer::begin(uint16_t port, int backlog) {
close();
_port = port;
err_t err;
Expand All @@ -77,13 +78,19 @@ void WiFiServer::begin(uint16_t port) {
return;
}

#if LWIP_VERSION_MAJOR == 1
(void)backlog;
tcp_pcb* listen_pcb = tcp_listen(pcb);
#else
tcp_pcb* listen_pcb = tcp_listen_with_backlog(pcb, backlog);
#endif

if (!listen_pcb) {
tcp_close(pcb);
return;
}
_pcb = listen_pcb;
_port = _pcb->local_port;
_listen_pcb = listen_pcb;
_port = _listen_pcb->local_port;
tcp_accept(listen_pcb, &WiFiServer::_s_accept);
tcp_arg(listen_pcb, (void*) this);
}
Expand Down Expand Up @@ -122,21 +129,21 @@ WiFiClient WiFiServer::available(byte* status) {
}

uint8_t WiFiServer::status() {
if (!_pcb)
if (!_listen_pcb)
return CLOSED;
return _pcb->state;
return _listen_pcb->state;
}

uint16_t WiFiServer::port() const {
return _port;
}

void WiFiServer::close() {
if (!_pcb) {
if (!_listen_pcb) {
return;
}
tcp_close(_pcb);
_pcb = nullptr;
tcp_close(_listen_pcb);
_listen_pcb = nullptr;
}

void WiFiServer::stop() {
Expand Down Expand Up @@ -171,7 +178,13 @@ long WiFiServer::_accept(tcp_pcb* apcb, long err) {
DEBUGV("WS:ac\r\n");
ClientContext* client = new ClientContext(apcb, &WiFiServer::_s_discard, this);
_unclaimed = slist_append_tail(_unclaimed, client);
tcp_accepted(_pcb);
#if LWIP_VERSION_MAJOR == 1
tcp_accepted(_listen_pcb);
#else
tcp_backlog_accepted(_listen_pcb);
// http://lwip.100.n7.nabble.com/Problem-re-opening-listening-pbc-tt32484.html#a32494
// https://www.nongnu.org/lwip/2_1_x/group__tcp__raw.html#gaeff14f321d1eecd0431611f382fcd338
#endif
return ERR_OK;
}

Expand Down
16 changes: 14 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ extern "C" {
#include "Server.h"
#include "IPAddress.h"

// lwIP-v2 backlog facility allows to keep memory safe by limiting the
// maximum number of simultaneously accepted clients.
// Generally in Arduino scenarios, only one client is used at a time.
// Default number of possibly simultaneously acepted client is defined
// below, user can overide it at runtime from sketch:
// WiFiServer::begin(port, max-simultaneous-clients-per-port);
// New incoming clients to this server will be delayed until an already
// connected one leaves. SYNACK is anyway answered to waiting clients, so
// the connection appears as open anyway.
#define MAX_DEFAULT_SIMULTANEOUS_CLIENTS_PER_PORT 3

class ClientContext;
class WiFiClient;

Expand All @@ -39,7 +50,7 @@ class WiFiServer : public Server {
protected:
uint16_t _port;
IPAddress _addr;
tcp_pcb* _pcb;
tcp_pcb* _listen_pcb;

ClientContext* _unclaimed;
ClientContext* _discarded;
Expand All @@ -52,7 +63,8 @@ class WiFiServer : public Server {
WiFiClient available(uint8_t* status = NULL);
bool hasClient();
void begin();
void begin(uint16_t port);
void begin(uint16_t port) { begin(port, MAX_DEFAULT_SIMULTANEOUS_CLIENTS_PER_PORT); }
void begin(uint16_t port, int backlog);
void setNoDelay(bool nodelay);
bool getNoDelay();
virtual size_t write(uint8_t);
Expand Down
2 changes: 1 addition & 1 deletion tests/host/common/MockWiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ WiFiClient WiFiServer::available (uint8_t* status)
{
(void)status;
if (hasClient())
return WiFiClient(new ClientContext(serverAccept(pcb2int(_pcb))));
return WiFiClient(new ClientContext(serverAccept(pcb2int(_listen_pcb))));
return WiFiClient();
}

Expand Down
13 changes: 7 additions & 6 deletions tests/host/common/MockWiFiServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ int serverAccept (int srvsock)
return mockSockSetup(clisock);
}

void WiFiServer::begin (uint16_t port)
void WiFiServer::begin (uint16_t port, int backlog)
{
(void)backlog;
_port = port;
return begin();
}
Expand Down Expand Up @@ -109,13 +110,13 @@ void WiFiServer::begin ()


// store int into pointer
_pcb = int2pcb(sock);
_listen_pcb = int2pcb(sock);
}

bool WiFiServer::hasClient ()
{
struct pollfd p;
p.fd = pcb2int(_pcb);
p.fd = pcb2int(_listen_pcb);
p.events = POLLIN;
return poll(&p, 1, 0) && p.revents == POLLIN;
}
Expand All @@ -134,7 +135,7 @@ size_t WiFiServer::write (const uint8_t *buf, size_t size)

void WiFiServer::close ()
{
if (pcb2int(_pcb) >= 0)
::close(pcb2int(_pcb));
_pcb = int2pcb(-1);
if (pcb2int(_listen_pcb) >= 0)
::close(pcb2int(_listen_pcb));
_listen_pcb = int2pcb(-1);
}
6 changes: 3 additions & 3 deletions tests/platformio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ source "$TRAVIS_BUILD_DIR"/tests/common.sh

function install_platformio()
{
pip install --user -U https://github.com/platformio/platformio/archive/develop.zip
pip3 install --user -U https://github.com/platformio/platformio/archive/develop.zip
platformio platform install "https://github.com/platformio/platform-espressif8266.git#feature/stage"
sed -i 's/https:\/\/github\.com\/esp8266\/Arduino\.git/*/' ~/.platformio/platforms/espressif8266/platform.json
ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266
ln -sf $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266
# Install dependencies:
# - esp8266/examples/ConfigFile
pio lib install "ArduinoJson@^6.11.0"
pio lib --global install "ArduinoJson@^6.11.0"
}

function build_sketches_with_platformio()
Expand Down
9 changes: 3 additions & 6 deletions tests/run_CI_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ EOF
test -z "$BUILD_TYPE" || break
done

# use pip2 for python2 with python3 is around, platformio doesn't like it
cp tests/platformio.sh tests/platformio-custom.sh
sed -i 's,pip ,pip2 ,g' tests/platformio-custom.sh

git submodule update --init

Expand Down Expand Up @@ -117,11 +114,11 @@ elif [ "$BUILD_TYPE" = "build1_odd" ]; then
BUILD_PARITY=odd tests/build1.sh

elif [ "$BUILD_TYPE" = "platformio" ]; then
tests/platformio-custom.sh
tests/platformio.sh
elif [ "$BUILD_TYPE" = "platformio_even" ]; then
BUILD_PARITY=even tests/platformio-custom.sh
BUILD_PARITY=even tests/platformio.sh
elif [ "$BUILD_TYPE" = "platformio_odd" ]; then
BUILD_PARITY=odd tests/platformio-custom.sh
BUILD_PARITY=odd tests/platformio.sh

elif [ "$BUILD_TYPE" = host ]; then
tests/ci/host_test.sh
Expand Down
Binary file modified tools/sdk/lib/liblwip2-1460-feat.a
Binary file not shown.
Binary file modified tools/sdk/lib/liblwip2-1460.a
Binary file not shown.
Binary file modified tools/sdk/lib/liblwip2-536-feat.a
Binary file not shown.
Binary file modified tools/sdk/lib/liblwip2-536.a
Binary file not shown.
Binary file modified tools/sdk/lib/liblwip6-1460-feat.a
Binary file not shown.
Binary file modified tools/sdk/lib/liblwip6-536-feat.a
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/sdk/lwip2/include/lwip-git-hash.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated by makefiles/make-lwip2-hash
#ifndef LWIP_HASH_H
#define LWIP_HASH_H
#define LWIP_HASH_STR "STABLE-2_1_2_RELEASE/glue:1.2-16-ge23a07e"
#define LWIP_HASH_STR "STABLE-2_1_2_RELEASE/glue:1.2-27-g7aade53"
#endif // LWIP_HASH_H
2 changes: 1 addition & 1 deletion tools/sdk/lwip2/include/lwip/priv/tcp_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ extern struct tcp_pcb ** const tcp_pcb_lists[NUM_TCP_PCB_LISTS];
#if TCP_DEBUG_PCB_LISTS
#define TCP_REG(pcbs, npcb) do {\
struct tcp_pcb *tcp_tmp_pcb; \
LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %"U16_F"\n", (void *)(npcb), (npcb)->local_port)); \
LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %" U16_F "\n", (void *)(npcb), (npcb)->local_port)); \
for (tcp_tmp_pcb = *(pcbs); \
tcp_tmp_pcb != NULL; \
tcp_tmp_pcb = tcp_tmp_pcb->next) { \
Expand Down
8 changes: 7 additions & 1 deletion tools/sdk/lwip2/include/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@
* TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb.
*/
#if !defined TCP_LISTEN_BACKLOG || defined __DOXYGEN__
#define TCP_LISTEN_BACKLOG 0
#define TCP_LISTEN_BACKLOG LWIP_FEATURES // 0
#endif

/**
Expand Down Expand Up @@ -2278,6 +2278,12 @@
* @ingroup lwip_opts_infrastructure
* @{
*/
/**
* LWIP_CHKSUM_ALGORITHM==3: Checksum algorithm fastest for ESP8266
*/
#if !defined LWIP_CHKSUM_ALGORITHM || defined __DOXYGEN__
#define LWIP_CHKSUM_ALGORITHM 3 // 2
#endif
/**
* LWIP_CHECKSUM_CTRL_PER_NETIF==1: Checksum generation/check can be enabled/disabled
* per netif.
Expand Down