make net_read() and net_write() more sane.

This commit is contained in:
Joris Vink 2018-07-05 12:36:47 +00:00
parent 47c1a1d195
commit 4f16a5d272
1 changed files with 8 additions and 2 deletions

View File

@ -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);