X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=src%2Fvg%2Fvg_steam_networking.h;h=6eb059909d261274abe9321572f935140b0fed68;hb=3dd767bb10e6fee9cbffeb185d1a9685810c17b5;hp=c5c053626b7bb83306503e6d495c9fc57be917cd;hpb=e99cbefb033306f6e500a6c0860e9bea6dbebf99;p=vg.git diff --git a/src/vg/vg_steam_networking.h b/src/vg/vg_steam_networking.h index c5c0536..6eb0599 100644 --- a/src/vg/vg_steam_networking.h +++ b/src/vg/vg_steam_networking.h @@ -4,12 +4,12 @@ #include "vg_steam.h" #ifdef VALVE_CALLBACK_PACK_SMALL +; #pragma pack(push,4) #else #pragma pack(push,8) #endif -typedef enum ESteamNetworkingConfigScope ESteamNetworkingConfigScope; enum ESteamNetworkingConfigScope { k_ESteamNetworkingConfig_Global = 1, @@ -18,8 +18,8 @@ enum ESteamNetworkingConfigScope k_ESteamNetworkingConfig_Connection = 4, k_ESteamNetworkingConfigScope__Force32Bit = 0x7fffffff }; +typedef enum ESteamNetworkingConfigScope ESteamNetworkingConfigScope; -typedef enum ESteamNetworkingConfigDataType ESteamNetworkingConfigDataType; enum ESteamNetworkingConfigDataType { k_ESteamNetworkingConfig_Int32 = 1, @@ -30,8 +30,8 @@ enum ESteamNetworkingConfigDataType k_ESteamNetworkingConfigDataType__Force32Bit = 0x7fffffff }; +typedef enum ESteamNetworkingConfigDataType ESteamNetworkingConfigDataType; -typedef enum ESteamNetworkingConfigValue ESteamNetworkingConfigValue; enum ESteamNetworkingConfigValue { k_ESteamNetworkingConfig_Invalid = 0, @@ -93,9 +93,9 @@ enum ESteamNetworkingConfigValue k_ESteamNetworkingConfig_DELETED_EnumerateDevVars = 35, k_ESteamNetworkingConfigValue__Force32Bit = 0x7fffffff }; +typedef enum ESteamNetworkingConfigValue ESteamNetworkingConfigValue; -typedef enum ESteamNetworkingConnectionState ESteamNetworkingConnectionState; enum ESteamNetworkingConnectionState { k_ESteamNetworkingConnectionState_None = 0, @@ -109,8 +109,8 @@ enum ESteamNetworkingConnectionState k_ESteamNetworkingConnectionState_Dead = -3, k_ESteamNetworkingConnectionState__Force32Bit = 0x7fffffff }; +typedef enum ESteamNetworkingConnectionState ESteamNetworkingConnectionState; -typedef enum ESteamNetConnectionEnd ESteamNetConnectionEnd; enum ESteamNetConnectionEnd { k_ESteamNetConnectionEnd_Invalid = 0, @@ -152,8 +152,8 @@ enum ESteamNetConnectionEnd k_ESteamNetConnectionEnd_Misc_Max = 5999, k_ESteamNetConnectionEnd__Force32Bit = 0x7fffffff }; +typedef enum ESteamNetConnectionEnd ESteamNetConnectionEnd; -typedef enum ESteamNetworkingIdentityType ESteamNetworkingIdentityType; enum ESteamNetworkingIdentityType { k_ESteamNetworkingIdentityType_Invalid = 0, @@ -164,8 +164,8 @@ enum ESteamNetworkingIdentityType k_ESteamNetworkingIdentityType_UnknownType = 4, k_ESteamNetworkingIdentityType__Force32bit = 0x7fffffff, }; +typedef enum ESteamNetworkingIdentityType ESteamNetworkingIdentityType; -typedef enum ESteamNetworkingAvailability ESteamNetworkingAvailability; enum ESteamNetworkingAvailability { k_ESteamNetworkingAvailability_CannotTry = -102, @@ -179,6 +179,7 @@ enum ESteamNetworkingAvailability k_ESteamNetworkingAvailability_Unknown = 0, k_ESteamNetworkingAvailability__Force32bit = 0x7fffffff, }; +typedef enum ESteamNetworkingAvailability ESteamNetworkingAvailability; /* Handle used to identify a connection to a remote host. */ typedef u32 HSteamNetConnection; @@ -193,10 +194,7 @@ typedef u32 HSteamListenSocket; HSteamListenSocket const k_HSteamListenSocket_Invalid = 0; typedef u32 SteamNetworkingPOPID; - -#define k_cchSteamNetworkingMaxConnectionCloseReason 128 -#define k_cchSteamNetworkingMaxConnectionDescription 128 -#define k_cchSteamNetworkingMaxConnectionAppName 32 +typedef i64 SteamNetworkingMicroseconds; #pragma pack(push,1) /* Store an IP and port. IPv6 is always used; IPv4 is represented using @@ -247,7 +245,6 @@ struct SteamNetworkingIdentity * "Fake IPs" are assigned to hosts, to make it easier to interface with * older code that assumed all hosts will have an IPv4 address */ -typedef enum ESteamNetworkingFakeIPType ESteamNetworkingFakeIPType; enum ESteamNetworkingFakeIPType { k_ESteamNetworkingFakeIPType_Invalid, @@ -256,6 +253,7 @@ enum ESteamNetworkingFakeIPType k_ESteamNetworkingFakeIPType_LocalIPv4, k_ESteamNetworkingFakeIPType__Force32Bit = 0x7fffffff }; +typedef enum ESteamNetworkingFakeIPType ESteamNetworkingFakeIPType; /* Set everything to zero. E.g. [::]:0 */ void SteamAPI_SteamNetworkingIPAddr_Clear( SteamNetworkingIPAddr* self ); @@ -328,69 +326,6 @@ ESteamNetworkingFakeIPType SteamAPI_SteamNetworkingIPAddr_GetFakeIPType( /* Return true if we are a FakeIP */ int SteamAPI_SteamNetworkingIPAddr_IsFakeIP( SteamNetworkingIPAddr* self ); - -/* Describe the state of a connection. */ -typedef struct SteamNetConnectionInfo_t SteamNetConnectionInfo_t; -struct SteamNetConnectionInfo_t -{ - SteamNetworkingIdentity m_identityRemote; - - /* Arbitrary user data set by the local application code */ - i64 m_nUserData; - - /* Handle to listen socket this was connected on, or - * k_HSteamListenSocket_Invalid if we initiated the connection */ - HSteamListenSocket m_hListenSocket; - - /* Remote address. Might be all 0's if we don't know it, or if this is N/A. - * (E.g. Basically everything except direct UDP connection.) */ - SteamNetworkingIPAddr m_addrRemote; - u16 m__pad1; - - /* What data center is the remote host in? (0 if we don't know.) */ - SteamNetworkingPOPID m_idPOPRemote; - - /* What relay are we using to communicate with the remote host? - * (0 if not applicable.) */ - SteamNetworkingPOPID m_idPOPRelay; - - /* High level state of the connection */ - ESteamNetworkingConnectionState m_eState; - - /* Basic cause of the connection termination or problem. - * See ESteamNetConnectionEnd for the values used */ - int m_eEndReason; - - /* - * Human-readable, but non-localized explanation for connection - * termination or problem. This is intended for debugging / - * diagnostic purposes only, not to display to users. It might - * have some details specific to the issue. - */ - char m_szEndDebug[ 128 ]; - - /* - * Debug description. This includes the internal connection ID, - * connection type (and peer information), and any name - * given to the connection by the app. This string is used in various - * internal logging messages. - * - * Note that the connection ID *usually* matches the HSteamNetConnection - * handle, but in certain cases with symmetric connections it might not. - */ - char m_szConnectionDescription[ 128 ]; - - /* - * Misc flags. Bitmask of k_nSteamNetworkConnectionInfoFlags_Xxxx - */ - int m_nFlags; - - /* - * Internal stuff, room to change API easily - */ - u32 reserved[63]; -}; - /* * In a few places we need to set configuration options on listen sockets and * connections, and have them take effect *before* the listen socket or @@ -446,6 +381,11 @@ void SteamAPI_SteamNetworkingConfigValue_t_SetString( SteamNetworkingConfigValue_t* self, ESteamNetworkingConfigValue eVal, const char * data ); +typedef void ISteamNetworkingSockets; +typedef struct SteamNetworkingMessage_t SteamNetworkingMessage_t; +typedef struct SteamNetConnectionInfo_t SteamNetConnectionInfo_t; + + /* * Handle used to identify a poll group, used to query many * connections at once efficiently. @@ -453,46 +393,389 @@ void SteamAPI_SteamNetworkingConfigValue_t_SetString( typedef u32 HSteamNetPollGroup; HSteamNetPollGroup const k_HSteamNetPollGroup_Invalid = 0; -void *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(void); -void *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI(void) +ISteamNetworkingSockets +*SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(void); + +ISteamNetworkingSockets +*SteamAPI_SteamGameServerNetworkingSockets_SteamAPI(void) { return SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(); } -void *SteamAPI_SteamNetworkingSockets_SteamAPI_v012(); -void *SteamAPI_SteamNetworkingSockets_SteamAPI() +ISteamNetworkingSockets *SteamAPI_SteamNetworkingSockets_SteamAPI_v012(); +ISteamNetworkingSockets *SteamAPI_SteamNetworkingSockets_SteamAPI() { return SteamAPI_SteamNetworkingSockets_SteamAPI_v012(); } + +/* + * Send the message unreliably. Can be lost. Messages *can* be larger than a + * single MTU (UDP packet), but there is no retransmission, so if any piece + * of the message is lost, the entire message will be dropped. + + * The sending API does have some knowledge of the underlying connection, so + * if there is no NAT-traversal accomplished or there is a recognized adjustment + * happening on the connection, the packet will be batched until the connection + * is open again. + + * Migration note: This is not exactly the same as k_EP2PSendUnreliable! You + * probably want k_ESteamNetworkingSendType_UnreliableNoNagle + */ +const int k_nSteamNetworkingSend_Unreliable = 0; + +/* + * Disable Nagle's algorithm. + * By default, Nagle's algorithm is applied to all outbound messages. This means + * that the message will NOT be sent immediately, in case further messages are + * sent soon after you send this, which can be grouped together. Any time there + * is enough buffered data to fill a packet, the packets will be pushed out + * immediately, but partially-full packets not be sent until the Nagle timer + * expires. See ISteamNetworkingSockets::FlushMessagesOnConnection, + * ISteamNetworkingMessages::FlushMessagesToUser + * + * NOTE: Don't just send every message without Nagle because you want packets to + * get there quicker. Make sure you understand the problem that Nagle is + * solving before disabling it. If you are sending small messages, often many at + * the same time, then it is very likely that it will be more efficient to leave + * Nagle enabled. A typical proper use of this flag is when you are sending + * what you know will be the last message sent for a while (e.g. the last in the + * server simulation tick to a particular client), and you use this flag to + * flush all messages. + */ +const int k_nSteamNetworkingSend_NoNagle = 1; + +/* + * Send a message unreliably, bypassing Nagle's algorithm for this message and + * any messages currently pending on the Nagle timer. This is equivalent to + * using k_ESteamNetworkingSend_Unreliable and then immediately flushing the + * messages using ISteamNetworkingSockets::FlushMessagesOnConnection or + * ISteamNetworkingMessages::FlushMessagesToUser. (But using this flag is more + * efficient since you only make one API call.) + */ +const int k_nSteamNetworkingSend_UnreliableNoNagle = + k_nSteamNetworkingSend_Unreliable | + k_nSteamNetworkingSend_NoNagle; +/* + * If the message cannot be sent very soon (because the connection is still + * doing some initial handshaking, route negotiations, etc), then just drop it. + * This is only applicable for unreliable messages. Using this flag on reliable + * messages is invalid. + */ +const int k_nSteamNetworkingSend_NoDelay = 4; + +/* + * Send an unreliable message, but if it cannot be sent relatively quickly, just + * drop it instead of queuing it. This is useful for messages that are not + * useful if they are excessively delayed, such as voice data. + * NOTE: The Nagle algorithm is not used, and if the message is not dropped, any + * messages waiting on the Nagle timer are immediately flushed. + * + * A message will be dropped under the following circumstances: + * - the connection is not fully connected. (E.g. the "Connecting" or + * "FindingRoute" states) + * - there is a sufficiently large number of messages queued up already such + * that the current message will not be placed on the wire in the next + * ~200ms or so. + * + * If a message is dropped for these reasons, k_EResultIgnored will be returned. + */ +const int k_nSteamNetworkingSend_UnreliableNoDelay = + k_nSteamNetworkingSend_Unreliable | + k_nSteamNetworkingSend_NoDelay | + k_nSteamNetworkingSend_NoNagle; + +/* + * Reliable message send. Can send up to + * k_cbMaxSteamNetworkingSocketsMessageSizeSend bytes in a single message. + * Does fragmentation/re-assembly of messages under the hood, as well as a + * sliding window for efficient sends of large chunks of data. + * The Nagle algorithm is used. See notes on + * k_ESteamNetworkingSendType_Unreliable for more details. + * See k_ESteamNetworkingSendType_ReliableNoNagle, + * ISteamNetworkingSockets::FlushMessagesOnConnection, + * ISteamNetworkingMessages::FlushMessagesToUser + * + * Migration note: This is NOT the same as k_EP2PSendReliable, it's more like + * k_EP2PSendReliableWithBuffering + */ +const int k_nSteamNetworkingSend_Reliable = 8; + +/* + * Send a message reliably, but bypass Nagle's algorithm. + * + * Migration note: This is equivalent to k_EP2PSendReliable + */ +const int k_nSteamNetworkingSend_ReliableNoNagle = + k_nSteamNetworkingSend_Reliable | + k_nSteamNetworkingSend_NoNagle; + + HSteamListenSocket SteamAPI_ISteamNetworkingSockets_CreateListenSocketIP( - void *self, SteamNetworkingIPAddr *localAddress, int nOptions, + ISteamNetworkingSockets *self, + SteamNetworkingIPAddr *localAddress, int nOptions, SteamNetworkingConfigValue_t *pOptions ); HSteamNetConnection SteamAPI_ISteamNetworkingSockets_ConnectByIPAddress( - void *self, + ISteamNetworkingSockets *self, SteamNetworkingIPAddr *address, int nOptions, SteamNetworkingConfigValue_t *pOptions ); EResult SteamAPI_ISteamNetworkingSockets_AcceptConnection( - void *self, HSteamNetConnection hConn ); + ISteamNetworkingSockets *self, + HSteamNetConnection hConn ); int SteamAPI_ISteamNetworkingSockets_CloseConnection( - void *self, HSteamNetConnection hPeer, int nReason, const char *pszDebug, + ISteamNetworkingSockets *self, + HSteamNetConnection hPeer, int nReason, const char *pszDebug, int bEnableLinger ); int SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress( - void *self, HSteamListenSocket hSocket, + ISteamNetworkingSockets *self, HSteamListenSocket hSocket, SteamNetworkingIPAddr *address ); int SteamAPI_ISteamNetworkingSockets_CloseConnection( - void *self, HSteamNetConnection hPeer, int nReason, const char *pszDebug, + ISteamNetworkingSockets *self, + HSteamNetConnection hPeer, int nReason, const char *pszDebug, int bEnableLinger ); int SteamAPI_ISteamNetworkingSockets_CloseListenSocket( - void *self, HSteamListenSocket hSocket ); + ISteamNetworkingSockets *self, HSteamListenSocket hSocket ); + +EResult SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( + ISteamNetworkingSockets* self, + HSteamNetConnection hConn, const void *pData, u32 cbData, int nSendFlags, + i64 * pOutMessageNumber ); + +void SteamAPI_ISteamNetworkingSockets_SendMessages( + ISteamNetworkingSockets* self, + int nMessages, SteamNetworkingMessage_t *const *pMessages, + i64 *pOutMessageNumberOrResult ); + +EResult SteamAPI_ISteamNetworkingSockets_FlushMessagesOnConnection( + ISteamNetworkingSockets* self, + HSteamNetConnection hConn ); + +int SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnConnection( + ISteamNetworkingSockets* self, + HSteamNetConnection hConn, + SteamNetworkingMessage_t **ppOutMessages, + int nMaxMessages ); + +/* + * Poll Groups + */ + +HSteamNetPollGroup SteamAPI_ISteamNetworkingSockets_CreatePollGroup( + ISteamNetworkingSockets *self ); + +int SteamAPI_ISteamNetworkingSockets_DestroyPollGroup( + ISteamNetworkingSockets *self, + HSteamNetPollGroup hPollGroup ); + +int SteamAPI_ISteamNetworkingSockets_SetConnectionPollGroup( + ISteamNetworkingSockets *self, + HSteamNetConnection hConn, HSteamNetPollGroup hPollGroup ); + +int SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnPollGroup( + ISteamNetworkingSockets *self, + HSteamNetPollGroup hPollGroup, SteamNetworkingMessage_t **ppOutMessages, + int nMaxMessages ); +/* + * Returns basic information about the high-level state of the connection. + * Returns false if the connection handle is invalid. + */ +int SteamAPI_ISteamNetworkingSockets_GetConnectionInfo( + ISteamNetworkingSockets* self, + HSteamNetConnection hConn, SteamNetConnectionInfo_t * pInfo ); + +int SteamAPI_ISteamNetworkingSockets_GetDetailedConnectionStatus( + ISteamNetworkingSockets* self, + HSteamNetConnection hConn, char *pszBuf, int cbBuf ); + +int SteamAPI_ISteamNetworkingSockets_SetConnectionUserData( + ISteamNetworkingSockets* self, HSteamNetConnection hPeer, i64 nUserData ); + +i64 SteamAPI_ISteamNetworkingSockets_GetConnectionUserData( + ISteamNetworkingSockets* self, HSteamNetConnection hPeer ); + +int SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress( + ISteamNetworkingSockets* self, + HSteamListenSocket hSocket, SteamNetworkingIPAddr *address ); + +enum{ k_cchSteamNetworkingMaxConnectionCloseReason = 128 }; +enum{ k_cchSteamNetworkingMaxConnectionDescription = 128 }; +enum{ k_cchSteamNetworkingMaxConnectionAppName = 32 }; +enum{ k_nSteamNetworkConnectionInfoFlags_Unauthenticated = 1 }; +enum{ k_nSteamNetworkConnectionInfoFlags_Unencrypted = 2 }; +enum{ k_nSteamNetworkConnectionInfoFlags_LoopbackBuffers = 4 }; +enum{ k_nSteamNetworkConnectionInfoFlags_Fast = 8 }; +enum{ k_nSteamNetworkConnectionInfoFlags_Relayed = 16 }; +enum{ k_nSteamNetworkConnectionInfoFlags_DualWifi = 32 }; + +/* Describe the state of a connection. */ +struct SteamNetConnectionInfo_t +{ + /* + * Who is on the other end? Depending on the connection type and phase of the + * connection, we might not know + */ + SteamNetworkingIdentity m_identityRemote; + + /* Arbitrary user data set by the local application code */ + i64 m_nUserData; + + /* + * Handle to listen socket this was connected on, or + * k_HSteamListenSocket_Invalid if we initiated the connection + */ + HSteamListenSocket m_hListenSocket; + + /* + * Remote address. Might be all 0's if we don't know it, or if this is N/A. + * (E.g. Basically everything except direct UDP connection.) + */ + SteamNetworkingIPAddr m_addrRemote; + u16 m__pad1; + + /* What data center is the remote host in? (0 if we don't know.) */ + SteamNetworkingPOPID m_idPOPRemote; + + /* + * What relay are we using to communicate with the remote host? + * (0 if not applicable.) + */ + SteamNetworkingPOPID m_idPOPRelay; + + /* High level state of the connection */ + ESteamNetworkingConnectionState m_eState; + + /* + * Basic cause of the connection termination or problem. + * See ESteamNetConnectionEnd for the values used + */ + int m_eEndReason; + + /* + * Human-readable, but non-localized explanation for connection + * termination or problem. This is intended for debugging / + * diagnostic purposes only, not to display to users. It might + * have some details specific to the issue. + */ + char m_szEndDebug[ k_cchSteamNetworkingMaxConnectionCloseReason ]; + + /* + * Debug description. This includes the internal connection ID, + * connection type (and peer information), and any name + * given to the connection by the app. This string is used in various + * internal logging messages. + * + * Note that the connection ID *usually* matches the HSteamNetConnection + * handle, but in certain cases with symmetric connections it might not. + */ + char m_szConnectionDescription + [ k_cchSteamNetworkingMaxConnectionDescription ]; + + /* Misc flags. Bitmask of k_nSteamNetworkConnectionInfoFlags_Xxxx */ + int m_nFlags; + + /* Internal stuff, room to change API easily */ + u32 reserved[63]; +}; + +/* + * Quick connection state, pared down to something you could call + * more frequently without it being too big of a perf hit. + */ +struct SteamNetConnectionRealTimeStatus_t +{ + /* High level state of the connection */ + ESteamNetworkingConnectionState m_eState; + + /* Current ping (ms) */ + int m_nPing; + + /* + * Connection quality measured locally, 0...1. + * (Percentage of packets delivered end-to-end in order). + */ + float m_flConnectionQualityLocal; + + /* Packet delivery success rate as observed from remote host */ + float m_flConnectionQualityRemote; + + /* Current data rates from recent history. */ + float m_flOutPacketsPerSec; + float m_flOutBytesPerSec; + float m_flInPacketsPerSec; + float m_flInBytesPerSec; + + /* + * Estimate rate that we believe that we can send data to our peer. + * Note that this could be significantly higher than m_flOutBytesPerSec, + * meaning the capacity of the channel is higher than you are sending data. + * (That's OK!) + */ + int m_nSendRateBytesPerSecond; + + /* + * Number of bytes pending to be sent. This is data that you have recently + * requested to be sent but has not yet actually been put on the wire. The + * reliable number ALSO includes data that was previously placed on the wire, + * but has now been scheduled for re-transmission. Thus, it's possible to + * observe m_cbPendingReliable increasing between two checks, even if no + * calls were made to send reliable data between the checks. Data that is + * awaiting the Nagle delay will appear in these numbers. + */ + int m_cbPendingUnreliable; + int m_cbPendingReliable; + + /* + * Number of bytes of reliable data that has been placed the wire, but + * for which we have not yet received an acknowledgment, and thus we may + * have to re-transmit. + */ + int m_cbSentUnackedReliable; + + /* + * If you queued a message right now, approximately how long would that + * message wait in the queue before we actually started putting its data on + * the wire in a packet? + * + * In general, data that is sent by the application is limited by the + * bandwidth of the channel. If you send data faster than this, it must be + * queued and put on the wire at a metered rate. Even sending a small amount + * of data (e.g. a few MTU, say ~3k) will require some of the data to be + * delayed a bit. + * + * Ignoring multiple lanes,the estimated delay will be approximately equal to + * + * ( m_cbPendingUnreliable+m_cbPendingReliable ) / + * m_nSendRateBytesPerSecond + * + * plus or minus one MTU. It depends on how much time has elapsed since the + * last packet was put on the wire. For example, the queue might have *just* + * been emptied, and the last packet placed on the wire, and we are exactly + * up against the send rate limit. In that case we might need to wait for + * one packet's worth of time to elapse before we can send again. On the + * other extreme, the queue might have data in it waiting for Nagle. (This + * will always be less than one packet, because as soon as we have a complete + * packet we would send it.) In that case, we might be ready to send data + * now, and this value will be 0. + * + * This value is only valid if multiple lanes are not used. If multiple lanes + * are in use, then the queue time will be different for each lane, and you + * must use the value in SteamNetConnectionRealTimeLaneStatus_t. + * + * Nagle delay is ignored for the purposes of this calculation. + */ + SteamNetworkingMicroseconds m_usecQueueTime; + + // Internal stuff, room to change API easily + u32 reserved[16]; +}; /* * Callbacks @@ -530,4 +813,198 @@ struct SteamNetAuthenticationStatus_t }; #pragma pack(pop) + +/* This does not have packing specified in the steamnetworkingtypes.h, it seems + * to use default */ +struct SteamNetworkingMessage_t +{ + /* + * Message payload + */ + void *m_pData; + + /* + * Size of the payload. + */ + int m_cbSize; + + HSteamNetConnection m_conn; + + /* + * For inbound messages: Who sent this to us? + * For outbound messages on connections: not used. + * For outbound messages on the ad-hoc ISteamNetworkingMessages interface: + * who should we send this to? + */ + SteamNetworkingIdentity m_identityPeer; + + /* + * For messages received on connections, this is the user data + * associated with the connection. + * + * This is *usually* the same as calling GetConnection() and then + * fetching the user data associated with that connection, but for + * the following subtle differences: + * + * - This user data will match the connection's user data at the time + * is captured at the time the message is returned by the API. + * If you subsequently change the userdata on the connection, + * this won't be updated. + * - This is an inline call, so it's *much* faster. + * - You might have closed the connection, so fetching the user data + * would not be possible. + * + * Not used when sending messages. + */ + i64 m_nConnUserData; + + /* + * Local timestamp when the message was received + * Not used for outbound messages. + */ + SteamNetworkingMicroseconds m_usecTimeReceived; + + /* + * Message number assigned by the sender. This is not used for outbound + * messages. Note that if multiple lanes are used, each lane has its own + * message numbers, which are assigned sequentially, so messages from + * different lanes will share the same numbers. + */ + i64 m_nMessageNumber; + + /* + * Function used to free up m_pData. This mechanism exists so that + * apps can create messages with buffers allocated from their own + * heap, and pass them into the library. This function will + * usually be something like: + * + * free( pMsg->m_pData ); + */ + void (*m_pfnFreeData)( SteamNetworkingMessage_t *pMsg ); + + /* + * Function to used to decrement the internal reference count and, if + * it's zero, release the message. You should not set this function pointer, + * or need to access this directly! Use the Release() function instead! + */ + void (*m_pfnRelease)( SteamNetworkingMessage_t *pMsg ); + + /* + * When using ISteamNetworkingMessages, the channel number the message was + * received on (Not used for messages sent or received on "connections") + */ + int m_nChannel; + + /* + * Bitmask of k_nSteamNetworkingSend_xxx flags. + * For received messages, only the k_nSteamNetworkingSend_Reliable bit is + * valid. + * For outbound messages, all bits are relevant + */ + int m_nFlags; + + /* + * Arbitrary user data that you can use when sending messages using + * ISteamNetworkingUtils::AllocateMessage and + * ISteamNetworkingSockets::SendMessage. + * (The callback you set in m_pfnFreeData might use this field.) + * + * Not used for received messages. + */ + i64 m_nUserData; + + /* + * For outbound messages, which lane to use? See + * ISteamNetworkingSockets::ConfigureConnectionLanes. + * For inbound messages, what lane was the message received on? + */ + u16 m_idxLane; + u16 _pad1__; +}; + +void SteamAPI_SteamNetworkingMessage_t_Release(SteamNetworkingMessage_t* self); + + + + +/* + * Utility + */ + +static const char *string_ESteamNetworkingConnectionState( + ESteamNetworkingConnectionState s ) +{ + switch(s) + { + case k_ESteamNetworkingConnectionState_None: return "None"; break; + case k_ESteamNetworkingConnectionState_Connecting: + return "Connecting"; + break; + case k_ESteamNetworkingConnectionState_FindingRoute: + return "Finding route"; + break; + case k_ESteamNetworkingConnectionState_Connected: + return "Connected"; + break; + case k_ESteamNetworkingConnectionState_ClosedByPeer: + return "Closed By Peer"; + break; + case k_ESteamNetworkingConnectionState_ProblemDetectedLocally: + return "Problem detected locally"; + break; + case k_ESteamNetworkingConnectionState_FinWait: + return "Finwait"; + break; + case k_ESteamNetworkingConnectionState_Linger: + return "Linger"; + break; + case k_ESteamNetworkingConnectionState_Dead: + return "Dead"; + break; + case k_ESteamNetworkingConnectionState__Force32Bit: + return "Force 32 Bit"; + break; + } + + return "Error"; +} + +static const char *string_ESteamNetworkingAvailability( + ESteamNetworkingAvailability s ) +{ + switch(s) + { + case k_ESteamNetworkingAvailability_CannotTry: + return "Cannot Try"; + break; + case k_ESteamNetworkingAvailability_Failed: + return "Failed"; + break; + case k_ESteamNetworkingAvailability_Previously: + return "Previously"; + break; + case k_ESteamNetworkingAvailability_Retrying: + return "Retrying"; + break; + case k_ESteamNetworkingAvailability_NeverTried: + return "Never tried"; + break; + case k_ESteamNetworkingAvailability_Waiting: + return "Waiting"; + break; + case k_ESteamNetworkingAvailability_Attempting: + return "Attempting"; + break; + case k_ESteamNetworkingAvailability_Current: + return "Current"; + break; + case k_ESteamNetworkingAvailability_Unknown: + return "Unknown"; + break; + default: + return "Error"; + break; + } +} + #endif /* VG_STEAM_NETWORKING_H */