File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed <
8000
div class="Box-sc-g0xbh4-0 prc-PageLayout-ContentWrapper-b-QRo Commit-module__SplitPageLayout_Content--ZY6yu" data-is-hidden="false">
Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -279,8 +279,28 @@ void WiFiClient::flush() {
279
279
280
280
uint8_t WiFiClient::connected ()
281
281
{
282
- uint8_t dummy = 0 ;
283
- read (&dummy, 0 );
282
+ if (_connected) {
283
+ uint8_t dummy;
284
+ int res = recv (fd (), &dummy, 0 , MSG_DONTWAIT);
285
+ if (res <= 0 ) {
286
+ switch (errno) {
287
+ case ENOTCONN:
288
+ case EPIPE:
289
+ case ECONNRESET:
290
+ case ECONNREFUSED:
291
+ case ECONNABORTED:
292
+ _connected = false ;
293
+ break ;
294
+ default :
295
+ _connected = true ;
296
+ break ;
297
+ }
298
+ }
299
+ else {
300
+ // Should never happen since requested 0 bytes
301
+ _connected = true ;
302
+ }
303
+ }
284
304
return _connected;
285
305
}
286
306
Original file line number Diff line number Diff line change @@ -45,8 +45,11 @@ WiFiClient WiFiServer::available(){
45
45
int client_sock = accept (sockfd, (struct sockaddr *)&_client, (socklen_t *)&cs);
46
46
if (client_sock >= 0 ){
47
47
int val = 1 ;
48
- if (setsockopt (client_sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&val, sizeof (int )) == ESP_OK)
49
- return WiFiClient (client_sock);
48
+ if (setsockopt (client_sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&val, sizeof (int )) == ESP_OK) {
49
+ val = _noDelay;
50
+ if (setsockopt (client_sock, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof (int )) == ESP_OK)
51
+ return WiFiClient (client_sock);
52
+ }
50
53
}
51
54
return WiFiClient ();
52
55
}
@@ -69,6 +72,14 @@ void WiFiServer::begin(){
69
72
_listening = true ;
70
73
}
71
74
75
+ void WiFiServer::setNoDelay (bool nodelay) {
76
+ _noDelay = nodelay;
77
+ }
78
+
79
+ bool WiFiServer::getNoDelay () {
80
+ return _noDelay;
81
+ }
82
+
72
83
void WiFiServer::end (){
73
84
close (sockfd);
74
85
sockfd = -1 ;
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ class WiFiServer : public Server {
29
29
uint16_t _port;
30
30
uint8_t _max_clients;
31
31
bool _listening;
32
+ bool _noDelay = false ;
32
33
33
34
public:
34
35
void listenOnLocalhost (){}
@@ -38,6 +39,8 @@ class WiFiServer : public Server {
38
39
WiFiClient available ();
39
40
WiFiClient accept (){return available ();}
40
41
void begin ();
42
+ void setNoDelay (bool nodelay);
43
+ bool getNoDelay ();
41
44
size_t write (const uint8_t *data, size_t len);
42
45
size_t write (uint8_t data){
43
46
return write (&data, 1 );
0 commit comments