struct Connection {
state: Arc<Mutex<ConnectionState>>,
socket: Arc<Mutex<TcpStream>>,
buffer: Mutex<BytesMut>,
}
Expand description
Object representing a TCP connection.
Fields§
§state: Arc<Mutex<ConnectionState>>
§socket: Arc<Mutex<TcpStream>>
§buffer: Mutex<BytesMut>
Implementations§
Source§impl Connection
impl Connection
Sourceconst BUFFER_SIZE: usize = 512usize
const BUFFER_SIZE: usize = 512usize
Base buffer size and the number of bytes we’re trying to read from the socket.
fn new(socket: TcpStream) -> Self
Sourceasync fn get_state(&self) -> ConnectionState
async fn get_state(&self) -> ConnectionState
Get the current state of the connection
Sourceasync fn set_state(&self, new_state: ConnectionState)
async fn set_state(&self, new_state: ConnectionState)
Change the state of the current Connection.
Sourceasync fn write<T: AsRef<[u8]>>(&self, data: T) -> Result<(), NetError>
async fn write<T: AsRef<[u8]>>(&self, data: T) -> Result<(), NetError>
Writes either a &u8 to the socket.
This function can take in Packet
.
Sourceasync fn wait_size(&self, bytes: &[u8]) -> Result<(usize, usize), ()>
async fn wait_size(&self, bytes: &[u8]) -> Result<(usize, usize), ()>
Attempts to read a packet size (in bytes, in VarInt). If yes, return size. (prepending the conn buffer) If no, append bytes to connection buffer.
Sourceasync fn wait_packet(
&self,
bytes: &[u8],
size: usize,
size_size: usize,
) -> Result<Packet, ()>
async fn wait_packet( &self, bytes: &[u8], size: usize, size_size: usize, ) -> Result<Packet, ()>
Wait for the number of bytes wait_size() spew. If yes, return packet. (prepending the conn buffer) If no, append bytes to connection buffer.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Connection
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl !UnwindSafe for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.