mirror of
https://github.com/libuv/libuv
synced 2025-03-28 21:13:16 +00:00
stream: allow multiple buffers for uv_try_write
This commit is contained in:
parent
7f65a74f8e
commit
17d60e3f94
@ -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 {
|
||||
|
@ -1305,13 +1305,14 @@ 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;
|
||||
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 +1320,12 @@ 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 = uv_count_bufs(bufs, nbufs);
|
||||
if (req.bufs != NULL)
|
||||
req_size = uv__write_req_size(&req);
|
||||
else
|
||||
|
@ -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* stream,
|
||||
const uv_buf_t bufs[],
|
||||
unsigned int nbufs) {
|
||||
/* NOTE: Won't work with overlapped writes */
|
||||
return UV_ENOSYS;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user