mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
add localPort to EthernetClient, simplify operator==
This commit is contained in:
parent
ca37de4ba4
commit
937bce1a0b
@ -19,6 +19,7 @@ public:
|
||||
virtual void stop() = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual operator bool() = 0;
|
||||
virtual uint16_t localPort() = 0;
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
|
@ -165,13 +165,12 @@ EthernetClient::operator bool() {
|
||||
}
|
||||
|
||||
bool EthernetClient::operator==(const EthernetClient& rhs) {
|
||||
if (_sock == MAX_SOCK_NUM || rhs._sock == MAX_SOCK_NUM) return false;
|
||||
if (W5100.readSnDPORT(_sock)!=W5100.readSnDPORT(rhs._sock)) return false;
|
||||
uint32_t a1;
|
||||
uint32_t a2;
|
||||
W5100.readSnDIPR(_sock,(uint8_t*) &a1);
|
||||
W5100.readSnDIPR(rhs._sock,(uint8_t*) &a2);
|
||||
return a1==a2;
|
||||
return _sock == rhs._sock && _sock != MAX_SOCK_NUM && rhs._sock != MAX_SOCK_NUM;
|
||||
}
|
||||
|
||||
uint16_t EthernetClient::localPort() {
|
||||
if (_sock == MAX_SOCK_NUM) return 0;
|
||||
return W5100.readSnPORT(_sock);
|
||||
}
|
||||
|
||||
IPAddress EthernetClient::remoteIP() {
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
virtual uint8_t connected();
|
||||
virtual operator bool();
|
||||
virtual bool operator==(const EthernetClient&);
|
||||
virtual uint16_t localPort();
|
||||
virtual IPAddress remoteIP();
|
||||
virtual uint16_t remotePort();
|
||||
|
||||
|
@ -72,8 +72,6 @@ void loop() {
|
||||
for (byte i=0;i<4;i++) {
|
||||
if (clients[i]!=client) {
|
||||
clients[i] = client;
|
||||
Serial.print("found slot: ");
|
||||
Serial.println(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -105,7 +103,6 @@ void loop() {
|
||||
for (byte i=0;i<4;i++) {
|
||||
if (!(clients[i].connected())) {
|
||||
clients[i].stop();
|
||||
~clients[i];
|
||||
clients[i]=EthernetClient();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user