@@ -353,60 +353,60 @@ impl SockAddr {
353
353
}
354
354
355
355
// TODO: rename to `Socket` once the struct `Socket` is no longer used.
356
- pub ( crate ) type SysSocket = c_int ;
356
+ pub ( crate ) type Socket = c_int ;
357
357
358
- pub ( crate ) fn socket ( family : c_int , ty : c_int , protocol : c_int ) -> io:: Result < SysSocket > {
358
+ pub ( crate ) fn socket ( family : c_int , ty : c_int , protocol : c_int ) -> io:: Result < Socket > {
359
359
syscall ! ( socket( family, ty, protocol) )
360
360
}
361
361
362
362
#[ cfg( feature = "all" ) ]
363
- pub ( crate ) fn socketpair ( family : c_int , ty : c_int , protocol : c_int ) -> io:: Result < [ SysSocket ; 2 ] > {
363
+ pub ( crate ) fn socketpair ( family : c_int , ty : c_int , protocol : c_int ) -> io:: Result < [ Socket ; 2 ] > {
364
364
let mut fds = [ 0 , 0 ] ;
365
365
syscall ! ( socketpair( family, ty, protocol, fds. as_mut_ptr( ) ) ) . map ( |_| fds)
366
366
}
367
367
368
- pub ( crate ) fn bind ( fd : SysSocket , addr : & SockAddr ) -> io:: Result < ( ) > {
368
+ pub ( crate ) fn bind ( fd : Socket , addr : & SockAddr ) -> io:: Result < ( ) > {
369
369
syscall ! ( bind( fd, addr. as_ptr( ) , addr. len( ) as _) ) . map ( |_| ( ) )
370
370
}
371
371
372
- pub ( crate ) fn connect ( fd : SysSocket , addr : & SockAddr ) -> io:: Result < ( ) > {
372
+ pub ( crate ) fn connect ( fd : Socket , addr : & SockAddr ) -> io:: Result < ( ) > {
373
373
syscall ! ( connect( fd, addr. as_ptr( ) , addr. len( ) ) ) . map ( |_| ( ) )
374
374
}
375
375
376
- pub ( crate ) fn listen ( fd : SysSocket , backlog : i32 ) -> io:: Result < ( ) > {
376
+ pub ( crate ) fn listen ( fd : Socket , backlog : i32 ) -> io:: Result < ( ) > {
377
377
syscall ! ( listen( fd, backlog) ) . map ( |_| ( ) )
378
378
}
379
379
380
- pub ( crate ) fn accept ( fd : SysSocket ) -> io:: Result < ( SysSocket , SockAddr ) > {
380
+ pub ( crate ) fn accept ( fd : Socket ) -> io:: Result < ( Socket , SockAddr ) > {
381
381
// Safety: `accept` initialises the `SockAddr` for us.
382
382
unsafe { SockAddr :: init ( |storage, len| syscall ! ( accept( fd, storage. cast( ) , len) ) ) }
383
383
}
384
384
385
- pub ( crate ) fn getsockname ( fd : SysSocket ) -> io:: Result < SockAddr > {
385
+ pub ( crate ) fn getsockname ( fd : Socket ) -> io:: Result < SockAddr > {
386
386
// Safety: `accept` initialises the `SockAddr` for us.
387
387
unsafe { SockAddr :: init ( |storage, len| syscall ! ( getsockname( fd, storage. cast( ) , len) ) ) }
388
388
. map ( |( _, addr) | addr)
389
389
}
390
390
391
- pub ( crate ) fn getpeername ( fd : SysSocket ) -> io:: Result < SockAddr > {
391
+ pub ( crate ) fn getpeername ( fd : Socket ) -> io:: Result < SockAddr > {
392
392
// Safety: `accept` initialises the `SockAddr` for us.
393
393
unsafe { SockAddr :: init ( |storage, len| syscall ! ( getpeername( fd, storage. cast( ) , len) ) ) }
394
394
. map ( |( _, addr) | addr)
395
395
}
396
396
397
- pub ( crate ) fn try_clone ( fd : SysSocket ) -> io:: Result < SysSocket > {
397
+ pub ( crate ) fn try_clone ( fd : Socket ) -> io:: Result < Socket > {
398
398
syscall ! ( fcntl( fd, libc:: F_DUPFD_CLOEXEC , 0 ) )
399
399
}
400
400
401
- pub ( crate ) fn set_nonblocking ( fd : SysSocket , nonblocking : bool ) -> io:: Result < ( ) > {
401
+ pub ( crate ) fn set_nonblocking ( fd : Socket , nonblocking : bool ) -> io:: Result < ( ) > {
402
402
if nonblocking {
403
403
fcntl_add ( fd, libc:: F_GETFL , libc:: F_SETFL , libc:: O_NONBLOCK )
404
404
} else {
405
405
fcntl_remove ( fd, libc:: F_GETFL , libc:: F_SETFL , libc:: O_NONBLOCK )
406
406
}
407
407
}
408
408
409
- pub ( crate ) fn shutdown ( fd : SysSocket , how : Shutdown ) -> io:: Result < ( ) > {
409
+ pub ( crate ) fn shutdown ( fd : Socket , how : Shutdown ) -> io:: Result < ( ) > {
410
410
let how = match how {
411
411
Shutdown :: Write => libc:: SHUT_WR ,
412
412
Shutdown :: Read => libc:: SHUT_RD ,
@@ -415,7 +415,7 @@ pub(crate) fn shutdown(fd: SysSocket, how: Shutdown) -> io::Result<()> {
415
415
syscall ! ( shutdown( fd, how) ) . map ( |_| ( ) )
416
416
}
417
417
418
- pub ( crate ) fn recv ( fd : SysSocket , buf : & mut [ u8 ] , flags : c_int ) -> io:: Result < usize > {
418
+ pub ( crate ) fn recv ( fd : Socket , buf : & mut [ u8 ] , flags : c_int ) -> io:: Result < usize > {
419
419
syscall ! ( recv(
420
420
fd,
421
421
buf. as_mut_ptr( ) . cast( ) ,
@@ -425,11 +425,7 @@ pub(crate) fn recv(fd: SysSocket, buf: &mut [u8], flags: c_int) -> io::Result<us
425
425
. map ( |n| n as usize )
426
426
}
427
427
428
- pub ( crate ) fn recv_from (
429
- fd : SysSocket ,
430
- buf : & mut [ u8 ] ,
431
- flags : c_int ,
432
- ) -> io:: Result < ( usize , SockAddr ) > {
428
+ pub ( crate ) fn recv_from ( fd : Socket , buf : & mut [ u8 ] , flags : c_int ) -> io:: Result < ( usize , SockAddr ) > {
433
429
// Safety: `recvfrom` initialises the `SockAddr` for us.
434
430
unsafe {
435
431
SockAddr :: init ( |addr, addrlen| {
@@ -448,7 +444,7 @@ pub(crate) fn recv_from(
448
444
449
445
#[ cfg( not( target_os = "redox" ) ) ]
450
446
pub ( crate ) fn recv_vectored (
451
- fd : SysSocket ,
447
+ fd : Socket ,
452
448
bufs : & mut [ IoSliceMut < ' _ > ] ,
453
449
flags : c_int ,
454
450
) -> io:: Result < ( usize , RecvFlags ) > {
@@ -457,7 +453,7 @@ pub(crate) fn recv_vectored(
457
453
458
454
#[ cfg( not( target_os = "redox" ) ) ]
459
455
pub ( crate ) fn recv_from_vectored (
460
- fd : SysSocket ,
456
+ fd : Socket ,
461
457
bufs : & mut [ IoSliceMut < ' _ > ] ,
462
458
flags : c_int ,
463
459
) -> io:: Result < ( usize , RecvFlags , SockAddr ) > {
@@ -478,7 +474,7 @@ pub(crate) fn recv_from_vectored(
478
474
/// Returns the (bytes received, sending address len, `RecvFlags`).
479
475
#[ cfg( not( target_os = "redox" ) ) ]
480
476
fn recvmsg (
481
- fd : SysSocket ,
477
+ fd : Socket ,
482
478
msg_name : * mut sockaddr_storage ,
483
479
bufs : & mut [ IoSliceMut < ' _ > ] ,
484
480
flags : c_int ,
@@ -501,7 +497,7 @@ fn recvmsg(
501
497
. map ( |n| ( n as usize , msg. msg_namelen , RecvFlags ( msg. msg_flags ) ) )
502
498
}
503
499
504
- pub ( crate ) fn send ( fd : SysSocket , buf : & [ u8 ] , flags : c_int ) -> io:: Result < usize > {
500
+ pub ( crate ) fn send ( fd : Socket , buf : & [ u8 ] , flags : c_int ) -> io:: Result < usize > {
505
501
syscall ! ( send(
506
502
fd,
507
503
buf. as_ptr( ) . cast( ) ,
@@ -512,20 +508,11 @@ pub(crate) fn send(fd: SysSocket, buf: &[u8], flags: c_int) -> io::Result<usize>
512
508
}
513
509
514
510
#[ cfg( not( target_os = "redox" ) ) ]
515
- pub ( crate ) fn send_vectored (
516
- fd : SysSocket ,
517
- bufs : & [ IoSlice < ' _ > ] ,
518
- flags : c_int ,
519
- ) -> io:: Result < usize > {
511
+ pub ( crate ) fn send_vectored ( fd : Socket , bufs : & [ IoSlice < ' _ > ] , flags : c_int ) -> io:: Result < usize > {
520
512
sendmsg ( fd, ptr:: null ( ) , 0 , bufs, flags)
521
513
}
522
514
523
- pub ( crate ) fn send_to (
524
- fd : SysSocket ,
525
- buf : & [ u8 ] ,
526
- addr : & SockAddr ,
527
- flags : c_int ,
528
- ) -> io:: Result < usize > {
515
+ pub ( crate ) fn send_to ( fd : Socket , buf : & [ u8 ] , addr : & SockAddr , flags : c_int ) -> io:: Result < usize > {
529
516
syscall ! ( sendto(
530
517
fd,
531
518
buf. as_ptr( ) . cast( ) ,
@@ -539,7 +526,7 @@ pub(crate) fn send_to(
539
526
540
527
#[ cfg( not( target_os = "redox" ) ) ]
541
528
pub ( crate ) fn send_to_vectored (
542
- fd : SysSocket ,
529
+ fd : Socket ,
543
530
bufs : & [ IoSlice < ' _ > ] ,
544
531
addr : & SockAddr ,
545
532
flags : c_int ,
@@ -550,7 +537,7 @@ pub(crate) fn send_to_vectored(
550
537
/// Returns the (bytes received, sending address len, `RecvFlags`).
551
538
#[ cfg( not( target_os = "redox" ) ) ]
552
539
fn sendmsg (
553
- fd : SysSocket ,
540
+ fd : Socket ,
554
541
msg_name : * const sockaddr_storage ,
555
542
msg_namelen : socklen_t ,
556
543
bufs : & [ IoSlice < ' _ > ] ,
@@ -573,7 +560,7 @@ fn sendmsg(
573
560
}
574
561
575
562
/// Wrapper around `getsockopt` to deal with platform specific timeouts.
576
- pub ( crate ) fn timeout_opt ( fd : SysSocket , opt : c_int , val : c_int ) -> io:: Result < Option < Duration > > {
563
+ pub ( crate ) fn timeout_opt ( fd : Socket , opt : c_int , val : c_int ) -> io:: Result < Option < Duration > > {
577
564
unsafe { getsockopt ( fd, opt, val) . map ( from_timeval) }
578
565
}
579
566
@@ -589,7 +576,7 @@ fn from_timeval(duration: libc::timeval) -> Option<Duration> {
589
576
590
577
/// Wrapper around `setsockopt` to deal with platform specific timeouts.
591
578
pub ( crate ) fn set_timeout_opt (
592
- fd : SysSocket ,
579
+ fd : Socket ,
593
580
opt : c_int ,
594
581
val : c_int ,
595
582
duration : Option < Duration > ,
@@ -612,14 +599,14 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
612
599
}
613
600
614
601
#[ cfg( feature = "all" ) ]
615
- pub ( crate ) fn keepalive_time ( fd : SysSocket ) -> io:: Result < Duration > {
602
+ pub ( crate ) fn keepalive_time ( fd : Socket ) -> io:: Result < Duration > {
616
603
unsafe {
617
604
getsockopt :: < c_int > ( fd, IPPROTO_TCP , KEEPALIVE_TIME )
618
605
. map ( |secs| Duration :: from_secs ( secs as u64 ) )
619
606
}
620
607
}
621
608
622
- pub ( crate ) fn set_tcp_keepalive ( fd : SysSocket , keepalive : & TcpKeepalive ) -> io:: Result < ( ) > {
609
+ pub ( crate ) fn set_tcp_keepalive ( fd : Socket , keepalive : & TcpKeepalive ) -> io:: Result < ( ) > {
623
610
if let Some ( time) = keepalive. time {
624
611
let secs = into_secs ( time) ;
625
612
unsafe { setsockopt ( fd, libc:: IPPROTO_TCP , KEEPALIVE_TIME , secs) ? }
@@ -653,7 +640,7 @@ fn into_secs(duration: Duration) -> c_int {
653
640
}
654
641
655
642
/// Add `flag` to the current set flags of `F_GETFD`.
656
- fn fcntl_add ( fd : SysSocket , get_cmd : c_int , set_cmd : c_int , flag : c_int ) -> io:: Result < ( ) > {
643
+ fn fcntl_add ( fd : Socket , get_cmd : c_int , set_cmd : c_int , flag : c_int ) -> io:: Result < ( ) > {
657
644
let previous = syscall ! ( fcntl( fd, get_cmd) ) ?;
658
645
let new = previous | flag;
659
646
if new != previous {
@@ -665,7 +652,7 @@ fn fcntl_add(fd: SysSocket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::
665
652
}
666
653
667
654
/// Remove `flag` to the current set flags of `F_GETFD`.
668
- fn fcntl_remove ( fd : SysSocket , get_cmd : c_int , set_cmd : c_int , flag : c_int ) -> io:: Result < ( ) > {
655
+ fn fcntl_remove ( fd : Socket , get_cmd : c_int , set_cmd : c_int , flag : c_int ) -> io:: Result < ( ) > {
669
656
let previous = syscall ! ( fcntl( fd, get_cmd) ) ?;
670
657
let new = previous & !flag;
671
658
if new != previous {
@@ -677,7 +664,7 @@ fn fcntl_remove(fd: SysSocket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> i
677
664
}
678
665
679
666
/// Caller must ensure `T` is the correct type for `opt` and `val`.
680
- pub ( crate ) unsafe fn getsockopt < T > ( fd : SysSocket , opt : c_int , val : c_int ) -> io:: Result < T > {
667
+ pub ( crate ) unsafe fn getsockopt < T > ( fd : Socket , opt : c_int , val : c_int ) -> io:: Result < T > {
681
668
let mut payload: MaybeUninit < T > = MaybeUninit :: uninit ( ) ;
682
669
let mut len = size_of :: < T > ( ) as libc:: socklen_t ;
683
670
syscall ! ( getsockopt(
@@ -696,7 +683,7 @@ pub(crate) unsafe fn getsockopt<T>(fd: SysSocket, opt: c_int, val: c_int) -> io:
696
683
697
684
/// Caller must ensure `T` is the correct type for `opt` and `val`.
698
685
pub ( crate ) unsafe fn setsockopt < T > (
699
- fd : SysSocket ,
686
+ fd : Socket ,
700
687
opt : c_int ,
701
688
val : c_int ,
702
689
payload : T ,
@@ -712,7 +699,7 @@ pub(crate) unsafe fn setsockopt<T>(
712
699
. map ( |_| ( ) )
713
700
}
714
701
715
- pub ( crate ) fn close ( fd : SysSocket ) {
702
+ pub ( crate ) fn close ( fd : Socket ) {
716
703
unsafe {
717
704
let _ = libc:: close ( fd) ;
718
705
}
0 commit comments