summaryrefslogtreecommitdiff
path: root/src/tcp.c
diff options
context:
space:
mode:
authorDaniel Dressler <danieru.dressler@gmail.com>2014-07-24 13:01:21 -0600
committerDaniel Dressler <danieru.dressler@gmail.com>2014-07-24 13:01:21 -0600
commitdcd46f5eb4e73d548dbdc7b297df3c7cac5fd8c9 (patch)
treedaff147d76eb1049ff4e0fae38dfc7a1a35c4312 /src/tcp.c
parenteb0bed7aba8bf67c578a5c553b2414762c227971 (diff)
Fix staling main loop if alloc fails in TCP
Diffstat (limited to 'src/tcp.c')
-rw-r--r--src/tcp.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/tcp.c b/src/tcp.c
index 4c316c8..5abe60b 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -93,12 +93,13 @@ struct http_packet_t *tcp_packet_get(struct tcp_conn_t *tcp,
struct http_packet_t *pkt = packet_new(msg);
if (pkt == NULL) {
ERR("failed to create packet for incoming tcp message");
- goto cleanup;
+ goto error;
}
+ // TODO: fix when packet was pre-filled by msg buffer
size_t want_size = packet_pending_bytes(pkt);
if (want_size == 0)
- goto cleanup;
+ goto error;
while (want_size != 0 && !msg->is_completed) {
NOTE("TCP: Getting %d bytes", want_size);
@@ -108,14 +109,14 @@ struct http_packet_t *tcp_packet_get(struct tcp_conn_t *tcp,
int errno_saved = errno;
ERR("recv failed with err %d:%s", errno_saved,
strerror(errno_saved));
- goto cleanup;
+ goto error;
}
NOTE("TCP: Got %d bytes", gotten_size);
if (gotten_size == 0) {
tcp->is_closed = 1;
if (pkt->filled_size == 0) {
// Client closed TCP conn
- goto cleanup;
+ goto error;
} else {
break;
}
@@ -128,7 +129,7 @@ struct http_packet_t *tcp_packet_get(struct tcp_conn_t *tcp,
NOTE("TCP: Received %lu bytes", pkt->filled_size);
return pkt;
-cleanup:
+error:
if (pkt != NULL)
packet_free(pkt);
return NULL;