From 4367c75afebaebcbf585fe03e3c07def9e0e9ae7 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Wed, 13 Dec 2023 19:49:12 +0100 Subject: Reformatted sendme() --- FICS/network.c | 61 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 26 deletions(-) (limited to 'FICS') diff --git a/FICS/network.c b/FICS/network.c index ac5a509..592a977 100644 --- a/FICS/network.c +++ b/FICS/network.c @@ -174,35 +174,44 @@ PRIVATE void net_flush_connection(int fd) return; } -PRIVATE int sendme(int which, char *str, int len) +PRIVATE int +sendme(int which, char *str, int len) { - int i, count; - fd_set writefds; - struct timeval to; - count = len; + fd_set writefds; + int i, count; + struct timeval to; - while ((i = ((con[which].sndbufsize - con[which].sndbufpos) < len) ? (con[which].sndbufsize - con[which].sndbufpos) : len) > 0) { - memmove(con[which].sndbuf + con[which].sndbufpos, str, i); - con[which].sndbufpos += i; - if (con[which].sndbufpos == con[which].sndbufsize) { + count = len; - FD_ZERO(&writefds); - FD_SET(con[which].outFd, &writefds); - to.tv_usec = 0; - to.tv_sec = 0; - select(no_file, NULL, &writefds, NULL, &to); - if (FD_ISSET(con[which].outFd, &writefds)) { - net_flushme(which); - } else { - /* time to grow the buffer */ - con[which].sndbufsize += MAX_STRING_LENGTH; - con[which].sndbuf = rrealloc(con[which].sndbuf, con[which].sndbufsize); - } - } - str += i; - len -= i; - } - return count; + while ((i = ((con[which].sndbufsize - con[which].sndbufpos) < len) ? + (con[which].sndbufsize - con[which].sndbufpos) : len) > 0) { + memmove(con[which].sndbuf + con[which].sndbufpos, str, i); + con[which].sndbufpos += i; + + if (con[which].sndbufpos == con[which].sndbufsize) { + FD_ZERO(&writefds); + FD_SET(con[which].outFd, &writefds); + + to.tv_usec = 0; + to.tv_sec = 0; + + select(no_file, NULL, &writefds, NULL, &to); + + if (FD_ISSET(con[which].outFd, &writefds)) { + net_flushme(which); + } else { + // time to grow the buffer + con[which].sndbufsize += MAX_STRING_LENGTH; + con[which].sndbuf = rrealloc(con[which].sndbuf, + con[which].sndbufsize); + } + } + + str += i; + len -= i; + } + + return count; } /* -- cgit v1.2.3