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.
This commit is contained in:
oni-link 2015-05-20 08:06:53 -03:00 committed by Thiago de Arruda
parent 4f5b250d4e
commit dcaf9c6bc3

View File

@ -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); RStream *rstream = handle_get_rstream((uv_handle_t *)stream);
if (cnt <= 0) { if (cnt <= 0) {
if (cnt != UV_ENOBUFS) { if (cnt != UV_ENOBUFS
DLOG("Closing RStream(%p)", rstream); // 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 // Read error or EOF, either way stop the stream and invoke the callback
// with eof == true // with eof == true
uv_read_stop(stream); uv_read_stop(stream);