1818//! Virtio socket support for Rust.
1919
2020use libc:: {
21- accept, fcntl, ioctl, sa_family_t, sockaddr, sockaddr_vm, socklen_t, suseconds_t , timeval ,
22- AF_VSOCK , FD_CLOEXEC , FIONBIO , F_SETFD ,
21+ accept, fcntl, ioctl, sa_family_t, sockaddr, sockaddr_vm, socklen_t, timeval , AF_VSOCK ,
22+ FD_CLOEXEC , FIONBIO , F_SETFD ,
2323} ;
2424use nix:: {
2525 ioctl_read_bad,
26- sys:: socket:: {
27- self , bind, connect, getpeername, getsockname, listen, recv, recvfrom, send, sendto,
28- shutdown, socket,
29- sockopt:: { ReceiveTimeout , SendTimeout , SocketError } ,
30- AddressFamily , Backlog , GetSockOpt , MsgFlags , SetSockOpt , SockFlag , SockType ,
26+ sys:: {
27+ socket:: {
28+ self , bind, connect, getpeername, getsockname, listen, recv, recvfrom, send, sendto,
29+ shutdown, socket,
30+ sockopt:: { ReceiveTimeout , SendTimeout , SocketError } ,
31+ AddressFamily , Backlog , GetSockOpt , MsgFlags , SetSockOpt , SockFlag , SockType ,
32+ } ,
33+ time:: TimeVal ,
3134 } ,
3235 unistd:: close,
3336} ;
@@ -62,8 +65,8 @@ fn default_send_msg_flags() -> MsgFlags {
6265 flags
6366}
6467
65- /// Internal helper to turn a [`Duration`] into a [`timeval`]
66- fn timeval_from_duration ( dur : Option < Duration > ) -> Result < timeval > {
68+ /// Internal helper to turn a [`Duration`] into a [`TimeVal`].
69+ fn timeval_from_duration ( dur : Option < Duration > ) -> Result < TimeVal > {
6770 match dur {
6871 Some ( dur) => {
6972 if dur. as_secs ( ) == 0 && dur. subsec_nanos ( ) == 0 {
@@ -80,19 +83,17 @@ fn timeval_from_duration(dur: Option<Duration>) -> Result<timeval> {
8083 } else {
8184 dur. as_secs ( ) as libc:: time_t
8285 } ;
86+ #[ cfg_attr( target_env = "musl" , allow( deprecated) ) ]
8387 let mut timeout = timeval {
8488 tv_sec : secs,
85- tv_usec : i64:: from ( dur. subsec_micros ( ) ) as suseconds_t ,
89+ tv_usec : i64:: from ( dur. subsec_micros ( ) ) as libc :: suseconds_t ,
8690 } ;
8791 if timeout. tv_sec == 0 && timeout. tv_usec == 0 {
8892 timeout. tv_usec = 1 ;
8993 }
90- Ok ( timeout)
94+ Ok ( timeout. into ( ) )
9195 }
92- None => Ok ( timeval {
93- tv_sec : 0 ,
94- tv_usec : 0 ,
95- } ) ,
96+ None => Ok ( TimeVal :: new ( 0 , 0 ) ) ,
9697 }
9798}
9899
@@ -311,13 +312,13 @@ impl VsockSocket {
311312
312313 /// Set the timeout on read operations.
313314 pub fn set_read_timeout ( & self , dur : Option < Duration > ) -> Result < ( ) > {
314- let timeout = timeval_from_duration ( dur) ?. into ( ) ;
315+ let timeout = timeval_from_duration ( dur) ?;
315316 Ok ( ReceiveTimeout . set ( & self . socket , & timeout) ?)
316317 }
317318
318319 /// Set the timeout on write operations.
319320 pub fn set_write_timeout ( & self , dur : Option < Duration > ) -> Result < ( ) > {
320- let timeout = timeval_from_duration ( dur) ?. into ( ) ;
321+ let timeout = timeval_from_duration ( dur) ?;
321322 Ok ( SendTimeout . set ( & self . socket , & timeout) ?)
322323 }
323324
@@ -460,13 +461,13 @@ impl VsockStream {
460461
461462 /// Set the timeout on read operations.
462463 pub fn set_read_timeout ( & self , dur : Option < Duration > ) -> Result < ( ) > {
463- let timeout = timeval_from_duration ( dur) ?. into ( ) ;
464+ let timeout = timeval_from_duration ( dur) ?;
464465 Ok ( ReceiveTimeout . set ( & self . socket , & timeout) ?)
465466 }
466467
467468 /// Set the timeout on write operations.
468469 pub fn set_write_timeout ( & self , dur : Option < Duration > ) -> Result < ( ) > {
469- let timeout = timeval_from_duration ( dur) ?. into ( ) ;
470+ let timeout = timeval_from_duration ( dur) ?;
470471 Ok ( SendTimeout . set ( & self . socket , & timeout) ?)
471472 }
472473
0 commit comments