moonbridge

changeset 133:891cdc4b43eb

Revised flushing behavior of write_nb(...) again
author jbe
date Thu Apr 16 20:48:11 2015 +0200 (2015-04-16)
parents 293e666a41e0
children 11269ec33cd7
files moonbridge_io.c
line diff
     1.1 --- a/moonbridge_io.c	Thu Apr 16 04:24:21 2015 +0200
     1.2 +++ b/moonbridge_io.c	Thu Apr 16 20:48:11 2015 +0200
     1.3 @@ -108,7 +108,7 @@
     1.4    }
     1.5  }
     1.6  
     1.7 -static void moonbr_io_handle_set_nopush(lua_State *L, moonbr_io_handle_t *handle, int nopush) {
     1.8 +static inline void moonbr_io_handle_set_nopush(lua_State *L, moonbr_io_handle_t *handle, int nopush) {
     1.9  #if defined(TCP_NOPUSH) || defined(TCP_CORK)
    1.10    if (
    1.11      !(handle->addrfam == AF_INET6 || handle->addrfam == AF_INET) ||
    1.12 @@ -289,7 +289,6 @@
    1.13      handle->writeleft += strlen;
    1.14    }
    1.15    if (flush) handle->flushedleft = handle->writeleft;
    1.16 -  if (handle->flushedleft) moonbr_io_handle_set_nopush(L, handle, 0);
    1.17    while (handle->writeqout != handle->writeqin) {
    1.18      lua_rawgeti(L, -1, handle->writeqout);
    1.19      str = lua_tolstring(L, -1, &strlen);
    1.20 @@ -313,7 +312,7 @@
    1.21          );
    1.22          handle->writeqoff += MOONBR_IO_WRITEBUFLEN - handle->writebufin;
    1.23          while (handle->writebufout < MOONBR_IO_WRITEBUFLEN) {
    1.24 -          if (!handle->flushedleft) moonbr_io_handle_set_nopush(L, handle, 1);
    1.25 +          moonbr_io_handle_set_nopush(L, handle, 1);
    1.26            written = write(
    1.27              handle->fd,
    1.28              handle->writebuf + handle->writebufout,
    1.29 @@ -331,8 +330,14 @@
    1.30            } else {
    1.31              handle->writebufout += written;
    1.32              handle->writeleft -= written;
    1.33 -            if (written >= handle->flushedleft) handle->flushedleft = 0;
    1.34 -            else handle->flushedleft -= written;
    1.35 +            if (handle->flushedleft) {
    1.36 +              if (written >= handle->flushedleft) {
    1.37 +                handle->flushedleft = 0;
    1.38 +                moonbr_io_handle_set_nopush(L, handle, 0);
    1.39 +              } else {
    1.40 +                handle->flushedleft -= written;
    1.41 +              }
    1.42 +            }
    1.43            }
    1.44          }
    1.45          handle->writebufin = 0;
    1.46 @@ -345,6 +350,7 @@
    1.47      lua_rawseti(L, -2, handle->writeqout++);
    1.48    }
    1.49    while (handle->flushedleft) {
    1.50 +    moonbr_io_handle_set_nopush(L, handle, 1);
    1.51      written = write(
    1.52        handle->fd,
    1.53        handle->writebuf + handle->writebufout,
    1.54 @@ -362,8 +368,14 @@
    1.55      } else {
    1.56        handle->writebufout += written;
    1.57        handle->writeleft -= written;
    1.58 -      if (written >= handle->flushedleft) handle->flushedleft = 0;
    1.59 -      else handle->flushedleft -= written;
    1.60 +      if (handle->flushedleft) {
    1.61 +        if (written >= handle->flushedleft) {
    1.62 +          handle->flushedleft = 0;
    1.63 +          moonbr_io_handle_set_nopush(L, handle, 0);
    1.64 +        } else {
    1.65 +          handle->flushedleft -= written;
    1.66 +        }
    1.67 +      }
    1.68      }
    1.69    }
    1.70    if (handle->writebufout == handle->writebufin) {

Impressum / About Us