You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue was created in order to create a reference issue for a PR.
When client.stop() is called and then a new client is created soon after, client.connected() == true due to still pending socket close.
In the very commonly used context
while (client.connected()) {
if (client.available()) {
// other stuff happens
}
}
this causes client.available() to block, which it should not do. When writing asynchronous programs, this can cause major issues in timing-sensitive tasks.
Sketch
Requires fix for issue #257 to be applied because of WiFiClient copy assignment.
#include<WiFi.h>char ssid[] = ""; // your network SSID (name)char pass[] = ""; // your network passwordint status = WL_IDLE_STATUS;
WiFiServer server(80);
WiFiClient client;
voidsetup()
{
Serial.begin(115200);
while (status != WL_CONNECTED) {
status = WiFi.begin(ssid, pass);
delay(5000);
}
server.setNonBlockingMode(); // server is set to NonBlockingMode();
server.begin();
}
voidloop()
{
client = server.available();
if (client) {
Serial.println("new client connected");
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n') {
if (currentLine.length() == 0) {
//do something
} else {
currentLine = "";
}
} elseif (c != '\r') {
currentLine += c;
}
}
}
client.stop();
Serial.println("client disconnected");
} else {
Serial.println("waiting for client connection");
delay(1000);
}
}
Error/Debug Message
// ... repeats while no client in non-blocking mode
[ERROR] get_available Accept connection failed
new client connected
client disconnected
[ERROR] get_available Accept connection failed
new client connected
client disconnected
[ERROR] get_available Accept connection failed
new client connected
client disconnected
[INFO] A client connected to this server :
[PORT]: 55775
[IP]:192.168.2.36
new client connected
GET / HTTP/1.1
Host: 192.168.2.172
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,fil;q=0.8
Cookie: __guid=259319114.1308697201864418800.1719734660203.9114
client disconnected
[INFO] A client connected to this server :
[PORT]: 55776
[IP]:192.168.2.36
new client connected
// blocked here by client.available()
Reproduce remarks
Since the client does nothing in the sketch above, the socket can sometimes be closed quickly. But I was able to reproduce this issue reliably on first try or with one or two browser refreshes.
I have checked online documentation, FAQ, GitHub Wiki and existing/closed issues.
I confirm I have checked online documentation, FAQ, GitHub Wiki and existing/closed issues.
The text was updated successfully, but these errors were encountered:
This fixes the broken rule of 3/5/0 in WiFiClient by removing the
unneeded destructor, which caused the socket to stop prematurely on
copy assignment.
It also fixes the blocking behavior caused by `client.available()` by
removing the unneeded `try_again` label and its corresponding `goto`.
In its place, we stop the socket (already pending stop) instead.
ClosesAmeba-AIoT#257, Ameba-AIoT#258
* fix: client non-persistent and blocking
This fixes the broken rule of 3/5/0 in WiFiClient by removing the
unneeded destructor, which caused the socket to stop prematurely on
copy assignment.
It also fixes the blocking behavior caused by `client.available()` by
removing the unneeded `try_again` label and its corresponding `goto`.
In its place, we stop the socket (already pending stop) instead.
Closes#257, #258
* Update WiFiClient.cpp
revert: reinstates the try_again label and the relevant goto
This reinstates the `try_again` label and the relevant `goto` statement as requested by @M-ichae-l in comment #r1713128977.
* Update WiFiClient.cpp
feat: stops socket if the client isn't in blocking mode
When `WiFiClient::available()` is called, this stops the socket if `clientdrv.getLastErrno(_sock)` returns `EAGAIN` and the client isn't in blocking mode.
* Update WiFiClient.cpp
* Update release_commit_log.txt
Boards
AMB82-Mini
External Hardware
Other than included JXF37 camera, none.
Hardware Configuration
None
Version
latest main (checkout manually)
IDE Name
VSCode w/ Arduino extension
Operating System
Windows 11
Auto Flash Mode
Disable
Erase All Flash Memory (16MB)
Disable
Standard Lib
Arduino_STD_PRINTF
Upload Speed
2000000
Description
This issue was created in order to create a reference issue for a PR.
When
client.stop()
is called and then a new client is created soon after,client.connected() == true
due to still pending socket close.In the very commonly used context
this causes
client.available()
to block, which it should not do. When writing asynchronous programs, this can cause major issues in timing-sensitive tasks.Sketch
Requires fix for issue #257 to be applied because of WiFiClient copy assignment.
Error/Debug Message
Reproduce remarks
Since the client does nothing in the sketch above, the socket can sometimes be closed quickly. But I was able to reproduce this issue reliably on first try or with one or two browser refreshes.
I have checked online documentation, FAQ, GitHub Wiki and existing/closed issues.
The text was updated successfully, but these errors were encountered: