diff options
| author | ame <[email protected]> | 2025-06-12 02:10:10 -0500 |
|---|---|---|
| committer | ame <[email protected]> | 2025-06-12 02:10:10 -0500 |
| commit | 8e7257aac8b30aaa57577770fd636e784361e35d (patch) | |
| tree | 71f7cb33f56a455bac2734bd53b483aa8bb7b27b /src/net/util.c | |
| parent | a2e8051d4cf6e46310e2e8aab83fee991560d8c0 (diff) | |
fix some net code, add streaming to some requests
Diffstat (limited to 'src/net/util.c')
| -rw-r--r-- | src/net/util.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/net/util.c b/src/net/util.c index 76ec30e..92d3bce 100644 --- a/src/net/util.c +++ b/src/net/util.c @@ -11,21 +11,21 @@ int64_t recv_header(int client_fd, char** _buffer, char** header_eof){ for(;;){ n = recv(client_fd, buffer + len, BUFFER_SIZE, 0); - if(n < 0){ - printf("%s %i\n", strerror(errno), errno); + if(n <= 0){ + //printf("%s %i\n", strerror(errno), errno); return -1; } - + + if((len += n) >= MAX_HEADER_SIZE){ + return -2; + } + // search the last 4 characters too if they exist // this could probably be changed to 3 int64_t start_len = len - 4 > 0 ? len - 4 : 0; int64_t search_end = len - 4 > 0 ? n + 4 : n; if((*header_eof = memmem(buffer + start_len, search_end, "\r\n\r\n", 4)) != NULL){ - return len + n; - } - - if((len += n) >= MAX_HEADER_SIZE){ - return -2; + return len; } buffer = realloc(buffer, sizeof* buffer * (len + BUFFER_SIZE + 1)); |
