diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2023-12-13 19:49:12 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2023-12-13 19:49:12 +0100 |
commit | 4367c75afebaebcbf585fe03e3c07def9e0e9ae7 (patch) | |
tree | a8b5c28b550baac882568e1ab69b5c6ea61ef105 | |
parent | ecfc618edda1bfa08bc2de6fc15cf87c2903df4f (diff) |
Reformatted sendme()
-rw-r--r-- | FICS/network.c | 61 |
1 files changed, 35 insertions, 26 deletions
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; } /* |