geomyidae

A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log | Files | Refs | README | LICENSE

commit 89ed3ff980bfd8b1a6405be67565b1de3b393ac3
parent 41aaba3aa82bbe810c1008246b2b226e7395fe1e
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sun, 23 Jul 2023 14:23:26 +0200

Add lingerie to all socks.

* fix TLS connection shutdown

Diffstat:
Mind.c | 28++++++++++++++++++++++++++++
Mind.h | 1+
Mmain.c | 34+++-------------------------------
3 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/ind.c b/ind.c @@ -630,3 +630,31 @@ humantime(const time_t *clock) return buf; } +void +lingersock(int sock) +{ + struct linger lingerie; + int j; + + /* + * On close only wait for at maximum 60 seconds for all data to be + * transmitted before forcefully closing the connection. + */ + lingerie.l_onoff = 1; + lingerie.l_linger = 60; + setsockopt(sock, SOL_SOCKET, SO_LINGER, + &lingerie, sizeof(lingerie)); + + /* + * Force explicit flush of buffers using TCP_NODELAY. + */ + j = 1; + setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &j, sizeof(int)); + waitforpendingbytes(sock); + j = 0; + setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &j, sizeof(int)); + shutdown(sock, SHUT_RDWR); + + return; +} + diff --git a/ind.h b/ind.h @@ -54,6 +54,7 @@ void setcgienviron(char *file, char *path, char *port, char *base, char *bhost, int istls, char *sel, char *traverse); char *humansize(off_t n); char *humantime(const time_t *clock); +void lingersock(int sock); #endif diff --git a/main.c b/main.c @@ -589,7 +589,6 @@ main(int argc, char *argv[]) { struct addrinfo hints; struct sockaddr_storage clt, slt; - struct linger lingerie; socklen_t cltlen, sltlen; int sock, dofork = 1, inetf = AF_UNSPEC, usechroot = 0, nocgi = 0, errno_save, nbindips = 0, i, j, @@ -1147,15 +1146,11 @@ read_selector_again: tls_free(tlsclientctx); } + lingersock(tlssocks[tlsclientreader? 0 : 1]); close(tlssocks[tlsclientreader? 0 : 1]); if (tlsclientreader) { - /* - * Only one process needs - * to do this. - */ - waitforpendingbytes(sock); - shutdown(sock, SHUT_RDWR); + lingersock(sock); close(sock); } return 0; @@ -1169,30 +1164,7 @@ read_selector_again: clienth, clientp, serverh, serverp, nocgi, istls); - if (!istls) { - /* - * On close only wait for at maximum 60 - * seconds for all data to be transmitted - * before forcefully closing the - * connection. - */ - lingerie.l_onoff = 1; - lingerie.l_linger = 60; - setsockopt(sock, SOL_SOCKET, SO_LINGER, - &lingerie, sizeof(lingerie)); - /* - * Force explict flush of buffers using - * TCP_NODELAY. - */ - j = 1; - setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, - &j, sizeof(int)); - waitforpendingbytes(sock); - j = 0; - setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, - &j, sizeof(int)); - shutdown(sock, SHUT_RDWR); - } + lingersock(sock); close(sock); if (loglvl & CONN) {