@@ -475,9 +475,9 @@ impl SockAddr {
475
475
P : AsRef < Path > ,
476
476
{
477
477
unsafe {
478
- SockAddr :: init ( |storage, len| {
479
- // Safety: `SockAddr::init ` zeros the address, which is a valid
480
- // representation.
478
+ SockAddr :: try_init ( |storage, len| {
479
+ // Safety: `SockAddr::try_init ` zeros the address, which is a
480
+ // valid representation.
481
481
let storage: & mut libc:: sockaddr_un = unsafe { & mut * storage. cast ( ) } ;
482
482
let len: & mut socklen_t = unsafe { & mut * len } ;
483
483
@@ -498,8 +498,8 @@ impl SockAddr {
498
498
storage. sun_family = libc:: AF_UNIX as sa_family_t ;
499
499
// Safety: `bytes` and `addr.sun_path` are not overlapping and
500
500
// both point to valid memory.
501
- // `SockAddr::init ` zeroes the memory, so the path is already
502
- // null terminated.
501
+ // `SockAddr::try_init ` zeroes the memory, so the path is
502
+ // already null terminated.
503
503
unsafe {
504
504
ptr:: copy_nonoverlapping (
505
505
bytes. as_ptr ( ) ,
@@ -539,9 +539,9 @@ impl SockAddr {
539
539
) ]
540
540
pub fn vsock ( cid : u32 , port : u32 ) -> io:: Result < SockAddr > {
541
541
unsafe {
542
- SockAddr :: init ( |storage, len| {
543
- // Safety: `SockAddr::init ` zeros the address, which is a valid
544
- // representation.
542
+ SockAddr :: try_init ( |storage, len| {
543
+ // Safety: `SockAddr::try_init ` zeros the address, which is a
544
+ // valid representation.
545
545
let storage: & mut libc:: sockaddr_vm = unsafe { & mut * storage. cast ( ) } ;
546
546
let len: & mut socklen_t = unsafe { & mut * len } ;
547
547
@@ -670,18 +670,18 @@ pub(crate) fn listen(fd: Socket, backlog: c_int) -> io::Result<()> {
670
670
671
671
pub ( crate ) fn accept ( fd : Socket ) -> io:: Result < ( Socket , SockAddr ) > {
672
672
// Safety: `accept` initialises the `SockAddr` for us.
673
- unsafe { SockAddr :: init ( |storage, len| syscall ! ( accept( fd, storage. cast( ) , len) ) ) }
673
+ unsafe { SockAddr :: try_init ( |storage, len| syscall ! ( accept( fd, storage. cast( ) , len) ) ) }
674
674
}
675
675
676
676
pub ( crate ) fn getsockname ( fd : Socket ) -> io:: Result < SockAddr > {
677
677
// Safety: `accept` initialises the `SockAddr` for us.
678
- unsafe { SockAddr :: init ( |storage, len| syscall ! ( getsockname( fd, storage. cast( ) , len) ) ) }
678
+ unsafe { SockAddr :: try_init ( |storage, len| syscall ! ( getsockname( fd, storage. cast( ) , len) ) ) }
679
679
. map ( |( _, addr) | addr)
680
680
}
681
681
682
682
pub ( crate ) fn getpeername ( fd : Socket ) -> io:: Result < SockAddr > {
683
683
// Safety: `accept` initialises the `SockAddr` for us.
684
- unsafe { SockAddr :: init ( |storage, len| syscall ! ( getpeername( fd, storage. cast( ) , len) ) ) }
684
+ unsafe { SockAddr :: try_init ( |storage, len| syscall ! ( getpeername( fd, storage. cast( ) , len) ) ) }
685
685
. map ( |( _, addr) | addr)
686
686
}
687
687
@@ -723,7 +723,7 @@ pub(crate) fn recv_from(
723
723
) -> io:: Result < ( usize , SockAddr ) > {
724
724
// Safety: `recvfrom` initialises the `SockAddr` for us.
725
725
unsafe {
726
- SockAddr :: init ( |addr, addrlen| {
726
+ SockAddr :: try_init ( |addr, addrlen| {
727
727
syscall ! ( recvfrom(
728
728
fd,
729
729
buf. as_mut_ptr( ) . cast( ) ,
@@ -755,7 +755,7 @@ pub(crate) fn recv_from_vectored(
755
755
// Safety: `recvmsg` initialises the address storage and we set the length
756
756
// manually.
757
757
unsafe {
758
- SockAddr :: init ( |storage, len| {
758
+ SockAddr :: try_init ( |storage, len| {
759
759
recvmsg ( fd, storage, bufs, flags) . map ( |( n, addrlen, recv_flags) | {
760
760
// Set the correct address length.
761
761
* len = addrlen;
@@ -1100,7 +1100,7 @@ impl crate::Socket {
1100
1100
pub ( crate ) fn _accept4 ( & self , flags : c_int ) -> io:: Result < ( crate :: Socket , SockAddr ) > {
1101
1101
// Safety: `accept4` initialises the `SockAddr` for us.
1102
1102
unsafe {
1103
- SockAddr :: init ( |storage, len| {
1103
+ SockAddr :: try_init ( |storage, len| {
1104
1104
syscall ! ( accept4( self . as_raw( ) , storage. cast( ) , len, flags) )
1105
1105
. map ( crate :: Socket :: from_raw)
1106
1106
} )
0 commit comments