win,tcp: support uv_try_write
PR: https://github.com/libuv/libuv/pull/127 Reviewed-by: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
e2f9b612c3
commit
9b8cef4428
@ -136,6 +136,8 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb,
|
||||
uv_read_cb read_cb);
|
||||
int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle,
|
||||
const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb);
|
||||
int uv__tcp_try_write(uv_tcp_t* handle, const uv_buf_t bufs[],
|
||||
unsigned int nbufs);
|
||||
|
||||
void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, uv_req_t* req);
|
||||
void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
|
||||
|
||||
@ -191,6 +191,7 @@ int uv_try_write(uv_stream_t* stream,
|
||||
|
||||
switch (stream->type) {
|
||||
case UV_TCP:
|
||||
return uv__tcp_try_write((uv_tcp_t*) stream, bufs, nbufs);
|
||||
case UV_TTY:
|
||||
case UV_NAMED_PIPE:
|
||||
return UV_EAGAIN;
|
||||
|
||||
@ -876,6 +876,30 @@ int uv_tcp_write(uv_loop_t* loop,
|
||||
}
|
||||
|
||||
|
||||
int uv__tcp_try_write(uv_tcp_t* handle,
|
||||
const uv_buf_t bufs[],
|
||||
unsigned int nbufs) {
|
||||
int result;
|
||||
DWORD bytes;
|
||||
|
||||
if (handle->write_reqs_pending > 0)
|
||||
return UV_EAGAIN;
|
||||
|
||||
result = WSASend(handle->socket,
|
||||
(WSABUF*) bufs,
|
||||
nbufs,
|
||||
&bytes,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if (result == SOCKET_ERROR)
|
||||
return uv_translate_sys_error(WSAGetLastError());
|
||||
else
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
|
||||
uv_req_t* req) {
|
||||
DWORD bytes, flags, err;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user