isync

mailbox synchronization program
git clone https://git.code.sf.net/p/isync/isync
Log | Files | Refs | README | LICENSE

commit 69653aafeb22298a72f13dd8db211f036e8be1a4
parent bc3145617a8b1aa2f5f7050e9ba757f837af7494
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date:   Thu,  9 Jun 2022 11:00:11 +0200

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

Diffstat:
Msrc/socket.c | 32++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)

diff --git 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;