URI: 
       Another hack for SO_LINGER in Linux. - geomyidae - A small C-based gopherd.
  HTML git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit 1908f14b2d4df2a0530fc4c7ca308220c89871c0
   DIR parent 2c95cfddd2b4d2aca43bdcad09cdadd3214a10c9
  HTML Author: Christoph Lohmann <20h@r-36.net>
       Date:   Sun, 18 Feb 2018 09:33:39 +0100
       
       Another hack for SO_LINGER in Linux.
       
       In case some connection stalled, wait 30 seconds until it is closed.
       DDoS is still possible, but that is not geomyidae's fault.
       
       Diffstat:
         M ind.c                               |      40 ++++++++++++++++++++++++++++----
       
       1 file changed, 36 insertions(+), 4 deletions(-)
       ---
   DIR diff --git a/ind.c b/ind.c
       @@ -57,12 +57,22 @@ filetype type[] = {
        int
        pendingbytes(int sock)
        {
       -        int pending;
       +        int pending, rval;
        
                pending = 0;
       +        rval = 0;
        #ifdef TIOCOUTQ
       -        ioctl(sock, TIOCOUTQ, &pending);
       +        rval = ioctl(sock, TIOCOUTQ, &pending);
       +#else
       +#ifdef SIOCOUTQ
       +        rval = ioctl(sock, SIOCOUTQ, &pending);
        #endif
       +#endif
       +
       +        if (rval != 0) {
       +                printf("rval = %d\n", rval);
       +                return 0;
       +        }
        
                return pending;
        }
       @@ -70,8 +80,30 @@ pendingbytes(int sock)
        void
        waitforpendingbytes(int sock)
        {
       -        while (pendingbytes(sock) > 0)
       -                usleep(10);
       +        int npending, opending, tries;
       +
       +        npending = opending = tries = 0;
       +
       +        /*
       +         * Wait until there is nothing pending or the connection stalled for
       +         * 30 seconds.
       +         */
       +        while ((npending = pendingbytes(sock)) > 0 && tries < 30000000) {
       +                if (opending != 0) {
       +                        if (opending != npending) {
       +                                tries = 0;
       +                        } else {
       +                                if (tries == 0) {
       +                                        tries = 1;
       +                                } else {
       +                                        tries += tries;
       +                                }
       +                        }
       +                }
       +                opending = npending;
       +
       +                usleep(tries);
       +        }
        }
        
        int