diff --git a/src/buffer.c b/src/buffer.c index 7148be34f6281f54bc3a661c5709e08c07d51f58..f6761ca3ef7de60840ed56fd677b3e5cda1c48a0 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -202,20 +202,32 @@ static int recvraw(p_buffer buf, size_t wanted, luaL_Buffer *b) { /*-------------------------------------------------------------------------*\ * Reads everything until the connection is closed (buffered) \*-------------------------------------------------------------------------*/ -static int recvall(p_buffer buf, luaL_Buffer *b) { +static int recvall(p_buffer buf, luaL_Buffer *b) +{ int err = IO_DONE; size_t total = 0; while (err == IO_DONE) { - const char *data; size_t count; + const char *data; + size_t count; err = buffer_get(buf, &data, &count); + //没有接收到数据,跳出循环 + if (count == 0) { + if (total > 0 && err == IO_TIMEOUT) { + return IO_DONE; + } + break; + } total += count; luaL_addlstring(b, data, count); buffer_skip(buf, count); } if (err == IO_CLOSED) { - if (total > 0) return IO_DONE; - else return IO_CLOSED; - } else return err; + if (total > 0) + return IO_DONE; + else + return IO_CLOSED; + } else + return err; } /*-------------------------------------------------------------------------*\