-
-
Save indutny/1d6fcf3da45540e160ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/include/uv.h b/include/uv.h | |
index d6485e5..d1da997 100644 | |
--- a/include/uv.h | |
+++ b/include/uv.h | |
@@ -681,7 +681,9 @@ UV_EXTERN int uv_write2(uv_write_t* req, | |
* - zero - if queued write is needed | |
* - negative error code | |
*/ | |
-UV_EXTERN int uv_try_write(uv_stream_t* handle, const char* buf, size_t length); | |
+UV_EXTERN int uv_try_write(uv_stream_t* handle, | |
+ const uv_buf_t bufs[], | |
+ unsigned int nbufs); | |
/* uv_write_t is a subclass of uv_req_t */ | |
struct uv_write_s { | |
diff --git a/src/unix/stream.c b/src/unix/stream.c | |
index afd2a05..a9d174a 100644 | |
--- a/src/unix/stream.c | |
+++ b/src/unix/stream.c | |
@@ -1305,13 +1305,15 @@ void uv_try_write_cb(uv_write_t* req, int status) { | |
} | |
-int uv_try_write(uv_stream_t* stream, const char* buf, size_t size) { | |
+int uv_try_write(uv_stream_t* stream, | |
+ const uv_buf_t bufs[], | |
+ unsigned int nbufs) { | |
int r; | |
int has_pollout; | |
+ unsigned int i; | |
size_t written; | |
size_t req_size; | |
uv_write_t req; | |
- uv_buf_t bufstruct; | |
/* Connecting or already writing some data */ | |
if (stream->connect_req != NULL || stream->write_queue_size != 0) | |
@@ -1319,13 +1321,14 @@ int uv_try_write(uv_stream_t* stream, const char* buf, size_t size) { | |
has_pollout = uv__io_active(&stream->io_watcher, UV__POLLOUT); | |
- bufstruct = uv_buf_init((char*) buf, size); | |
- r = uv_write(&req, stream, &bufstruct, 1, uv_try_write_cb); | |
+ r = uv_write(&req, stream, bufs, nbufs, uv_try_write_cb); | |
if (r != 0) | |
return r; | |
/* Remove not written bytes from write queue size */ | |
- written = size; | |
+ written = 0; | |
+ for (i = 0; i < nbufs; i++) | |
+ written += bufs[i].len; | |
if (req.bufs != NULL) | |
req_size = uv__write_req_size(&req); | |
else | |
diff --git a/src/win/stream.c b/src/win/stream.c | |
index da62883..0bd261a 100644 | |
--- a/src/win/stream.c | |
+++ b/src/win/stream.c | |
@@ -202,7 +202,9 @@ int uv_write2(uv_write_t* req, | |
} | |
-int uv_try_write(uv_stream_t* handle, const char* buf, size_t length) { | |
+int uv_try_write(uv_stream_t* handle, | |
+ const uv_buf_t bufs[], | |
+ unsigned int nbufs) { | |
/* NOTE: Won't work with overlapped writes */ | |
return UV_ENOSYS; | |
} | |
diff --git a/test/test-tcp-try-write.c b/test/test-tcp-try-write.c | |
index 3fd6166..f4f4fb5 100644 | |
--- a/test/test-tcp-try-write.c | |
+++ b/test/test-tcp-try-write.c | |
@@ -61,7 +61,8 @@ static void connect_cb(uv_connect_t* req, int status) { | |
connect_cb_called++; | |
do { | |
- r = uv_try_write((uv_stream_t*) &client, zeroes, sizeof(zeroes)); | |
+ buf = uv_buf_init(zeroes, sizeof(zeroes)); | |
+ r = uv_try_write((uv_stream_t*) &client, &buf, 1); | |
ASSERT(r >= 0); | |
bytes_written += r; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use uv_count_bufs here https://gist.github.com/indutny/1d6fcf3da45540e160ea#file-1-diff-L51