stream: introduce uv_try_write2 function
`uv_try_write2(stream, bufs, nbufs, send_handle)` acts like `uv_try_write()` and extended write function for sending handles over a pipe like `uv_write2`. It always returns `UV_EAGAIN` instead of `UV_ENOSYS` on Windows so we can easily write cross-platform code without special treatment. PR-URL: https://github.com/libuv/libuv/pull/3183 Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This commit is contained in:
parent
6085bcef8d
commit
bcc4f8fdde
@ -207,6 +207,16 @@ API
|
||||
* < 0: negative error code (``UV_EAGAIN`` is returned if no data can be sent
|
||||
immediately).
|
||||
|
||||
.. c:function:: int uv_try_write2(uv_stream_t* handle, const uv_buf_t bufs[], unsigned int nbufs, uv_stream_t* send_handle)
|
||||
|
||||
Same as :c:func:`uv_try_write` and extended write function for sending
|
||||
handles over a pipe like c:func:`uv_write2`.
|
||||
|
||||
Try to send a handle is not supported on Windows,
|
||||
where it returns ``UV_EAGAIN``.
|
||||
|
||||
.. versionadded:: 1.42.0
|
||||
|
||||
.. c:function:: int uv_is_readable(const uv_stream_t* handle)
|
||||
|
||||
Returns 1 if the stream is readable, 0 otherwise.
|
||||
|
||||
@ -528,6 +528,10 @@ UV_EXTERN int uv_write2(uv_write_t* req,
|
||||
UV_EXTERN int uv_try_write(uv_stream_t* handle,
|
||||
const uv_buf_t bufs[],
|
||||
unsigned int nbufs);
|
||||
UV_EXTERN int uv_try_write2(uv_stream_t* handle,
|
||||
const uv_buf_t bufs[],
|
||||
unsigned int nbufs,
|
||||
uv_stream_t* send_handle);
|
||||
|
||||
/* uv_write_t is a subclass of uv_req_t. */
|
||||
struct uv_write_s {
|
||||
|
||||
@ -1525,6 +1525,14 @@ int uv_write(uv_write_t* req,
|
||||
int uv_try_write(uv_stream_t* stream,
|
||||
const uv_buf_t bufs[],
|
||||
unsigned int nbufs) {
|
||||
return uv_try_write2(stream, bufs, nbufs, NULL);
|
||||
}
|
||||
|
||||
|
||||
int uv_try_write2(uv_stream_t* stream,
|
||||
const uv_buf_t bufs[],
|
||||
unsigned int nbufs,
|
||||
uv_stream_t* send_handle) {
|
||||
int err;
|
||||
|
||||
/* Connecting or already writing some data */
|
||||
@ -1535,7 +1543,7 @@ int uv_try_write(uv_stream_t* stream,
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return uv__try_write(stream, bufs, nbufs, NULL);
|
||||
return uv__try_write(stream, bufs, nbufs, send_handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -188,6 +188,16 @@ int uv_try_write(uv_stream_t* stream,
|
||||
}
|
||||
|
||||
|
||||
int uv_try_write2(uv_stream_t* stream,
|
||||
const uv_buf_t bufs[],
|
||||
unsigned int nbufs,
|
||||
uv_stream_t* send_handle) {
|
||||
if (send_handle != NULL)
|
||||
return UV_EAGAIN;
|
||||
return uv_try_write(stream, bufs, nbufs);
|
||||
}
|
||||
|
||||
|
||||
int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) {
|
||||
uv_loop_t* loop = handle->loop;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user