Ejemplo n.º 1
0
int async_read(uv_stream_t *const stream, size_t const size, uv_buf_t *const out) {
	if(!stream) return UV_EINVAL;
	if(!out) return UV_EINVAL;
	async_state state[1];
	state->thread = async_active();
	state->size = size;
	state->status = 0;
	*state->buf = uv_buf_init(NULL, 0);
	stream->data = state;
	int rc = uv_read_start(stream, alloc_cb, read_cb);
	if(rc < 0) return rc;
	rc = async_yield_cancelable();
	uv_read_stop(stream);
	if(rc < 0) {
		free(state->buf->base);
		return rc;
	}
	out->base = state->buf->base;
	out->len = state->buf->len;
	return state->status;
}
Ejemplo n.º 2
0
int async_yield_flags(unsigned const flags) {
	if(ASYNC_CANCELABLE & flags) return async_yield_cancelable();
	async_yield();
	return 0;
}