Skip to content

Commit 1c58899

Browse files
reimplementing Server class with ethernet and wifi subclasses
1 parent b371331 commit 1c58899

File tree

8 files changed

+316
-232
lines changed

8 files changed

+316
-232
lines changed
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
#ifndef ARDUINO_LWIP_ETHERNET_CLIENT_H
2-
#define ARDUINO_LWIP_ETHERNET_CLIENT_H
3-
1+
#pragma once
42

53
#include "lwipClient.h"
64

75
class EthernetClient : public lwipClient {
86
public:
9-
EthernetClient() {
10-
this->bindCNetIf(Ethernet);
11-
}
12-
EthernetClient(struct tcp_pcb *pcb) : lwipClient(pcb) {
13-
this->bindCNetIf(Ethernet);
14-
}
15-
};
7+
EthernetClient() {
8+
}
9+
EthernetClient(struct tcp_pcb *pcb, lwipServer *server)
10+
: lwipClient(pcb, server) {
11+
}
12+
EthernetClient(lwipClient c)
13+
: lwipClient(c) {
14+
}
15+
16+
int connect(IPAddress ip, uint16_t port) {
17+
auto res = lwipClient::connect(ip, port);
1618

17-
#endif
19+
this->bindCNetIf(Ethernet);
20+
21+
return res;
22+
}
23+
};
Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
1-
#ifndef ARDUINO_LWIP_ETHERNET_SERVER_H
2-
#define ARDUINO_LWIP_ETHERNET_SERVER_H
3-
4-
1+
#pragma once
52

63
#include "lwipServer.h"
74
#include "EthernetClient.h"
85

9-
class EthernetServer : public lwipServer {
10-
public:
11-
EthernetServer() {}
12-
EthernetServer(uint16_t port) : lwipServer(port) {}
13-
14-
EthernetClient available() {
15-
accept();
6+
class EthernetServer: public lwipServer {
7+
public:
8+
void begin() {
9+
lwipServer::begin();
10+
this->bindCNetIf(WiFi);
11+
}
1612

17-
for (int n = 0; n < MAX_CLIENT; n++) {
18-
if (_tcp_client[n] != NULL) {
19-
if (_tcp_client[n]->pcb != NULL) {
20-
EthernetClient client(_tcp_client[n]);
21-
uint8_t s = client.status();
22-
if (s == TCP_ACCEPTED) {
23-
if (client.available()) {
24-
return client;
25-
}
26-
}
27-
}
28-
}
29-
}
30-
31-
struct tcp_struct *default_client = NULL;
32-
return EthernetClient(default_client);
33-
}
13+
EthernetClient available() {
14+
return EthernetClient(lwipServer::available());
15+
}
3416
};
35-
36-
#endif

libraries/WiFi/src/WiFiClient.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
#ifndef ARDUINO_LWIP_WIFI_CLIENT_H
2-
#define ARDUINO_LWIP_WIFI_CLIENT_H
3-
1+
#pragma once
42

53
#include "lwipClient.h"
64

7-
class WiFiClient : public lwipClient {
8-
public:
9-
WiFiClient() {
10-
this->bindCNetIf(WiFi);
11-
}
12-
WiFiClient(struct tcp_pcb *pcb) : lwipClient(pcb) {
13-
this->bindCNetIf(WiFi);
14-
}
15-
};
5+
class WiFiClient: public lwipClient {
6+
public:
7+
WiFiClient() {
8+
}
9+
WiFiClient(struct tcp_pcb *pcb, lwipServer *server)
10+
: lwipClient(pcb, server) {
11+
}
12+
WiFiClient(lwipClient c)
13+
: lwipClient(c) {
14+
}
1615

17-
#endif
16+
int connect(IPAddress ip, uint16_t port) {
17+
auto res = lwipClient::connect(ip, port);
1818

19+
this->bindCNetIf(WiFi);
20+
21+
return res;
22+
}
23+
};

libraries/WiFi/src/WiFiServer.h

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
1-
#ifndef ARDUINO_LWIP_WIFI_SERVER_H
2-
#define ARDUINO_LWIP_WIFI_SERVER_H
3-
1+
#pragma once
42

53
#include "lwipServer.h"
6-
#include "WiFiClient.h"
7-
8-
class WiFiServer : public lwipServer {
9-
public:
10-
WiFiServer() {}
11-
WiFiServer(uint16_t port) : lwipServer(port) {}
4+
#include "lwipClient.h"
125

13-
WiFiClient available() {
14-
accept();
6+
class WiFiServer: public lwipServer {
7+
public:
8+
void begin() {
9+
lwipServer::begin();
10+
this->bindCNetIf(WiFi);
11+
}
1512

16-
for (int n = 0; n < MAX_CLIENT; n++) {
17-
if (_tcp_client[n] != NULL) {
18-
if (_tcp_client[n]->pcb != NULL) {
19-
WiFiClient client(_tcp_client[n]);
20-
uint8_t s = client.status();
21-
if (s == TCP_ACCEPTED) {
22-
if (client.available()) {
23-
return client;
24-
}
25-
}
26-
}
27-
}
28-
}
29-
30-
struct tcp_struct *default_client = NULL;
31-
return WiFiClient(default_client);
32-
}
13+
WiFiClient available() {
14+
return WiFiClient(lwipServer::available());
15+
}
3316
};
34-
35-
#endif

0 commit comments

Comments
 (0)