Skip to content

Commit ad5dead

Browse files
committed
Changed names of the Ethernet classes: Client -> EthernetClient, NetClient -> Client, and basic testing performed
1 parent b7533c1 commit ad5dead

File tree

20 files changed

+89
-89
lines changed

20 files changed

+89
-89
lines changed

hardware/arduino/cores/arduino/NetClient.h renamed to hardware/arduino/cores/arduino/Client.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#ifndef netclient_h
2-
#define netclient_h
1+
#ifndef client_h
2+
#define client_h
33
#include "Print.h"
4-
#include "NetClient.h"
4+
#include "Stream.h"
55
#include "IPAddress.h"
66

7-
class NetClient : public Stream {
7+
class Client : public Stream {
88

99
public:
1010
virtual int connect(IPAddress ip, uint16_t port) =0;
@@ -20,6 +20,8 @@ class NetClient : public Stream {
2020
virtual void stop() = 0;
2121
virtual uint8_t connected() = 0;
2222
virtual operator bool() = 0;
23+
protected:
24+
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
2325
};
2426

2527
#endif

hardware/arduino/cores/arduino/NetServer.h

-11
This file was deleted.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef server_h
2+
#define server_h
3+
4+
class Server {
5+
public:
6+
virtual void begin() =0;
7+
};
8+
9+
#endif

libraries/Ethernet/Ethernet.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <inttypes.h>
55
//#include "w5100.h"
66
#include "IPAddress.h"
7-
#include "Client.h"
8-
#include "Server.h"
7+
#include "EthernetClient.h"
8+
#include "EthernetServer.h"
99

1010
#define MAX_SOCK_NUM 4
1111

@@ -29,8 +29,8 @@ class EthernetClass {
2929
IPAddress gatewayIP();
3030
IPAddress dnsServerIP();
3131

32-
friend class Client;
33-
friend class Server;
32+
friend class EthernetClient;
33+
friend class EthernetServer;
3434
};
3535

3636
extern EthernetClass Ethernet;

libraries/Ethernet/Client.cpp renamed to libraries/Ethernet/EthernetClient.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ extern "C" {
88
#include "Arduino.h"
99

1010
#include "Ethernet.h"
11-
#include "Client.h"
12-
#include "Server.h"
11+
#include "EthernetClient.h"
12+
#include "EthernetServer.h"
1313
#include "Dns.h"
1414

15-
uint16_t Client::_srcport = 1024;
15+
uint16_t EthernetClient::_srcport = 1024;
1616

17-
Client::Client() : _sock(MAX_SOCK_NUM) {
17+
EthernetClient::EthernetClient() : _sock(MAX_SOCK_NUM) {
1818
}
1919

20-
Client::Client(uint8_t sock) : _sock(sock) {
20+
EthernetClient::EthernetClient(uint8_t sock) : _sock(sock) {
2121
}
2222

23-
int Client::connect(const char* host, uint16_t port) {
23+
int EthernetClient::connect(const char* host, uint16_t port) {
2424
// Look up the host first
2525
int ret = 0;
2626
DNSClient dns;
@@ -35,7 +35,7 @@ int Client::connect(const char* host, uint16_t port) {
3535
}
3636
}
3737

38-
int Client::connect(IPAddress ip, uint16_t port) {
38+
int EthernetClient::connect(IPAddress ip, uint16_t port) {
3939
if (_sock != MAX_SOCK_NUM)
4040
return 0;
4141

@@ -54,7 +54,7 @@ int Client::connect(IPAddress ip, uint16_t port) {
5454
if (_srcport == 0) _srcport = 1024;
5555
socket(_sock, SnMR::TCP, _srcport, 0);
5656

57-
if (!::connect(_sock, ip.raw_address(), port)) {
57+
if (!::connect(_sock, rawIPAddress(ip), port)) {
5858
_sock = MAX_SOCK_NUM;
5959
return 0;
6060
}
@@ -70,15 +70,15 @@ int Client::connect(IPAddress ip, uint16_t port) {
7070
return 1;
7171
}
7272

73-
size_t Client::write(uint8_t b) {
73+
size_t EthernetClient::write(uint8_t b) {
7474
return write(&b, 1);
7575
}
7676

77-
size_t Client::write(const char *str) {
77+
size_t EthernetClient::write(const char *str) {
7878
return write((const uint8_t *) str, strlen(str));
7979
}
8080

81-
size_t Client::write(const uint8_t *buf, size_t size) {
81+
size_t EthernetClient::write(const uint8_t *buf, size_t size) {
8282
if (_sock == MAX_SOCK_NUM) {
8383
setWriteError();
8484
return 0;
@@ -90,13 +90,13 @@ size_t Client::write(const uint8_t *buf, size_t size) {
9090
return size;
9191
}
9292

93-
int Client::available() {
93+
int EthernetClient::available() {
9494
if (_sock != MAX_SOCK_NUM)
9595
return W5100.getRXReceivedSize(_sock);
9696
return 0;
9797
}
9898

99-
int Client::read() {
99+
int EthernetClient::read() {
100100
uint8_t b;
101101
if ( recv(_sock, &b, 1) > 0 )
102102
{
@@ -110,11 +110,11 @@ int Client::read() {
110110
}
111111
}
112112

113-
int Client::read(uint8_t *buf, size_t size) {
113+
int EthernetClient::read(uint8_t *buf, size_t size) {
114114
return recv(_sock, buf, size);
115115
}
116116

117-
int Client::peek() {
117+
int EthernetClient::peek() {
118118
uint8_t b;
119119
// Unlike recv, peek doesn't check to see if there's any data available, so we must
120120
if (!available())
@@ -123,12 +123,12 @@ int Client::peek() {
123123
return b;
124124
}
125125

126-
void Client::flush() {
126+
void EthernetClient::flush() {
127127
while (available())
128128
read();
129129
}
130130

131-
void Client::stop() {
131+
void EthernetClient::stop() {
132132
if (_sock == MAX_SOCK_NUM)
133133
return;
134134

@@ -148,22 +148,22 @@ void Client::stop() {
148148
_sock = MAX_SOCK_NUM;
149149
}
150150

151-
uint8_t Client::connected() {
151+
uint8_t EthernetClient::connected() {
152152
if (_sock == MAX_SOCK_NUM) return 0;
153153

154154
uint8_t s = status();
155155
return !(s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::FIN_WAIT ||
156156
(s == SnSR::CLOSE_WAIT && !available()));
157157
}
158158

159-
uint8_t Client::status() {
159+
uint8_t EthernetClient::status() {
160160
if (_sock == MAX_SOCK_NUM) return SnSR::CLOSED;
161161
return W5100.readSnSR(_sock);
162162
}
163163

164164
// the next function allows us to use the client returned by
165-
// Server::available() as the condition in an if-statement.
165+
// EthernetServer::available() as the condition in an if-statement.
166166

167-
Client::operator bool() {
167+
EthernetClient::operator bool() {
168168
return _sock != MAX_SOCK_NUM;
169169
}

libraries/Ethernet/Client.h renamed to libraries/Ethernet/EthernetClient.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#ifndef client_h
2-
#define client_h
1+
#ifndef ethernetclient_h
2+
#define ethernetclient_h
33
#include "Arduino.h"
44
#include "Print.h"
5-
#include "NetClient.h"
5+
#include "Client.h"
66
#include "IPAddress.h"
77

8-
class Client : public NetClient {
8+
class EthernetClient : public Client {
99

1010
public:
11-
Client();
12-
Client(uint8_t sock);
11+
EthernetClient();
12+
EthernetClient(uint8_t sock);
1313

1414
uint8_t status();
1515
virtual int connect(IPAddress ip, uint16_t port);
@@ -26,7 +26,7 @@ class Client : public NetClient {
2626
virtual uint8_t connected();
2727
virtual operator bool();
2828

29-
friend class Server;
29+
friend class EthernetServer;
3030

3131
private:
3232
static uint16_t _srcport;

libraries/Ethernet/Server.cpp renamed to libraries/Ethernet/EthernetServer.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ extern "C" {
55
}
66

77
#include "Ethernet.h"
8-
#include "Client.h"
9-
#include "Server.h"
8+
#include "EthernetClient.h"
9+
#include "EthernetServer.h"
1010

11-
Server::Server(uint16_t port)
11+
EthernetServer::EthernetServer(uint16_t port)
1212
{
1313
_port = port;
1414
}
1515

16-
void Server::begin()
16+
void EthernetServer::begin()
1717
{
1818
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
19-
Client client(sock);
19+
EthernetClient client(sock);
2020
if (client.status() == SnSR::CLOSED) {
2121
socket(sock, SnMR::TCP, _port, 0);
2222
listen(sock);
@@ -26,12 +26,12 @@ void Server::begin()
2626
}
2727
}
2828

29-
void Server::accept()
29+
void EthernetServer::accept()
3030
{
3131
int listening = 0;
3232

3333
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
34-
Client client(sock);
34+
EthernetClient client(sock);
3535

3636
if (EthernetClass::_server_port[sock] == _port) {
3737
if (client.status() == SnSR::LISTEN) {
@@ -48,12 +48,12 @@ void Server::accept()
4848
}
4949
}
5050

51-
Client Server::available()
51+
EthernetClient EthernetServer::available()
5252
{
5353
accept();
5454

5555
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
56-
Client client(sock);
56+
EthernetClient client(sock);
5757
if (EthernetClass::_server_port[sock] == _port &&
5858
(client.status() == SnSR::ESTABLISHED ||
5959
client.status() == SnSR::CLOSE_WAIT)) {
@@ -64,27 +64,27 @@ Client Server::available()
6464
}
6565
}
6666

67-
return Client(MAX_SOCK_NUM);
67+
return EthernetClient(MAX_SOCK_NUM);
6868
}
6969

70-
size_t Server::write(uint8_t b)
70+
size_t EthernetServer::write(uint8_t b)
7171
{
7272
write(&b, 1);
7373
}
7474

75-
size_t Server::write(const char *str)
75+
size_t EthernetServer::write(const char *str)
7676
{
7777
write((const uint8_t *)str, strlen(str));
7878
}
7979

80-
size_t Server::write(const uint8_t *buffer, size_t size)
80+
size_t EthernetServer::write(const uint8_t *buffer, size_t size)
8181
{
8282
size_t n = 0;
8383

8484
accept();
8585

8686
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
87-
Client client(sock);
87+
EthernetClient client(sock);
8888

8989
if (EthernetClass::_server_port[sock] == _port &&
9090
client.status() == SnSR::ESTABLISHED) {

libraries/Ethernet/Server.h renamed to libraries/Ethernet/EthernetServer.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
#ifndef server_h
2-
#define server_h
1+
#ifndef ethernetserver_h
2+
#define ethernetserver_h
33

4-
#include "NetServer.h"
4+
#include "Server.h"
55

6-
class Client;
6+
class EthernetClient;
77

8-
class Server :
9-
public NetServer {
8+
class EthernetServer :
9+
public Server {
1010
private:
1111
uint16_t _port;
1212
void accept();
1313
public:
14-
Server(uint16_t);
15-
Client available();
14+
EthernetServer(uint16_t);
15+
EthernetClient available();
1616
virtual void begin();
1717
virtual size_t write(uint8_t);
1818
virtual size_t write(const char *str);

libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.pde

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ IPAddress subnet(255, 255, 255, 0);
3939
// Initialize the Ethernet server library
4040
// with the IP address and port you want to use
4141
// (port 80 is default for HTTP):
42-
Server server(80);
42+
EthernetServer server(80);
4343

4444

4545
//Sensor's memory register addresses:
@@ -96,7 +96,7 @@ void loop() {
9696
}
9797

9898
// listen for incoming Ethernet connections:
99-
listenForClients();
99+
listenForEthernetClients();
100100
}
101101

102102

@@ -124,9 +124,9 @@ void getData() {
124124
Serial.println(" Pa");
125125
}
126126

127-
void listenForClients() {
127+
void listenForEthernetClients() {
128128
// listen for incoming clients
129-
Client client = server.available();
129+
EthernetClient client = server.available();
130130
if (client) {
131131
Serial.println("Got a client");
132132
// an http request ends with a blank line

libraries/Ethernet/examples/ChatServer/ChatServer.pde

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ IPAddress gateway(192,168,1, 1);
2929
IPAddress subnet(255, 255, 0, 0);
3030

3131
// telnet defaults to port 23
32-
Server server(23);
32+
EthernetServer server(23);
3333
boolean gotAMessage = false; // whether or not you got a message from the client yet
3434

3535
void setup() {
@@ -43,7 +43,7 @@ void setup() {
4343

4444
void loop() {
4545
// wait for a new client:
46-
Client client = server.available();
46+
EthernetClient client = server.available();
4747

4848
// when the client sends the first byte, say hello:
4949
if (client) {

0 commit comments

Comments
 (0)