Skip to main content

GnsSocket

Struct GnsSocket 

Source
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,

Source

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.

Source

pub fn get_connection_info( &self, GnsConnection: GnsConnection, ) -> Option<GnsConnectionInfo>

Source

pub fn flush_messages_on_connection( &self, GnsConnection: GnsConnection, ) -> GnsResult<()>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn configure_connection_lanes( &self, GnsConnection: GnsConnection, lanes: &[GnsLane], ) -> GnsResult<()>

Source

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.

Source

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>

Source

pub fn new(global: &'static GnsGlobal) -> Self

Creates a socket in the IsCreated state.

Source

pub fn listen( self, address: IpAddr, port: u16, ) -> GnsResult<GnsSocket<IsServer>>

Listens for incoming connections.

This moves the socket from IsCreated to IsServer, which gives you the server operations.

Source

pub fn connect( self, address: IpAddr, port: u16, ) -> GnsResult<GnsSocket<IsClient>>

Connects to a remote host.

This moves the socket from IsCreated to IsClient, which gives you the client operations.

Source§

impl GnsSocket<IsServer>

Source

pub fn accept(&self, connection: GnsConnection) -> GnsResult<()>

Accepts an incoming connection. Only a socket in the IsServer state has this operation.

Source§

impl GnsSocket<IsClient>

Source

pub fn connection(&self) -> GnsConnection

Returns the socket connection. Only a socket in the IsClient state has this operation.

Auto Trait Implementations§

§

impl<S> Freeze for GnsSocket<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for GnsSocket<S>
where S: RefUnwindSafe,

§

impl<S> Send for GnsSocket<S>
where S: Send,

§

impl<S> Sync for GnsSocket<S>
where S: Sync,

§

impl<S> Unpin for GnsSocket<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for GnsSocket<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for GnsSocket<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.