@@ -1408,6 +1408,32 @@ impl UnixDatagram {
1408
1408
self . 0 . write ( buf)
1409
1409
}
1410
1410
1411
+ /// Like `send`, except that it sends from a slice of buffers.
1412
+ ///
1413
+ /// The peer address may be set by the `connect` method, and this method
1414
+ /// will return an error if the socket has not already been connected.
1415
+ ///
1416
+ /// On success, returns the number of bytes written.
1417
+ ///
1418
+ /// # Examples
1419
+ ///
1420
+ /// ```no_run
1421
+ /// use std::os::unix::net::UnixDatagram;
1422
+ /// use std::io::IoSlice;
1423
+ ///
1424
+ /// fn main() -> std::io::Result<()> {
1425
+ /// let sock = UnixDatagram::unbound()?;
1426
+ /// sock.connect("/some/sock").expect("Couldn't connect");
1427
+ /// let bufs = [IoSlice::new(b" "), IoSlice::new(b"hello world")];
1428
+ /// sock.send_vectored(&bufs).expect("send_vectored function failed");
1429
+ /// Ok(())
1430
+ /// }
1431
+ /// ```
1432
+ #[ unstable( feature = "unix_socket_send_vectored" , issue = "68612" ) ]
1433
+ pub fn send_vectored ( & self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
1434
+ self . 0 . write_vectored ( bufs)
1435
+ }
1436
+
1411
1437
/// Sets the read timeout for the socket.
1412
1438
///
1413
1439
/// If the provided value is [`None`], then [`recv`] and [`recv_from`] calls will
@@ -1941,6 +1967,30 @@ mod test {
1941
1967
or_panic ! ( bsock2. recv_from( & mut buf) ) ;
1942
1968
}
1943
1969
1970
+ #[ test]
1971
+ fn test_unix_datagram_send_vectored ( ) {
1972
+ let dir = tmpdir ( ) ;
1973
+ let path1 = dir. path ( ) . join ( "sock1" ) ;
1974
+
1975
+ let sock1 = or_panic ! ( UnixDatagram :: bind( & path1) ) ;
1976
+ let sock2 = or_panic ! ( UnixDatagram :: unbound( ) ) ;
1977
+ or_panic ! ( sock2. connect( & path1) ) ;
1978
+
1979
+ let a = [ ] ;
1980
+ let b = [ 10 ] ;
1981
+ let c = [ 11 , 12 ] ;
1982
+ or_panic ! ( sock2. send_vectored( & [ IoSlice :: new( & a) , IoSlice :: new( & b) , IoSlice :: new( & c) ] ) ) ;
1983
+ let mut buf = [ 0 ; 4 ] ;
1984
+ let len = or_panic ! ( sock1. recv( & mut buf) ) ;
1985
+ // some implementations don't support writev, so we may only write the first buffer
1986
+ if len == 1 {
1987
+ assert_eq ! ( buf, [ 10 , 0 , 0 , 0 ] ) ;
1988
+ } else {
1989
+ assert_eq ! ( len, 3 ) ;
1990
+ assert_eq ! ( buf, [ 10 , 11 , 12 , 0 ] ) ;
1991
+ }
1992
+ }
1993
+
1944
1994
#[ test]
1945
1995
fn test_unix_datagram_recv ( ) {
1946
1996
let dir = tmpdir ( ) ;
0 commit comments