ovidiucp/TinyWebServer

Remove lock functions

Closed this issue · 4 comments

Hello,
I've used your library and is very good, but I think there are two locks in some client data input that can hang the webserver.
I suggest the insertion of two timeout check that can unlock the functions when client don't send expected data.
I hope the code could be useful.
Thanks

Alberto

Here the diff

22a23
#define READ_TIMEOUT 100
124a126
uint32_t start_time = millis();
128a131,133
if (millis() - start_time > READ_TIMEOUT) {
return false;
}
131a137
start_time = millis();
522a529
uint32_t start_time = millis();
523a531,533
if (millis() - start_time > READ_TIMEOUT) {
return i < size - 1;
}
530a541
start_time = millis();

Thanks for the fix! Would you mind posting a unified diff (diff -u), or even better, sending a pull request?

Here the diff -u
Thanks

Alberto

diff -u ovidiucp-TinyWebServer-e46b2fd/TinyWebServer.cpp mio/TinyWebServer.cpp

--- ovidiucp-TinyWebServer-e46b2fd/TinyWebServer.cpp 2012-04-25 11:00:46.000000000 +0200
+++ mio/TinyWebServer.cpp 2012-09-03 11:16:01.000000000 +0200
@@ -20,6 +20,7 @@
// when the debugging is enabled and debugging lines are preceded by 'TWS:'

#define DEBUG 0
+#define READ_TIMEOUT 10

#include "Arduino.h"

@@ -122,13 +123,18 @@
char ch;
int pos;
const char* header;

  • uint32_t start_time = millis();
    while (1) {
    if (should_stop_processing()) {
    return false;
    }
  • if (millis() - start_time > READ_TIMEOUT) {
  •    return false;
    
  • }
    if (!read_next_char(client_, (uint8_t*)&ch)) {
    continue;
    }
  • start_time = millis();
    #if DEBUG
    Serial.print(ch);
    #endif
    @@ -520,7 +526,11 @@
    char ch;

buffer[0] = 0;

  • uint32_t start_time = millis();
    for (; i < size - 1; i++) {
  •    if (millis() - start_time > READ_TIMEOUT) {
    
  •           return i < size - 1;
    
  •    }
    
    if (!read_next_char(client_, (uint8_t*)&ch)) {
    continue;
    }
    @@ -528,6 +538,7 @@
    break;
    }
    buffer[i] = ch;
  • start_time = millis();
    }
    buffer[i] = 0;
    return i < size - 1;

Closed!

Awesome, thanks!

On Wed, Mar 25, 2015 at 9:14 AM, Aberto Panu notifications@github.com
wrote:

Closed!


Reply to this email directly or view it on GitHub
#15 (comment)
.

This confidential email is read by the NSA (at the least).