mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
Fix issue with peek function
This commit is contained in:
parent
a363b196a6
commit
a5c38d11a9
@ -35,8 +35,22 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) {
|
|||||||
{
|
{
|
||||||
ServerDrv::startClient(uint32_t(ip), port, _sock);
|
ServerDrv::startClient(uint32_t(ip), port, _sock);
|
||||||
WiFiClass::_state[_sock] = _sock;
|
WiFiClass::_state[_sock] = _sock;
|
||||||
while(!connected());
|
|
||||||
|
unsigned long start = millis();
|
||||||
|
|
||||||
|
// wait 4 second for the connection to close
|
||||||
|
while (!connected() && millis() - start < 10000)
|
||||||
|
delay(1);
|
||||||
|
|
||||||
|
if (!connected())
|
||||||
|
{
|
||||||
|
Serial.println("timeout on client connection");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Serial.println("CONNECTED");
|
||||||
}else{
|
}else{
|
||||||
|
Serial.println("No Socket available");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -94,8 +108,12 @@ int WiFiClient::read(uint8_t* buf, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int WiFiClient::peek() {
|
int WiFiClient::peek() {
|
||||||
//TODO to be implemented
|
uint8_t b;
|
||||||
return 0;
|
if (!available())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
ServerDrv::getData(_sock, &b, 1);
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiFiClient::flush() {
|
void WiFiClient::flush() {
|
||||||
@ -112,10 +130,11 @@ void WiFiClient::stop() {
|
|||||||
|
|
||||||
unsigned long start = millis();
|
unsigned long start = millis();
|
||||||
|
|
||||||
|
|
||||||
// wait a second for the connection to close
|
// wait a second for the connection to close
|
||||||
while (status() != CLOSED && millis() - start < 1000)
|
while (status() != CLOSED && millis() - start < 1000)
|
||||||
delay(1);
|
delay(1);
|
||||||
|
Serial.print("Stop client! Status:");Serial.println(status(),10);
|
||||||
_sock = 255;
|
_sock = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +144,12 @@ uint8_t WiFiClient::connected() {
|
|||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
uint8_t s = status();
|
uint8_t s = status();
|
||||||
|
/*
|
||||||
|
if (s== SYN_SENT) Serial.print("*");
|
||||||
|
else{
|
||||||
|
Serial.print("Status:"); Serial.println(s,10);
|
||||||
|
}
|
||||||
|
*/
|
||||||
return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
|
return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
|
||||||
s == FIN_WAIT_2 || s == TIME_WAIT ||
|
s == FIN_WAIT_2 || s == TIME_WAIT ||
|
||||||
s == SYN_SENT || s== SYN_RCVD ||
|
s == SYN_SENT || s== SYN_RCVD ||
|
||||||
|
@ -146,12 +146,13 @@ uint8_t ServerDrv::availData(uint8_t sock)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerDrv::getData(uint8_t sock, uint8_t *data)
|
bool ServerDrv::getData(uint8_t sock, uint8_t *data, uint8_t peek)
|
||||||
{
|
{
|
||||||
WAIT_FOR_SLAVE_SELECT();
|
WAIT_FOR_SLAVE_SELECT();
|
||||||
// Send Command
|
// Send Command
|
||||||
SpiDrv::sendCmd(GET_DATA_TCP_CMD, PARAM_NUMS_1);
|
SpiDrv::sendCmd(GET_DATA_TCP_CMD, PARAM_NUMS_2);
|
||||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
SpiDrv::sendParam(&sock, sizeof(sock));
|
||||||
|
SpiDrv::sendParam(peek, LAST_PARAM);
|
||||||
|
|
||||||
//Wait the reply elaboration
|
//Wait the reply elaboration
|
||||||
SpiDrv::waitForSlaveReady();
|
SpiDrv::waitForSlaveReady();
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
static uint8_t getClientState(uint8_t sock);
|
static uint8_t getClientState(uint8_t sock);
|
||||||
|
|
||||||
static bool getData(uint8_t sock, uint8_t *data);
|
static bool getData(uint8_t sock, uint8_t *data, uint8_t peek = 0);
|
||||||
|
|
||||||
static bool getDataBuf(uint8_t sock, uint8_t *data, uint16_t *len);
|
static bool getDataBuf(uint8_t sock, uint8_t *data, uint16_t *len);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user