pub struct NetConnection<Manager> { /* private fields */ }

Implementations§

source§

impl<Manager: 'static> NetConnection<Manager>

source

pub fn clear_poll_group(&self) -> Result<(), InvalidHandle>

Clear the poll group for a connection.

Returns Err(InvalidHandle) when connection is invalid.

source

pub fn close( self, reason: NetConnectionEnd, debug_string: Option<&str>, enable_linger: bool ) -> bool

Disconnects from the remote host and invalidates the connection handle. Any unread data on the connection is discarded.

nReason is an application defined code that will be received on the other end and recorded (when possible) in backend analytics. The value should come from a restricted range. (See ESteamNetConnectionEnd.) If you don’t need to communicate any information to the remote host, and do not want analytics to be able to distinguish “normal” connection terminations from “exceptional” ones, You may pass zero, in which case the generic value of k_ESteamNetConnectionEnd_App_Generic will be used.

pszDebug is an optional human-readable diagnostic string that will be received by the remote host and recorded (when possible) in backend analytics.

If you wish to put the socket into a “linger” state, where an attempt is made to flush any remaining sent data, use bEnableLinger=true. Otherwise reliable data is not flushed.

If the connection has already ended and you are just freeing up the connection interface, the reason code, debug string, and linger flag are ignored.

source

pub fn connection_user_data(&self) -> Result<i64, InvalidHandle>

Fetch connection user data. Returns -1 if handle is invalid or if you haven’t set any userdata on the connection.

source

pub fn set_connection_user_data( &self, user_data: i64 ) -> Result<(), InvalidHandle>

Set connection user data. the data is returned in the following places

  • You can query it using GetConnectionUserData.
  • The SteamNetworkingmessage_t structure.
  • The SteamNetConnectionInfo_t structure. (Which is a member of SteamNetConnectionStatusChangedCallback_t.)

Returns false if the handle is invalid.

source

pub fn set_connection_name(&self, name: &str)

Set a name for the connection, used mostly for debugging

source

pub fn send_message( &self, data: &[u8], send_flags: SendFlags ) -> SResult<MessageNumber>

Send a message to the remote host on the specified connection.

nSendFlags determines the delivery guarantees that will be provided, when data should be buffered, etc. E.g. k_nSteamNetworkingSend_Unreliable

Note that the semantics we use for messages are not precisely the same as the semantics of a standard “stream” socket. (SOCK_STREAM) For an ordinary stream socket, the boundaries between chunks are not considered relevant, and the sizes of the chunks of data written will not necessarily match up to the sizes of the chunks that are returned by the reads on the other end. The remote host might read a partial chunk, or chunks might be coalesced. For the message semantics used here, however, the sizes WILL match. Each send call will match a successful read call on the remote host one-for-one. If you are porting existing stream-oriented code to the semantics of reliable messages, your code should work the same, since reliable message semantics are more strict than stream semantics. The only caveat is related to performance: there is per-message overhead to retain the message sizes, and so if your code sends many small chunks of data, performance will suffer. Any code based on stream sockets that does not write excessively small chunks will work without any changes.

The pOutMessageNumber is an optional pointer to receive the message number assigned to the message, if sending was successful.

Returns:

  • k_EResultInvalidParam: invalid connection handle, or the individual message is too big. (See k_cbMaxSteamNetworkingSocketsMessageSizeSend)
  • k_EResultInvalidState: connection is in an invalid state
  • k_EResultNoConnection: connection has ended
  • k_EResultIgnored: You used k_nSteamNetworkingSend_NoDelay, and the message was dropped because we were not ready to send it.
  • k_EResultLimitExceeded: there was already too much data queued to be sent. (See k_ESteamNetworkingConfig_SendBufferSize)
source

pub fn connection_name(&self) -> Result<(), InvalidHandle>

Fetch connection name. Returns false if handle is invalid

source

pub fn flush_messages(&self) -> SResult<()>

Flush any messages waiting on the Nagle timer and send them at the next transmission opportunity (often that means right now).

If Nagle is enabled (it’s on by default) then when calling SendMessageToConnection the message will be buffered, up to the Nagle time before being sent, to merge small messages into the same packet. (See k_ESteamNetworkingConfig_NagleTime)

Returns: k_EResultInvalidParam: invalid connection handle k_EResultInvalidState: connection is in an invalid state k_EResultNoConnection: connection has ended k_EResultIgnored: We weren’t (yet) connected, so this operation has no effect.

source

pub fn receive_messages( &mut self, batch_size: usize ) -> Result<Vec<NetworkingMessage<Manager>>, InvalidHandle>

Fetch the next available message(s) from the connection, if any. Returns the number of messages returned into your array, up to nMaxMessages. If the connection handle is invalid, -1 is returned.

The order of the messages returned in the array is relevant. Reliable messages will be received in the order they were sent (and with the same sizes — see SendMessageToConnection for on this subtle difference from a stream socket).

Unreliable messages may be dropped, or delivered out of order with respect to each other or with respect to reliable messages. The same unreliable message may be received multiple times.

If any messages are returned, you MUST call SteamNetworkingMessage_t::Release() on each of them free up resources after you are done. It is safe to keep the object alive for a little while (put it into some queue, etc), and you may call Release() from any thread.

source

pub fn set_poll_group(&self, poll_group: &NetPollGroup<Manager>)

Assign a connection to a poll group. Note that a connection may only belong to a single poll group. Adding a connection to a poll group implicitly removes it from any other poll group it is in.

You can call clear_connection_poll_group to remove a connection from its current poll group without adding it to a new poll group.

If there are received messages currently pending on the connection, an attempt is made to add them to the queue of messages for the poll group in approximately the order that would have applied if the connection was already part of the poll group at the time that the messages were received.

Returns false if the connection handle is invalid, or if the poll group handle is invalid (and not k_HSteamNetPollGroup_Invalid).

source

pub fn run_callbacks(&self)

Trait Implementations§

source§

impl<Manager> Drop for NetConnection<Manager>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<Manager: Send + Sync> Send for NetConnection<Manager>

source§

impl<Manager: Send + Sync> Sync for NetConnection<Manager>

Auto Trait Implementations§

§

impl<Manager> RefUnwindSafe for NetConnection<Manager>
where Manager: RefUnwindSafe,

§

impl<Manager> Unpin for NetConnection<Manager>

§

impl<Manager> UnwindSafe for NetConnection<Manager>
where Manager: RefUnwindSafe,

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

§

type Error = Infallible

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

§

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.