From 7253890eaed0b43f306ec5f85015954fdaedda53 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Wed, 13 Dec 2023 20:00:33 +0100 Subject: Reformatted net_flushme() --- FICS/network.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'FICS/network.c') diff --git a/FICS/network.c b/FICS/network.c index be8a8ae..65e34f6 100644 --- a/FICS/network.c +++ b/FICS/network.c @@ -113,25 +113,36 @@ PRIVATE int remConnection(int fd) return 0; } -PRIVATE void net_flushme(int which) +PRIVATE void +net_flushme(int which) { - int sent; + int sent; + + if ((sent = send(con[which].outFd, con[which].sndbuf, + con[which].sndbufpos, 0)) == -1) { + if (errno != EPIPE) { // EPIPE = they've disconnected + fprintf(stderr, "FICS: net_flushme(%d) couldn't send, " + "errno=%d.\n", + which, errno); + } - sent = send(con[which].outFd, con[which].sndbuf, con[which].sndbufpos, 0); - if (sent == -1) { - if (errno != EPIPE) /* EPIPE = they've disconnected */ - fprintf(stderr, "FICS: net_flushme(%d) couldn't send, errno=%d.\n", which, errno); - con[which].sndbufpos = 0; - } else { - con[which].sndbufpos -= sent; - if (con[which].sndbufpos) - memmove(con[which].sndbuf, con[which].sndbuf + sent, con[which].sndbufpos); - } - if (con[which].sndbufsize > MAX_STRING_LENGTH && con[which].sndbufpos < MAX_STRING_LENGTH) { - /* time to shrink the buffer */ - con[which].sndbuf = rrealloc(con[which].sndbuf, MAX_STRING_LENGTH); - con[which].sndbufsize = MAX_STRING_LENGTH; - } + con[which].sndbufpos = 0; + } else { + con[which].sndbufpos -= sent; + + if (con[which].sndbufpos) { + memmove(con[which].sndbuf, con[which].sndbuf + sent, + con[which].sndbufpos); + } + } + + if (con[which].sndbufsize > MAX_STRING_LENGTH && + con[which].sndbufpos < MAX_STRING_LENGTH) { + // time to shrink the buffer... + con[which].sndbuf = rrealloc(con[which].sndbuf, + MAX_STRING_LENGTH); + con[which].sndbufsize = MAX_STRING_LENGTH; + } } PRIVATE void -- cgit v1.2.3