// Callback invoked by libuv after it copies the data into the buffer provided // by `alloc_cb`. This is also called on EOF or when `alloc_cb` returns a // 0-length buffer. 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); // Read error or EOF, either way stop the stream and invoke the callback // with eof == true uv_read_stop(stream); rstream->cb(rstream, rstream->data, true); } return; } // at this point we're sure that cnt is positive, no error occurred size_t nread = (size_t) cnt; // Data was already written, so all we need is to update 'wpos' to reflect // the space actually used in the buffer. rbuffer_produced(rstream->buffer, nread); rstream->cb(rstream, rstream->data, false); }
void rstream_read_event(Event event) { RStream *rstream = event.data.rstream.ptr; rstream->cb(rstream, rstream->data, event.data.rstream.eof); }