Skip to content

Commit 1eedbaa

Browse files
committed
Add Socket::send_with_flags
1 parent a58c042 commit 1eedbaa

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

library/std/src/os/unix/net/stream.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,16 @@ use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_wi
3434
target_os = "cygwin"
3535
))]
3636
use super::{UCred, peer_cred};
37-
use crate::ffi::c_void;
37+
use crate::fmt;
3838
use crate::io::{self, IoSlice, IoSliceMut};
3939
use crate::net::Shutdown;
4040
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
4141
use crate::path::Path;
4242
use crate::sealed::Sealed;
4343
use crate::sys::cvt;
44-
use crate::sys::net::{Socket, wrlen_t};
44+
use crate::sys::net::Socket;
4545
use crate::sys_common::{AsInner, FromInner};
4646
use crate::time::Duration;
47-
use crate::{cmp, fmt};
4847

4948
/// A Unix stream socket.
5049
///
@@ -655,11 +654,7 @@ impl io::Write for UnixStream {
655654
#[stable(feature = "unix_socket", since = "1.10.0")]
656655
impl<'a> io::Write for &'a UnixStream {
657656
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
658-
let len = cmp::min(buf.len(), <wrlen_t>::MAX as usize) as wrlen_t;
659-
let ret = cvt(unsafe {
660-
libc::send(self.0.as_raw(), buf.as_ptr() as *const c_void, len, MSG_NOSIGNAL)
661-
})?;
662-
Ok(ret as usize)
657+
self.0.send_with_flags(buf, MSG_NOSIGNAL)
663658
}
664659

665660
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {

library/std/src/sys/net/connection/socket/unix.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ impl Socket {
281281
self.0.duplicate().map(Socket)
282282
}
283283

284+
pub fn send_with_flags(&self, buf: &[u8], flags: c_int) -> io::Result<usize> {
285+
let len = cmp::min(buf.len(), <wrlen_t>::MAX as usize) as wrlen_t;
286+
let ret = cvt(unsafe {
287+
libc::send(self.as_raw_fd(), buf.as_ptr() as *const c_void, len, flags)
288+
})?;
289+
Ok(ret as usize)
290+
}
291+
284292
fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Result<()> {
285293
let ret = cvt(unsafe {
286294
libc::recv(

0 commit comments

Comments
 (0)