mirror of
https://github.com/ValveSoftware/GameNetworkingSockets.git
synced 2026-05-29 16:20:34 +00:00
Fix win32 compile
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
// Serves as an example of you how to hook up signaling server
|
||||
// to SteamNetworkingSockets P2P connections
|
||||
|
||||
#include "../tests/test_common.h"
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <assert.h>
|
||||
@@ -10,8 +12,6 @@
|
||||
#include <steam/isteamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
#include "../tests/test_common.h"
|
||||
|
||||
#ifdef POSIX
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -24,6 +24,10 @@
|
||||
inline int GetSocketError() { return errno; }
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
typedef int socklen_t;
|
||||
inline int GetSocketError() { return WSAGetLastError(); }
|
||||
#endif
|
||||
|
||||
inline int HexDigitVal( char c )
|
||||
@@ -124,8 +128,8 @@ class CTrivialSignalingClient : public ITrivialSignalingClient
|
||||
return;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
opt = 1;
|
||||
if ( ioctlsocket( sock, FIONBIO, (unsigned long*)&opt ) == -1 )
|
||||
unsigned long opt = 1;
|
||||
if ( ioctlsocket( m_sock, FIONBIO, &opt ) == -1 )
|
||||
{
|
||||
CloseSocket();
|
||||
TEST_Printf( "ioctlsocket() failed, error=%d\n", GetSocketError() );
|
||||
@@ -169,7 +173,7 @@ public:
|
||||
if ( m_sock != INVALID_SOCKET )
|
||||
{
|
||||
int l = s.length();
|
||||
int r = ::send( m_sock, s.c_str(), s.length(), 0 );
|
||||
int r = ::send( m_sock, s.c_str(), l, 0 );
|
||||
if ( r != l && r != 0 )
|
||||
{
|
||||
// Socket hosed, or we sent a partial signal.
|
||||
@@ -312,7 +316,7 @@ public:
|
||||
// To process this call, SteamnetworkingSockets will need take its own internal lock.
|
||||
// That lock may be held by another thread that is asking you to send a signal! So
|
||||
// be warned that deadlocks are a possibility here.
|
||||
m_pSteamNetworkingSockets->ReceivedP2PCustomSignal( data.c_str(), data.length(), &context );
|
||||
m_pSteamNetworkingSockets->ReceivedP2PCustomSignal( data.c_str(), (int)data.length(), &context );
|
||||
}
|
||||
|
||||
next_message:
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
// Misc stuff used in the tests
|
||||
#pragma once
|
||||
|
||||
// Force asserts to be enabled, even in release build
|
||||
#undef NDEBUG
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
struct SteamNetworkingIdentity;
|
||||
|
||||
extern void TEST_Init();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <assert.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
@@ -8,8 +9,6 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
#ifndef STEAMNETWORKINGSOCKETS_OPENSOURCE
|
||||
|
||||
+5
-6
@@ -1,4 +1,4 @@
|
||||
#include <assert.h>
|
||||
#include "test_common.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
@@ -56,8 +55,8 @@ void Quit( int rc )
|
||||
void SendMessageToPeer( const char *pszMsg )
|
||||
{
|
||||
EResult r = SteamNetworkingSockets()->SendMessageToConnection(
|
||||
g_hConnection, pszMsg, strlen(pszMsg)+1, k_nSteamNetworkingSend_Reliable, nullptr );
|
||||
assert( r == k_EREsultOK );
|
||||
g_hConnection, pszMsg, (int)strlen(pszMsg)+1, k_nSteamNetworkingSend_Reliable, nullptr );
|
||||
assert( r == k_EResultOK );
|
||||
}
|
||||
|
||||
// Called when a connection undergoes a state transition.
|
||||
@@ -217,7 +216,7 @@ int main( int argc, const char **argv )
|
||||
{
|
||||
TEST_Printf( "Creating listen socket, local virtual port %d\n", g_nVirtualPortLocal );
|
||||
g_hListenSock = SteamNetworkingSockets()->CreateListenSocketP2P( g_nVirtualPortLocal, 0, nullptr );
|
||||
assert( g_hListenSock != k_HSteamListemSocket_Invalid );
|
||||
assert( g_hListenSock != k_HSteamListenSocket_Invalid );
|
||||
}
|
||||
else if ( g_eTestRole == k_ETestRole_Symmetric )
|
||||
{
|
||||
@@ -239,7 +238,7 @@ int main( int argc, const char **argv )
|
||||
SteamNetworkingConfigValue_t opt;
|
||||
opt.SetInt32( k_ESteamNetworkingConfig_SymmetricConnect, 1 ); // << Note we set symmetric mode on the listen socket
|
||||
g_hListenSock = SteamNetworkingSockets()->CreateListenSocketP2P( g_nVirtualPortLocal, 1, &opt );
|
||||
assert( g_hListenSock != k_HSteamListemSocket_Invalid );
|
||||
assert( g_hListenSock != k_HSteamListenSocket_Invalid );
|
||||
}
|
||||
|
||||
// Begin connecting to peer, unless we are the server
|
||||
|
||||
Reference in New Issue
Block a user