diff options
author | oni-link <knil.ino@gmail.com> | 2015-05-20 08:06:53 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-07-01 05:40:53 -0300 |
commit | dcaf9c6bc3d5f83782fca7a145ba5feac7746b1e (patch) | |
tree | 5135fa805c0ff67cb2dbb66509d1dbaf5206cf3f | |
parent | 4f5b250d4effc276157cca9b8224f9e9ca25b33c (diff) | |
download | rneovim-dcaf9c6bc3d5f83782fca7a145ba5feac7746b1e.tar.gz rneovim-dcaf9c6bc3d5f83782fca7a145ba5feac7746b1e.tar.bz2 rneovim-dcaf9c6bc3d5f83782fca7a145ba5feac7746b1e.zip |
rstream: Fix bug triggered when libuv doesn't use the allocated buffer
Libuv will return 0 to signal that the buffer allocated by `alloc_cb` wasn't
used, and in this case the read_cb should simply be ignored.
-rw-r--r-- | src/nvim/os/rstream.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index 702f282d53..a99745f068 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -338,8 +338,16 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) RStream *rstream = handle_get_rstream((uv_handle_t *)stream); if (cnt <= 0) { - if (cnt != UV_ENOBUFS) { - DLOG("Closing RStream(%p)", rstream); + if (cnt != UV_ENOBUFS + // cnt == 0 means libuv asked for a buffer and decided it wasn't needed: + // http://docs.libuv.org/en/latest/stream.html#c.uv_read_start. + // + // We don't need to do anything with the RBuffer because the next call + // to `alloc_cb` will return the same unused pointer(`rbuffer_produced` + // won't be called) + && cnt != 0) { + DLOG("Closing RStream(%p) because of %s(%zd)", rstream, + uv_strerror((int)cnt), cnt); // Read error or EOF, either way stop the stream and invoke the callback // with eof == true uv_read_stop(stream); |