Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TcpSocket type #1514

Merged
merged 6 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ libc = "0.2.86"

[target.'cfg(windows)'.dependencies]
miow = "0.3.6"
winapi = { version = "0.3", features = ["winsock2", "mswsock", "mstcpip"] }
winapi = { version = "0.3", features = ["winsock2", "mswsock"] }
ntapi = "0.3"

[dev-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion ci/azure-test-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:

- ${{ if eq(parameters.cmd, 'test') }}:
- script: |
cargo install cargo-hack
# Cargo-hack's dependency bitflags has a higher MSVR then us.
rustup install nightly
rustup run nightly cargo install cargo-hack
cargo hack check --feature-powerset
displayName: Check feature powerset

Expand Down
2 changes: 1 addition & 1 deletion src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! [portability guidelines]: ../struct.Poll.html#portability

mod tcp;
pub use self::tcp::{TcpKeepalive, TcpListener, TcpSocket, TcpStream};
pub use self::tcp::{TcpListener, TcpStream};

mod udp;
pub use self::udp::UdpSocket;
Expand Down
18 changes: 13 additions & 5 deletions src/net/tcp/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket};
use std::{fmt, io};

use super::{TcpSocket, TcpStream};
use crate::io_source::IoSource;
use crate::net::TcpStream;
#[cfg(unix)]
use crate::sys::tcp::set_reuseaddr;
use crate::sys::tcp::{bind, listen, new_for_addr};
use crate::{event, sys, Interest, Registry, Token};

/// A structure representing a socket server
Expand Down Expand Up @@ -50,7 +53,11 @@ impl TcpListener {
/// 3. Bind the socket to the specified address.
/// 4. Calls `listen` on the socket to prepare it to receive new connections.
pub fn bind(addr: SocketAddr) -> io::Result<TcpListener> {
let socket = TcpSocket::new_for_addr(addr)?;
let socket = new_for_addr(addr)?;
#[cfg(unix)]
let listener = unsafe { TcpListener::from_raw_fd(socket) };
#[cfg(windows)]
let listener = unsafe { TcpListener::from_raw_socket(socket as _) };

// On platforms with Berkeley-derived sockets, this allows to quickly
// rebind a socket, without needing to wait for the OS to clean up the
Expand All @@ -60,10 +67,11 @@ impl TcpListener {
// which allows “socket hijacking”, so we explicitly don't set it here.
// https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
#[cfg(not(windows))]
socket.set_reuseaddr(true)?;
set_reuseaddr(&listener.inner, true)?;

socket.bind(addr)?;
socket.listen(1024)
bind(&listener.inner, addr)?;
listen(&listener.inner, 1024)?;
Ok(listener)
}

/// Creates a new `TcpListener` from a standard `net::TcpListener`.
Expand Down
3 changes: 0 additions & 3 deletions src/net/tcp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
mod listener;
pub use self::listener::TcpListener;

mod socket;
pub use self::socket::{TcpKeepalive, TcpSocket};

mod stream;
pub use self::stream::TcpStream;