| Set SO_LINGER, flush using TCP_NODELAY and fix wait overflow. - geomyidae - A s… | |
| git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri… | |
| Log | |
| Files | |
| Refs | |
| Tags | |
| README | |
| LICENSE | |
| --- | |
| commit c99b01b00b1c6d0740e92d9e77ab8e0daa96c4bf | |
| parent 1375ce4688358eca4db5bd1f0309863a574d250e | |
| Author: Christoph Lohmann <[email protected]> | |
| Date: Wed, 22 Jul 2020 14:41:10 +0200 | |
| Set SO_LINGER, flush using TCP_NODELAY and fix wait overflow. | |
| Diffstat: | |
| M ind.c | 3 ++- | |
| M main.c | 17 ++++++++++++++++- | |
| 2 files changed, 18 insertions(+), 2 deletions(-) | |
| --- | |
| diff --git a/ind.c b/ind.c | |
| @@ -79,7 +79,8 @@ pendingbytes(int sock) | |
| void | |
| waitforpendingbytes(int sock) | |
| { | |
| - int npending = 0, opending = 0, trytime = 10; | |
| + int npending = 0, opending = 0; | |
| + useconds_t trytime = 10; | |
| /* | |
| * Wait until there is nothing pending or the connection stalled | |
| diff --git a/main.c b/main.c | |
| @@ -15,6 +15,7 @@ | |
| #include <sys/stat.h> | |
| #include <sys/wait.h> | |
| #include <sys/types.h> | |
| +#include <netinet/tcp.h> | |
| #include <signal.h> | |
| #include <string.h> | |
| #include <strings.h> | |
| @@ -416,6 +417,7 @@ main(int argc, char *argv[]) | |
| { | |
| struct addrinfo hints; | |
| struct sockaddr_storage clt; | |
| + struct linger lingerie; | |
| socklen_t cltlen; | |
| int sock, dofork = 1, inetf = AF_UNSPEC, usechroot = 0, | |
| nocgi = 0, errno_save, nbindips = 0, i, j, | |
| @@ -867,9 +869,22 @@ main(int argc, char *argv[]) | |
| clientp, nocgi, istls); | |
| if (!istls) { | |
| + 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); | |
| - close(sock); | |
| } | |
| close(sock); | |