Implement some networking sockets functions.

This commit is contained in:
Mr_Goldberg 2022-05-21 00:38:29 -04:00
parent 6d5cb3181f
commit a0e558ed4c
No known key found for this signature in database
GPG key ID: 8597D87419DEF278
2 changed files with 38 additions and 2 deletions

View file

@ -755,6 +755,7 @@ EResult SendMessageToConnection( HSteamNetConnection hConn, const void *pData, u
bool reliable = false;
if (nSendFlags & k_nSteamNetworkingSend_Reliable) reliable = true;
if (pOutMessageNumber) *pOutMessageNumber = 1; //TODO
if (network->sendTo(&msg, reliable)) return k_EResultOK;
return k_EResultFail;
}
@ -800,6 +801,20 @@ EResult SendMessageToConnection( HSteamNetConnection hConn, const void *pData, u
void SendMessages( int nMessages, SteamNetworkingMessage_t *const *pMessages, int64 *pOutMessageNumberOrResult )
{
PRINT_DEBUG("Steam_Networking_Sockets::SendMessages\n");
for (int i = 0; i < nMessages; ++i) {
int64 out_number = 0;
int result = SendMessageToConnection(pMessages[i]->m_conn, pMessages[i]->m_pData, pMessages[i]->m_cbSize, pMessages[i]->m_nFlags, &out_number);
if (pOutMessageNumberOrResult) {
if (result == k_EResultOK) {
pOutMessageNumberOrResult[i] = out_number;
} else {
pOutMessageNumberOrResult[i] = -result;
}
}
pMessages[i]->m_pfnFreeData(pMessages[i]);
pMessages[i]->Release();
}
}

View file

@ -68,6 +68,18 @@ Steam_Networking_Utils(class Settings *settings, class Networking *network, clas
this->run_every_runcb->remove(&Steam_Networking_Utils::steam_run_every_runcb, this);
}
static void free_steam_message_data(SteamNetworkingMessage_t *pMsg)
{
free(pMsg->m_pData);
pMsg->m_pData = NULL;
}
static void delete_steam_message(SteamNetworkingMessage_t *pMsg)
{
if (pMsg->m_pfnFreeData) pMsg->m_pfnFreeData(pMsg);
delete pMsg;
}
/// Allocate and initialize a message object. Usually the reason
/// you call this is to pass it to ISteamNetworkingSockets::SendMessages.
/// The returned object will have all of the relevant fields cleared to zero.
@ -90,8 +102,17 @@ Steam_Networking_Utils(class Settings *settings, class Networking *network, clas
SteamNetworkingMessage_t *AllocateMessage( int cbAllocateBuffer )
{
PRINT_DEBUG("Steam_Networking_Utils::AllocateMessage\n");
//TODO
return NULL;
SteamNetworkingMessage_t *pMsg = new SteamNetworkingMessage_t();
pMsg->m_pfnFreeData = &free_steam_message_data;
pMsg->m_pfnRelease = &delete_steam_message;
if (cbAllocateBuffer < 0)
cbAllocateBuffer = 0;
if (cbAllocateBuffer)
pMsg->m_pData = malloc(cbAllocateBuffer);
pMsg->m_cbSize = cbAllocateBuffer;
return pMsg;
}
bool InitializeRelayAccess()