Skip to content

Commit 438c0e1

Browse files
committed
Rename sys::SysSocket to sys::Socket
1 parent e0f8ff5 commit 438c0e1

File tree

3 files changed

+59
-76
lines changed

3 files changed

+59
-76
lines changed

src/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use crate::{Domain, Protocol, SockAddr, TcpKeepalive, Type};
6868
/// ```
6969
pub struct Socket {
7070
// The `sys` module most have access to the socket.
71-
pub(crate) inner: sys::SysSocket,
71+
pub(crate) inner: sys::Socket,
7272
}
7373

7474
impl Socket {

src/sys/unix.rs

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -353,60 +353,60 @@ impl SockAddr {
353353
}
354354

355355
// 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;
357357

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> {
359359
syscall!(socket(family, ty, protocol))
360360
}
361361

362362
#[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]> {
364364
let mut fds = [0, 0];
365365
syscall!(socketpair(family, ty, protocol, fds.as_mut_ptr())).map(|_| fds)
366366
}
367367

368-
pub(crate) fn bind(fd: SysSocket, addr: &SockAddr) -> io::Result<()> {
368+
pub(crate) fn bind(fd: Socket, addr: &SockAddr) -> io::Result<()> {
369369
syscall!(bind(fd, addr.as_ptr(), addr.len() as _)).map(|_| ())
370370
}
371371

372-
pub(crate) fn connect(fd: SysSocket, addr: &SockAddr) -> io::Result<()> {
372+
pub(crate) fn connect(fd: Socket, addr: &SockAddr) -> io::Result<()> {
373373
syscall!(connect(fd, addr.as_ptr(), addr.len())).map(|_| ())
374374
}
375375

376-
pub(crate) fn listen(fd: SysSocket, backlog: i32) -> io::Result<()> {
376+
pub(crate) fn listen(fd: Socket, backlog: i32) -> io::Result<()> {
377377
syscall!(listen(fd, backlog)).map(|_| ())
378378
}
379379

380-
pub(crate) fn accept(fd: SysSocket) -> io::Result<(SysSocket, SockAddr)> {
380+
pub(crate) fn accept(fd: Socket) -> io::Result<(Socket, SockAddr)> {
381381
// Safety: `accept` initialises the `SockAddr` for us.
382382
unsafe { SockAddr::init(|storage, len| syscall!(accept(fd, storage.cast(), len))) }
383383
}
384384

385-
pub(crate) fn getsockname(fd: SysSocket) -> io::Result<SockAddr> {
385+
pub(crate) fn getsockname(fd: Socket) -> io::Result<SockAddr> {
386386
// Safety: `accept` initialises the `SockAddr` for us.
387387
unsafe { SockAddr::init(|storage, len| syscall!(getsockname(fd, storage.cast(), len))) }
388388
.map(|(_, addr)| addr)
389389
}
390390

391-
pub(crate) fn getpeername(fd: SysSocket) -> io::Result<SockAddr> {
391+
pub(crate) fn getpeername(fd: Socket) -> io::Result<SockAddr> {
392392
// Safety: `accept` initialises the `SockAddr` for us.
393393
unsafe { SockAddr::init(|storage, len| syscall!(getpeername(fd, storage.cast(), len))) }
394394
.map(|(_, addr)| addr)
395395
}
396396

397-
pub(crate) fn try_clone(fd: SysSocket) -> io::Result<SysSocket> {
397+
pub(crate) fn try_clone(fd: Socket) -> io::Result<Socket> {
398398
syscall!(fcntl(fd, libc::F_DUPFD_CLOEXEC, 0))
399399
}
400400

401-
pub(crate) fn set_nonblocking(fd: SysSocket, nonblocking: bool) -> io::Result<()> {
401+
pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
402402
if nonblocking {
403403
fcntl_add(fd, libc::F_GETFL, libc::F_SETFL, libc::O_NONBLOCK)
404404
} else {
405405
fcntl_remove(fd, libc::F_GETFL, libc::F_SETFL, libc::O_NONBLOCK)
406406
}
407407
}
408408

409-
pub(crate) fn shutdown(fd: SysSocket, how: Shutdown) -> io::Result<()> {
409+
pub(crate) fn shutdown(fd: Socket, how: Shutdown) -> io::Result<()> {
410410
let how = match how {
411411
Shutdown::Write => libc::SHUT_WR,
412412
Shutdown::Read => libc::SHUT_RD,
@@ -415,7 +415,7 @@ pub(crate) fn shutdown(fd: SysSocket, how: Shutdown) -> io::Result<()> {
415415
syscall!(shutdown(fd, how)).map(|_| ())
416416
}
417417

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> {
419419
syscall!(recv(
420420
fd,
421421
buf.as_mut_ptr().cast(),
@@ -425,11 +425,7 @@ pub(crate) fn recv(fd: SysSocket, buf: &mut [u8], flags: c_int) -> io::Result<us
425425
.map(|n| n as usize)
426426
}
427427

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)> {
433429
// Safety: `recvfrom` initialises the `SockAddr` for us.
434430
unsafe {
435431
SockAddr::init(|addr, addrlen| {
@@ -448,7 +444,7 @@ pub(crate) fn recv_from(
448444

449445
#[cfg(not(target_os = "redox"))]
450446
pub(crate) fn recv_vectored(
451-
fd: SysSocket,
447+
fd: Socket,
452448
bufs: &mut [IoSliceMut<'_>],
453449
flags: c_int,
454450
) -> io::Result<(usize, RecvFlags)> {
@@ -457,7 +453,7 @@ pub(crate) fn recv_vectored(
457453

458454
#[cfg(not(target_os = "redox"))]
459455
pub(crate) fn recv_from_vectored(
460-
fd: SysSocket,
456+
fd: Socket,
461457
bufs: &mut [IoSliceMut<'_>],
462458
flags: c_int,
463459
) -> io::Result<(usize, RecvFlags, SockAddr)> {
@@ -478,7 +474,7 @@ pub(crate) fn recv_from_vectored(
478474
/// Returns the (bytes received, sending address len, `RecvFlags`).
479475
#[cfg(not(target_os = "redox"))]
480476
fn recvmsg(
481-
fd: SysSocket,
477+
fd: Socket,
482478
msg_name: *mut sockaddr_storage,
483479
bufs: &mut [IoSliceMut<'_>],
484480
flags: c_int,
@@ -501,7 +497,7 @@ fn recvmsg(
501497
.map(|n| (n as usize, msg.msg_namelen, RecvFlags(msg.msg_flags)))
502498
}
503499

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> {
505501
syscall!(send(
506502
fd,
507503
buf.as_ptr().cast(),
@@ -512,20 +508,11 @@ pub(crate) fn send(fd: SysSocket, buf: &[u8], flags: c_int) -> io::Result<usize>
512508
}
513509

514510
#[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> {
520512
sendmsg(fd, ptr::null(), 0, bufs, flags)
521513
}
522514

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> {
529516
syscall!(sendto(
530517
fd,
531518
buf.as_ptr().cast(),
@@ -539,7 +526,7 @@ pub(crate) fn send_to(
539526

540527
#[cfg(not(target_os = "redox"))]
541528
pub(crate) fn send_to_vectored(
542-
fd: SysSocket,
529+
fd: Socket,
543530
bufs: &[IoSlice<'_>],
544531
addr: &SockAddr,
545532
flags: c_int,
@@ -550,7 +537,7 @@ pub(crate) fn send_to_vectored(
550537
/// Returns the (bytes received, sending address len, `RecvFlags`).
551538
#[cfg(not(target_os = "redox"))]
552539
fn sendmsg(
553-
fd: SysSocket,
540+
fd: Socket,
554541
msg_name: *const sockaddr_storage,
555542
msg_namelen: socklen_t,
556543
bufs: &[IoSlice<'_>],
@@ -573,7 +560,7 @@ fn sendmsg(
573560
}
574561

575562
/// 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>> {
577564
unsafe { getsockopt(fd, opt, val).map(from_timeval) }
578565
}
579566

@@ -589,7 +576,7 @@ fn from_timeval(duration: libc::timeval) -> Option<Duration> {
589576

590577
/// Wrapper around `setsockopt` to deal with platform specific timeouts.
591578
pub(crate) fn set_timeout_opt(
592-
fd: SysSocket,
579+
fd: Socket,
593580
opt: c_int,
594581
val: c_int,
595582
duration: Option<Duration>,
@@ -612,14 +599,14 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
612599
}
613600

614601
#[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> {
616603
unsafe {
617604
getsockopt::<c_int>(fd, IPPROTO_TCP, KEEPALIVE_TIME)
618605
.map(|secs| Duration::from_secs(secs as u64))
619606
}
620607
}
621608

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<()> {
623610
if let Some(time) = keepalive.time {
624611
let secs = into_secs(time);
625612
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
@@ -653,7 +640,7 @@ fn into_secs(duration: Duration) -> c_int {
653640
}
654641

655642
/// 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<()> {
657644
let previous = syscall!(fcntl(fd, get_cmd))?;
658645
let new = previous | flag;
659646
if new != previous {
@@ -665,7 +652,7 @@ fn fcntl_add(fd: SysSocket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::
665652
}
666653

667654
/// 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<()> {
669656
let previous = syscall!(fcntl(fd, get_cmd))?;
670657
let new = previous & !flag;
671658
if new != previous {
@@ -677,7 +664,7 @@ fn fcntl_remove(fd: SysSocket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> i
677664
}
678665

679666
/// 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> {
681668
let mut payload: MaybeUninit<T> = MaybeUninit::uninit();
682669
let mut len = size_of::<T>() as libc::socklen_t;
683670
syscall!(getsockopt(
@@ -696,7 +683,7 @@ pub(crate) unsafe fn getsockopt<T>(fd: SysSocket, opt: c_int, val: c_int) -> io:
696683

697684
/// Caller must ensure `T` is the correct type for `opt` and `val`.
698685
pub(crate) unsafe fn setsockopt<T>(
699-
fd: SysSocket,
686+
fd: Socket,
700687
opt: c_int,
701688
val: c_int,
702689
payload: T,
@@ -712,7 +699,7 @@ pub(crate) unsafe fn setsockopt<T>(
712699
.map(|_| ())
713700
}
714701

715-
pub(crate) fn close(fd: SysSocket) {
702+
pub(crate) fn close(fd: Socket) {
716703
unsafe {
717704
let _ = libc::close(fd);
718705
}

0 commit comments

Comments
 (0)