diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2026-07-19 16:05:56 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2026-07-19 16:05:56 +0300 |
| commit | cf74e8d7279606f8bc1dfaa8f3a7266b5fb9e900 (patch) | |
| tree | b4197b31d6fd26b10bbc3ad425a423fa7235057b | |
| parent | a2924e66d09c1f45892859f0f1810319d67df7a2 (diff) | |
| download | lark-cf74e8d7279606f8bc1dfaa8f3a7266b5fb9e900.tar.gz lark-cf74e8d7279606f8bc1dfaa8f3a7266b5fb9e900.zip | |
simplify xread/xwrite
| -rw-r--r-- | src/server.c | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/src/server.c b/src/server.c index e49cea9..468c4d6 100644 --- a/src/server.c +++ b/src/server.c @@ -34,11 +34,8 @@ struct server_ctx { /* buf is sized by count */ static ssize_t readx(int fd, void *buf, size_t count) { - /* total read */ - size_t t = 0; - while (1) { - ssize_t r = read(fd, buf + t, count - t); + ssize_t r = read(fd, buf, count); if (r == -1) { if (errno == EINTR) /* read interrupted, try again */ @@ -46,28 +43,21 @@ static ssize_t readx(int fd, void *buf, size_t count) if (errno == EWOULDBLOCK) /* no more data to read for now */ - return t; - - /* otherwise some unknown error, return it */ - return r; + return 0; } /* we've read as many bytes as are currently available */ - t += r; - return t; + return r; } /* should never be reached, but keep here to avoid warnings */ - return t; + return 0; } static ssize_t writex(int fd, void *buf, size_t count) { - /* total written */ - size_t t = 0; - while (1) { - ssize_t r = write(fd, buf + t, count - t); + ssize_t r = write(fd, buf, count); if (r == -1) { if (errno == EINTR) /* write interrupted, try again */ @@ -75,21 +65,14 @@ static ssize_t writex(int fd, void *buf, size_t count) if (errno == EWOULDBLOCK) /* no more data to read for now */ - return t; - - /* otherwise some unknown error, return it */ - return r; + return 0; } - t += r; - - /* we've written the full buffer, quit */ - if (t == count) - return t; + return r; } /* should never be reached, but keep here to avoid warnings */ - return t; + return 0; } static int new_connection(struct server_ctx *ctx, int new_conn_fd) |
