1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-29 05:21:37 +03:00

restore proper arduino Client:: & Wire:: API (#5969)

This commit is contained in:
david gauchard
2019-04-26 22:05:46 +02:00
committed by GitHub
parent 5dd780c571
commit cdb549572d
15 changed files with 65 additions and 52 deletions

View File

@ -35,7 +35,7 @@ int EthernetClient::connect(const char* host, uint16_t port) {
}
}
int EthernetClient::connect(CONST IPAddress& ip, uint16_t port) {
int EthernetClient::connect(IPAddress ip, uint16_t port) {
if (_sock != MAX_SOCK_NUM)
return 0;
@ -119,15 +119,13 @@ int EthernetClient::peek() {
return b;
}
bool EthernetClient::flush(unsigned int maxWaitMs) {
(void)maxWaitMs;
void EthernetClient::flush() {
::flush(_sock);
return true;
}
bool EthernetClient::stop(unsigned int maxWaitMs) {
void EthernetClient::stop() {
if (_sock == MAX_SOCK_NUM)
return true;
return;
// attempt to close the connection gracefully (send a FIN to other side)
disconnect(_sock);
@ -135,27 +133,20 @@ bool EthernetClient::stop(unsigned int maxWaitMs) {
// wait up to a second for the connection to close
uint8_t s;
if (maxWaitMs == 0)
maxWaitMs = 1000;
do {
s = status();
if (s == SnSR::CLOSED)
break; // exit the loop
delay(1);
} while (millis() - start < maxWaitMs);
bool ret = true;
} while (millis() - start < 1000);
// if it hasn't closed, close it forcefully
if (s != SnSR::CLOSED) {
ret = false;
close(_sock);
}
EthernetClass::_server_port[_sock] = 0;
_sock = MAX_SOCK_NUM;
return ret;
}
uint8_t EthernetClient::connected() {

View File

@ -12,7 +12,7 @@ public:
EthernetClient(uint8_t sock);
uint8_t status();
virtual int connect(CONST IPAddress& ip, uint16_t port);
virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char *host, uint16_t port);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);
@ -20,8 +20,8 @@ public:
virtual int read();
virtual int read(uint8_t *buf, size_t size);
virtual int peek();
virtual bool flush(unsigned int maxWaitMs = 0);
virtual bool stop(unsigned int maxWaitMs = 0);
virtual void flush();
virtual void stop();
virtual uint8_t connected();
virtual operator bool();
virtual bool operator==(const bool value) { return bool() == value; }

View File

@ -94,9 +94,9 @@ public:
virtual void flush(); // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() const { return _remoteIP; };
virtual IPAddress remoteIP() { return _remoteIP; };
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() const { return _remotePort; };
virtual uint16_t remotePort() { return _remotePort; };
};
#endif