use std::net::SocketAddr;
use tokio::sync::mpsc::{self, error::TrySendError};
use crate::{
server::ServerSyncMessage,
shared::{peer_connection::PeerConnection, InternalConnectionRef},
};
pub type ServerSideConnection = PeerConnection<ServerConnection>;
pub struct ServerConnection {
connection_handle: InternalConnectionRef,
to_connection_send: mpsc::Sender<ServerSyncMessage>,
}
impl ServerConnection {
pub(crate) fn new(
connection_handle: InternalConnectionRef,
to_connection_send: mpsc::Sender<ServerSyncMessage>,
) -> Self {
Self {
connection_handle,
to_connection_send,
}
}
}
impl ServerSideConnection {
#[inline(always)]
pub fn max_datagram_size(&self) -> Option<usize> {
self.specific.connection_handle.max_datagram_size()
}
#[inline(always)]
pub fn quinn_connection_stats(&self) -> quinn::ConnectionStats {
self.specific.connection_handle.stats()
}
#[inline(always)]
pub(crate) fn try_send_to_async_connection(
&self,
msg: ServerSyncMessage,
) -> Result<(), TrySendError<ServerSyncMessage>> {
self.specific.to_connection_send.try_send(msg)
}
#[inline(always)]
pub fn remote_addr(&self) -> SocketAddr {
self.specific.connection_handle.remote_address()
}
}