diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-03-05 03:36:17 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-03-05 03:36:17 +0100 |
commit | 0b8e1a614fae4bdbf529992f04fdaf2cff498d50 (patch) | |
tree | 141ebd6f962719cc21c77a22e797912138356dc1 | |
parent | e80177752184bab0ec4290d1b04da9019690273f (diff) | |
download | blogc-0b8e1a614fae4bdbf529992f04fdaf2cff498d50.tar.gz blogc-0b8e1a614fae4bdbf529992f04fdaf2cff498d50.tar.bz2 blogc-0b8e1a614fae4bdbf529992f04fdaf2cff498d50.zip |
runserver: fixed request read. increased buffer
-rw-r--r-- | src/blogc-runserver/httpd-utils.c | 19 | ||||
-rw-r--r-- | src/blogc-runserver/httpd-utils.h | 2 | ||||
-rw-r--r-- | tests/blogc-runserver/check_httpd_utils.c | 33 |
3 files changed, 16 insertions, 38 deletions
diff --git a/src/blogc-runserver/httpd-utils.c b/src/blogc-runserver/httpd-utils.c index 5e9df2d..e67afb1 100644 --- a/src/blogc-runserver/httpd-utils.c +++ b/src/blogc-runserver/httpd-utils.c @@ -19,16 +19,25 @@ br_readline(int socket) bc_string_t *rv = bc_string_new(); char buffer[READLINE_BUFFER_SIZE]; ssize_t len; + bool end = false; while ((len = read(socket, buffer, READLINE_BUFFER_SIZE)) > 0) { - for (ssize_t i = 0; i < len; i++) { - if (buffer[i] == '\r' || buffer[i] == '\n' || buffer[i] == '\0') - goto end; - bc_string_append_c(rv, buffer[i]); + if (!end) { + for (ssize_t i = 0; i < len; i++) { + if (buffer[i] == '\r' || buffer[i] == '\n' || buffer[i] == '\0') { + // we finished "recording", but still need to exhaust + // request data. + end = true; + break; + } + bc_string_append_c(rv, buffer[i]); + } + } + if (len < READLINE_BUFFER_SIZE) { + break; } } -end: return bc_string_free(rv, false); } diff --git a/src/blogc-runserver/httpd-utils.h b/src/blogc-runserver/httpd-utils.h index 0e62758..026dd5f 100644 --- a/src/blogc-runserver/httpd-utils.h +++ b/src/blogc-runserver/httpd-utils.h @@ -9,7 +9,7 @@ #ifndef _HTTPD_UTILS_H #define _HTTPD_UTILS_H -#define READLINE_BUFFER_SIZE 256 +#define READLINE_BUFFER_SIZE 2048 char* br_readline(int socket); int br_hextoi(const char c); diff --git a/tests/blogc-runserver/check_httpd_utils.c b/tests/blogc-runserver/check_httpd_utils.c index 36a2913..e0fabe3 100644 --- a/tests/blogc-runserver/check_httpd_utils.c +++ b/tests/blogc-runserver/check_httpd_utils.c @@ -33,8 +33,6 @@ test_readline(void **state) char *t; will_return(__wrap_read, 1234); will_return(__wrap_read, "bola"); - will_return(__wrap_read, 1234); - will_return(__wrap_read, ""); t = br_readline(1234); assert_string_equal(t, "bola"); free(t); @@ -53,36 +51,6 @@ test_readline(void **state) t = br_readline(1234); assert_string_equal(t, "bola3"); free(t); - will_return(__wrap_read, 1234); - will_return(__wrap_read, "bola"); - will_return(__wrap_read, 1234); - will_return(__wrap_read, "guda"); - will_return(__wrap_read, 1234); - will_return(__wrap_read, ""); - t = br_readline(1234); - assert_string_equal(t, "bolaguda"); - free(t); - will_return(__wrap_read, 1234); - will_return(__wrap_read, "bola1"); - will_return(__wrap_read, 1234); - will_return(__wrap_read, "bola\nguda"); - t = br_readline(1234); - assert_string_equal(t, "bola1bola"); - free(t); - will_return(__wrap_read, 1234); - will_return(__wrap_read, "bola2"); - will_return(__wrap_read, 1234); - will_return(__wrap_read, "bola\rguda"); - t = br_readline(1234); - assert_string_equal(t, "bola2bola"); - free(t); - will_return(__wrap_read, 1234); - will_return(__wrap_read, "bola3"); - will_return(__wrap_read, 1234); - will_return(__wrap_read, "bola\r\nguda"); - t = br_readline(1234); - assert_string_equal(t, "bola3bola"); - free(t); } @@ -110,6 +78,7 @@ test_hextoi(void **state) assert_int_equal(br_hextoi('C'), 12); assert_int_equal(br_hextoi('D'), 13); assert_int_equal(br_hextoi('E'), 14); + assert_int_equal(br_hextoi('F'), 15); assert_int_equal(br_hextoi('g'), -1); assert_int_equal(br_hextoi('G'), -1); assert_int_equal(br_hextoi('-'), -1); |