| Date: Wed, 22 Jul 2020 14:41:10 +0200
Set SO_LINGER, flush using TCP_NODELAY and fix wait overflow.
Diffstat:
ind.c | 3 ++-
main.c | 17 ++++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
--- |
| t@@ -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 |
| t@@ -15,6 +15,7 @@
#include
#include
#include
+#include
#include
#include
#include
t@@ -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,
t@@ -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);
|