mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-18 23:03:34 +03:00
ESP8266WebServer - Drop inactive connection when another is waiting to improve page load time (#8216)
* ESP8266WebServer - drop current HC_WAIT_READ connection sooner when another has data Safari sometimes opens two connections when loading a page and only sends a request over the second one, resulting in a 5 second wait (HTTP_MAX_DATA_WAIT) before the request is processed. This commit drops the current connection after 30ms (HTTP_MAX_DATA_AVAILABLE_WAIT) when there is a new connection with data available or the buffer of pending TCP clients is full (currently 5).
This commit is contained in:
@ -109,6 +109,25 @@ bool WiFiServer::hasClient() {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t WiFiServer::hasClientData() {
|
||||
ClientContext *next = _unclaimed;
|
||||
while (next) {
|
||||
size_t s = next->getSize();
|
||||
// return the amount of data available from the first connection that has any
|
||||
if (s) return s;
|
||||
next = next->next();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WiFiServer::hasMaxPendingClients() {
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
return ((struct tcp_pcb_listen *)_listen_pcb)->accepts_pending >= MAX_PENDING_CLIENTS_PER_PORT;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
WiFiClient WiFiServer::available(byte* status) {
|
||||
(void) status;
|
||||
if (_unclaimed) {
|
||||
|
@ -82,6 +82,13 @@ public:
|
||||
virtual ~WiFiServer() {}
|
||||
WiFiClient available(uint8_t* status = NULL);
|
||||
bool hasClient();
|
||||
// hasClientData():
|
||||
// returns the amount of data available from the first client
|
||||
// or 0 if there is none
|
||||
size_t hasClientData();
|
||||
// hasMaxPendingClients():
|
||||
// returns true if the queue of pending clients is full
|
||||
bool hasMaxPendingClients();
|
||||
void begin();
|
||||
void begin(uint16_t port);
|
||||
void begin(uint16_t port, uint8_t backlog);
|
||||
|
Reference in New Issue
Block a user