pub struct GnsSocket<S> { /* private fields */ }Expand description
A network socket, and the main type of this library.
Use GnsSocket::connect to create a client socket and
GnsSocket::listen to create a server socket. Every operation on a socket
is safe.
Dropping a socket frees everything that belongs to it. It does not free the
GnsGlobal instance.
Implementations§
Source§impl<S> GnsSocket<S>where
S: IsReady,
impl<S> GnsSocket<S>where
S: IsReady,
Sourcepub fn get_connection_real_time_status(
&self,
GnsConnection: GnsConnection,
nb_of_lanes: u32,
) -> GnsResult<(GnsConnectionRealTimeStatus, Vec<GnsConnectionRealTimeLaneStatus>)>
pub fn get_connection_real_time_status( &self, GnsConnection: GnsConnection, nb_of_lanes: u32, ) -> GnsResult<(GnsConnectionRealTimeStatus, Vec<GnsConnectionRealTimeLaneStatus>)>
Returns the status of a connection and of its lanes.
Configure the lanes with Self::configure_connection_lanes before you
call this.
pub fn get_connection_info( &self, GnsConnection: GnsConnection, ) -> Option<GnsConnectionInfo>
pub fn flush_messages_on_connection( &self, GnsConnection: GnsConnection, ) -> GnsResult<()>
Sourcepub fn close_connection(
&self,
GnsConnection: GnsConnection,
reason: u32,
debug: Option<&CStr>,
linger: bool,
) -> GnsResult<()>
pub fn close_connection( &self, GnsConnection: GnsConnection, reason: u32, debug: Option<&CStr>, linger: bool, ) -> GnsResult<()>
Closes a connection.
The wrapper forwards debug to the peer when you pass Some. Pass
None to send no diagnostic string and avoid allocating.
§Errors
Returns GnsError::Close if the connection handle is invalid, for
example because the connection is already closed.
Sourcepub fn receive_messages<const K: usize>(&self) -> GnsResult<ReceivedMessages<K>>
pub fn receive_messages<const K: usize>(&self) -> GnsResult<ReceivedMessages<K>>
Receives up to K messages and returns an iterator over the ones that
were available.
Each message is yielded by value, so you can keep it, forward it, or let it drop, which releases it. Any message left in the iterator is released when the iterator is dropped.
The K-slot pointer buffer lives inline in the returned iterator, so
this call allocates nothing and copies no payload. Use
receive_messages_into to reuse one
buffer across calls and avoid moving the inline array.
§Errors
Returns GnsError::Receive if the connection or poll group handle is
invalid.
Sourcepub fn receive_messages_into<'a>(
&self,
buffer: &'a mut [MessageSlot],
) -> GnsResult<ReceivedMessagesInto<'a>>
pub fn receive_messages_into<'a>( &self, buffer: &'a mut [MessageSlot], ) -> GnsResult<ReceivedMessagesInto<'a>>
Receives up to buffer.len() messages into a buffer you own, and
returns an iterator over the ones that were available.
This is the variant of receive_messages that
neither allocates nor moves the buffer. GameNetworkingSockets fills
buffer in place and the returned iterator borrows it, so reusing one
buffer across a polling loop costs nothing per call.
§Errors
Returns GnsError::Receive if the connection or poll group handle is
invalid.
Sourcepub fn receive_events(&self) -> impl Iterator<Item = GnsConnectionEvent> + '_
pub fn receive_events(&self) -> impl Iterator<Item = GnsConnectionEvent> + '_
Returns an iterator that drains the pending connection events.
Unlike receive_messages, you supply no
buffer. Events arrive on an internal lock-free queue that the
connection-status callback fills, and this call pops from that queue.
pub fn configure_connection_lanes( &self, GnsConnection: GnsConnection, lanes: &[GnsLane], ) -> GnsResult<()>
Sourcepub fn send_message(
&self,
message: GnsNetworkMessage<ToSend>,
) -> GnsResult<GnsMessageNumber>
pub fn send_message( &self, message: GnsNetworkMessage<ToSend>, ) -> GnsResult<GnsMessageNumber>
Sends a single message to its target connection.
This is a convenience wrapper over
send_messages for the common one-message case.
Sourcepub fn send_messages(
&self,
messages: impl IntoIterator<Item = GnsNetworkMessage<ToSend>>,
) -> Vec<SendOutcome>
pub fn send_messages( &self, messages: impl IntoIterator<Item = GnsNetworkMessage<ToSend>>, ) -> Vec<SendOutcome>
Sends each message to its target connection.
The returned Vec holds one SendOutcome per input message, in the
same order.
Source§impl GnsSocket<IsCreated>
impl GnsSocket<IsCreated>
Source§impl GnsSocket<IsClient>
impl GnsSocket<IsClient>
Sourcepub fn connection(&self) -> GnsConnection
pub fn connection(&self) -> GnsConnection
Returns the socket connection. Only a socket in the IsClient state
has this operation.