moonbridge
diff moonbridge_io.c @ 92:111b2469b753
Always re-fill immediate send buffer in write_nb method
author | jbe |
---|---|
date | Tue Apr 07 04:07:37 2015 +0200 (2015-04-07) |
parents | 6b26783f9323 |
children | de3982f17d05 |
line diff
1.1 --- a/moonbridge_io.c Tue Apr 07 03:50:28 2015 +0200 1.2 +++ b/moonbridge_io.c Tue Apr 07 04:07:37 2015 +0200 1.3 @@ -178,7 +178,7 @@ 1.4 moonbr_io_handle_t *handle; 1.5 int i, top; 1.6 const char *str; 1.7 - size_t strlen, strpos; 1.8 + size_t strlen; 1.9 size_t written; 1.10 ssize_t result; 1.11 handle = luaL_checkudata(L, 1, MOONBR_IO_HANDLE_MT_REGKEY); 1.12 @@ -202,16 +202,15 @@ 1.13 while (handle->writeqout != handle->writeqin) { 1.14 lua_rawgeti(L, -1, handle->writeqout); 1.15 str = lua_tolstring(L, -1, &strlen); 1.16 - strpos = handle->writeqoff; 1.17 - while (strpos < strlen) { 1.18 - if (strlen - strpos < MOONBR_IO_WRITEBUFLEN - handle->writebufcnt) { 1.19 - memcpy(handle->writebuf + handle->writebufcnt, str + strpos, strlen - strpos); 1.20 - handle->writebufcnt += strlen - strpos; 1.21 + while (handle->writeqoff < strlen) { 1.22 + if (strlen - handle->writeqoff < MOONBR_IO_WRITEBUFLEN - handle->writebufcnt) { 1.23 + memcpy(handle->writebuf + handle->writebufcnt, str + handle->writeqoff, strlen - handle->writeqoff); 1.24 + handle->writebufcnt += strlen - handle->writeqoff; 1.25 break; 1.26 } else { 1.27 written = 0; 1.28 - memcpy(handle->writebuf + handle->writebufcnt, str + strpos, MOONBR_IO_WRITEBUFLEN - handle->writebufcnt); 1.29 - strpos += MOONBR_IO_WRITEBUFLEN - handle->writebufcnt; 1.30 + memcpy(handle->writebuf + handle->writebufcnt, str + handle->writeqoff, MOONBR_IO_WRITEBUFLEN - handle->writebufcnt); 1.31 + handle->writeqoff += MOONBR_IO_WRITEBUFLEN - handle->writebufcnt; 1.32 while (written < MOONBR_IO_WRITEBUFLEN) { 1.33 result = write(handle->fd, handle->writebuf + written, MOONBR_IO_WRITEBUFLEN - written); 1.34 if (result < 0) { 1.35 @@ -219,8 +218,8 @@ 1.36 if (written) { 1.37 handle->writebufcnt -= written; 1.38 memmove(handle->writebuf, handle->writebuf + written, handle->writebufcnt); 1.39 + goto moonbr_io_write_impl_continue; 1.40 } 1.41 - handle->writeqoff = strpos; 1.42 goto moonbr_io_write_impl_block; 1.43 } else if (errno != EINTR) { 1.44 moonbr_io_errmsg(); 1.45 @@ -229,13 +228,13 @@ 1.46 lua_pushstring(L, errmsg); 1.47 return 2; 1.48 } 1.49 - } else { 1.50 - written += result; 1.51 - handle->writeleft -= result; 1.52 } 1.53 + written += result; 1.54 + handle->writeleft -= result; 1.55 } 1.56 handle->writebufcnt = 0; 1.57 } 1.58 + moonbr_io_write_impl_continue:; 1.59 } 1.60 handle->writeqoff = 0; 1.61 lua_pop(L, 1);