From 69653aafeb22298a72f13dd8db211f036e8be1a4 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 9 Jun 2022 11:00:11 +0200 Subject: [PATCH] beautify socket_read_line() somewhat - use more appropriate name for socket object - localize some variable declarations - denoise the code by using more local variables - don't pointlessly do stuff when we're failing anyway --- src/socket.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/socket.c b/src/socket.c index f6e3f7f..5132146 100644 --- a/src/socket.c +++ b/src/socket.c @@ -816,27 +816,27 @@ socket_read( conn_t *conn, char *buf, uint len ) } char * -socket_read_line( conn_t *b ) +socket_read_line( conn_t *conn ) { - char *p, *s; - uint n; - - s = b->buf + b->offset; - p = memchr( s + b->scanoff, '\n', b->bytes - b->scanoff ); + uint off = conn->offset; + uint cnt = conn->bytes; + char *s = conn->buf + off; + char *p = memchr( s + conn->scanoff, '\n', cnt - conn->scanoff ); if (!p) { - b->scanoff = b->bytes; - if (b->offset + b->bytes == sizeof(b->buf)) { - memmove( b->buf, b->buf + b->offset, b->bytes ); - b->offset = 0; - } - if (b->state == SCK_EOF) + if (conn->state == SCK_EOF) return (void *)~0; + conn->scanoff = cnt; + if (off + cnt == sizeof(conn->buf)) { + memmove( conn->buf, conn->buf + off, cnt ); + conn->offset = 0; + } return NULL; } - n = (uint)(p + 1 - s); - b->offset += n; - b->bytes -= n; - b->scanoff = 0; + uint n = (uint)(p + 1 - s); + cnt -= n; + conn->offset = off + n; + conn->bytes = cnt; + conn->scanoff = 0; if (p != s && p[-1] == '\r') p--; *p = 0;