Skip to content

Commit 4a10a9c

Browse files
Add writev to TcpStream (tokio-rs#136)
* Add writev to TcpStream Co-authored-by: FrankReh <[email protected]>
1 parent ecaaa3e commit 4a10a9c

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/driver/socket.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ impl Socket {
4444
op.await
4545
}
4646

47+
pub async fn writev<T: IoBuf>(&self, buf: Vec<T>) -> crate::BufResult<usize, Vec<T>> {
48+
let op = Op::writev_at(&self.fd, buf, 0).unwrap();
49+
op.await
50+
}
51+
4752
pub(crate) async fn send_to<T: IoBuf>(
4853
&self,
4954
buf: T,

src/net/tcp/stream.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,34 @@ impl TcpStream {
164164
(Ok(()), buf)
165165
}
166166

167+
/// Write data from buffers into this socket returning how many bytes were
168+
/// written.
169+
///
170+
/// This function will attempt to write the entire contents of `bufs`, but
171+
/// the entire write may not succeed, or the write may also generate an
172+
/// error. The bytes will be written starting at the specified offset.
173+
///
174+
/// # Return
175+
///
176+
/// The method returns the operation result and the same array of buffers
177+
/// passed in as an argument. A return value of `0` typically means that the
178+
/// underlying socket is no longer able to accept bytes and will likely not
179+
/// be able to in the future as well, or that the buffer provided is empty.
180+
///
181+
/// # Errors
182+
///
183+
/// Each call to `write` may generate an I/O error indicating that the
184+
/// operation could not be completed. If an error is returned then no bytes
185+
/// in the buffer were written to this writer.
186+
///
187+
/// It is **not** considered an error if the entire buffer could not be
188+
/// written to this writer.
189+
///
190+
/// [`Ok(n)`]: Ok
191+
pub async fn writev<T: IoBuf>(&self, buf: Vec<T>) -> crate::BufResult<usize, Vec<T>> {
192+
self.inner.writev(buf).await
193+
}
194+
167195
/// Shuts down the read, write, or both halves of this connection.
168196
///
169197
/// This function will cause all pending and future I/O on the specified portions to return

src/net/unix/stream.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,34 @@ impl UnixStream {
130130
(Ok(()), buf)
131131
}
132132

133+
/// Write data from buffers into this socket returning how many bytes were
134+
/// written.
135+
///
136+
/// This function will attempt to write the entire contents of `bufs`, but
137+
/// the entire write may not succeed, or the write may also generate an
138+
/// error. The bytes will be written starting at the specified offset.
139+
///
140+
/// # Return
141+
///
142+
/// The method returns the operation result and the same array of buffers
143+
/// passed in as an argument. A return value of `0` typically means that the
144+
/// underlying socket is no longer able to accept bytes and will likely not
145+
/// be able to in the future as well, or that the buffer provided is empty.
146+
///
147+
/// # Errors
148+
///
149+
/// Each call to `write` may generate an I/O error indicating that the
150+
/// operation could not be completed. If an error is returned then no bytes
151+
/// in the buffer were written to this writer.
152+
///
153+
/// It is **not** considered an error if the entire buffer could not be
154+
/// written to this writer.
155+
///
156+
/// [`Ok(n)`]: Ok
157+
pub async fn writev<T: IoBuf>(&self, buf: Vec<T>) -> crate::BufResult<usize, Vec<T>> {
158+
self.inner.writev(buf).await
159+
}
160+
133161
/// Shuts down the read, write, or both halves of this connection.
134162
///
135163
/// This function will cause all pending and future I/O on the specified portions to return

0 commit comments

Comments
 (0)