Skip to content

Commit

Permalink
PeerAddress -> Address
Browse files Browse the repository at this point in the history
  • Loading branch information
jabuwu committed May 18, 2024
1 parent e5d1d27 commit b7800b4
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/c/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) struct ENetHost<S: Socket> {
pub(crate) time: MaybeUninit<Box<dyn Fn() -> Duration>>,
pub(crate) compressor: MaybeUninit<Option<Box<dyn Compressor>>>,
pub(crate) packet_data: [[u8; 4096]; 2],
pub(crate) received_address: MaybeUninit<Option<S::PeerAddress>>,
pub(crate) received_address: MaybeUninit<Option<S::Address>>,
pub(crate) received_data: *mut u8,
pub(crate) received_data_length: usize,
pub(crate) total_sent_data: u32,
Expand Down Expand Up @@ -154,7 +154,7 @@ pub(crate) unsafe fn enet_host_random<S: Socket>(host: *mut ENetHost<S>) -> u32
}
pub(crate) unsafe fn enet_host_connect<S: Socket>(
host: *mut ENetHost<S>,
address: S::PeerAddress,
address: S::Address,
mut channel_count: usize,
data: u32,
) -> *mut ENetPeer<S> {
Expand Down
2 changes: 1 addition & 1 deletion src/c/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) struct ENetPeer<S: Socket> {
pub(crate) connect_id: u32,
pub(crate) outgoing_session_id: u8,
pub(crate) incoming_session_id: u8,
pub(crate) address: MaybeUninit<Option<S::PeerAddress>>,
pub(crate) address: MaybeUninit<Option<S::Address>>,
pub(crate) data: *mut u8,
pub(crate) state: ENetPeerState,
pub(crate) channels: *mut ENetChannel,
Expand Down
2 changes: 1 addition & 1 deletion src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<S: Socket> Host<S> {
/// Returns [`NoAvailablePeers`] if all peer slots have been filled.
pub fn connect(
&mut self,
address: S::PeerAddress,
address: S::Address,
channel_count: usize,
data: u32,
) -> Result<&mut Peer<S>, NoAvailablePeers> {
Expand Down
2 changes: 1 addition & 1 deletion src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<S: Socket> Peer<S> {
///
/// If the peer has disconnected, the previously connected peer's address will be returned.
#[must_use]
pub fn address(&self) -> Option<S::PeerAddress> {
pub fn address(&self) -> Option<S::Address> {
unsafe { (*self.0).address.assume_init_ref().clone() }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/read_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<A: Address + 'static, E: std::error::Error + Send + Sync + 'static> Default
impl<A: Address + 'static, E: std::error::Error + Send + Sync + 'static> Socket
for ReadWrite<A, E>
{
type PeerAddress = A;
type Address = A;
type Error = E;

fn init(&mut self, _socket_options: SocketOptions) -> Result<(), Self::Error> {
Expand Down
8 changes: 4 additions & 4 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub trait Socket: Sized {
///
/// An example is the standard library's [`std::net::SocketAddr`], used with
/// [`std::net::UdpSocket`].
type PeerAddress: Address + 'static;
type Address: Address + 'static;
/// Errors returned by this socket.
type Error: std::error::Error + std::fmt::Debug + Send + Sync + 'static;

Expand All @@ -38,14 +38,14 @@ pub trait Socket: Sized {
Ok(())
}
/// Try to send data. Should return the number of bytes successfully sent, or an error.
fn send(&mut self, address: Self::PeerAddress, buffer: &[u8]) -> Result<usize, Self::Error>;
fn send(&mut self, address: Self::Address, buffer: &[u8]) -> Result<usize, Self::Error>;
/// Try to receive data. May return an error, or optionally, a data packet.
///
/// Data packets are wrapped in [`PacketReceived`]. See its docs for more info.
fn receive(
&mut self,
mtu: usize,
) -> Result<Option<(Self::PeerAddress, PacketReceived)>, Self::Error>;
) -> Result<Option<(Self::Address, PacketReceived)>, Self::Error>;
}

/// Return type of [`Socket::receive`], representing either a complete packet, or a partial
Expand All @@ -67,7 +67,7 @@ pub enum PacketReceived {
}

impl Socket for UdpSocket {
type PeerAddress = SocketAddr;
type Address = SocketAddr;
type Error = io::Error;

fn init(&mut self, _socket_options: SocketOptions) -> Result<(), io::Error> {
Expand Down
6 changes: 3 additions & 3 deletions src/test/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ impl Socket {
}

impl enet::Socket for Socket {
type PeerAddress = usize;
type Address = usize;
type Error = Infallible;

fn init(&mut self, _socket_options: enet::SocketOptions) -> Result<(), Self::Error> {
Ok(())
}

fn send(&mut self, address: Self::PeerAddress, buffer: &[u8]) -> Result<usize, Self::Error> {
fn send(&mut self, address: Self::Address, buffer: &[u8]) -> Result<usize, Self::Error> {
Socket::send(self, address, buffer);
Ok(buffer.len())
}

fn receive(
&mut self,
_mtu: usize,
) -> Result<Option<(Self::PeerAddress, enet::PacketReceived)>, Self::Error> {
) -> Result<Option<(Self::Address, enet::PacketReceived)>, Self::Error> {
if let Some((address, data)) = Socket::receive(self) {
Ok(Some((address, enet::PacketReceived::Complete(data))))
} else {
Expand Down

0 comments on commit b7800b4

Please sign in to comment.