kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 4f16a5d272c959bab7542cdc07a781907d194682
parent 47c1a1d195418047cb7ee35f60ae6c5b885e3c8f
Author: Joris Vink <joris@coders.se>
Date:   Thu,  5 Jul 2018 12:36:47 +0000

make net_read() and net_write() more sane.

Diffstat:
src/net.c | 10++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/net.c b/src/net.c @@ -419,7 +419,7 @@ net_write(struct connection *c, size_t len, size_t *written) ssize_t r; r = write(c->fd, (c->snb->buf + c->snb->s_off), len); - if (r <= -1) { + if (r == -1) { switch (errno) { case EINTR: *written = 0; @@ -445,7 +445,7 @@ net_read(struct connection *c, size_t *bytes) r = read(c->fd, (c->rnb->buf + c->rnb->s_off), (c->rnb->b_len - c->rnb->s_off)); - if (r <= 0) { + if (r == -1) { switch (errno) { case EINTR: *bytes = 0; @@ -459,6 +459,12 @@ net_read(struct connection *c, size_t *bytes) } } + if (r == 0) { + kore_connection_disconnect(c); + c->flags &= ~CONN_READ_POSSIBLE; + return (KORE_RESULT_OK); + } + *bytes = (size_t)r; return (KORE_RESULT_OK);