diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ot_tcp.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/ot_tcp.c b/src/ot_tcp.c index f93795b..5d7b78f 100644 --- a/src/ot_tcp.c +++ b/src/ot_tcp.c | |||
| @@ -45,6 +45,7 @@ static ssize_t header_complete(char *request, ssize_t byte_count) { | |||
| 45 | void tcp_read(const int64_t sock, struct ot_workstruct *ws) { | 45 | void tcp_read(const int64_t sock, struct ot_workstruct *ws) { |
| 46 | struct http_data *cookie = fdstate_cookie(sock); | 46 | struct http_data *cookie = fdstate_cookie(sock); |
| 47 | ssize_t byte_count = read((int)sock, ws->inbuf, G_INBUF_SIZE); | 47 | ssize_t byte_count = read((int)sock, ws->inbuf, G_INBUF_SIZE); |
| 48 | uint32_t generation; | ||
| 48 | 49 | ||
| 49 | if (byte_count == 0 || (byte_count == -1 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)) { | 50 | if (byte_count == 0 || (byte_count == -1 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)) { |
| 50 | http_close(sock); | 51 | http_close(sock); |
| @@ -75,6 +76,7 @@ void tcp_read(const int64_t sock, struct ot_workstruct *ws) { | |||
| 75 | return; | 76 | return; |
| 76 | } | 77 | } |
| 77 | 78 | ||
| 79 | generation = fdstate_generation((int)sock); | ||
| 78 | while ((ws->header_size = header_complete(cookie->request.data, (ssize_t)cookie->request.size))) { | 80 | while ((ws->header_size = header_complete(cookie->request.data, (ssize_t)cookie->request.size))) { |
| 79 | ws->request = cookie->request.data; | 81 | ws->request = cookie->request.data; |
| 80 | ws->request_size = (ssize_t)cookie->request.size; | 82 | ws->request_size = (ssize_t)cookie->request.size; |
| @@ -84,6 +86,11 @@ void tcp_read(const int64_t sock, struct ot_workstruct *ws) { | |||
| 84 | off it, so there is nothing here left to look at */ | 86 | off it, so there is nothing here left to look at */ |
| 85 | if (ws->handed_off) | 87 | if (ws->handed_off) |
| 86 | return; | 88 | return; |
| 89 | |||
| 90 | /* The handler may have closed the connection inline, for instance on a | ||
| 91 | write error, which frees the cookie this loop reads from */ | ||
| 92 | if (fdstate_generation((int)sock) != generation) | ||
| 93 | return; | ||
| 87 | #ifdef WANT_KEEPALIVE | 94 | #ifdef WANT_KEEPALIVE |
| 88 | if (!ws->keep_alive) | 95 | if (!ws->keep_alive) |
| 89 | #endif | 96 | #endif |
