This commit is contained in:
FluorescentCIAAfricanAmerican
2020-04-22 12:56:21 -04:00
commit 3bf9df6b27
15370 changed files with 5489726 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
// stdafx.cpp : source file that includes just the standard includes
// socket_tests.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
+30
View File
@@ -0,0 +1,30 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__62CC06CE_9B37_4015_8F00_2E8386891128__INCLUDED_)
#define AFX_STDAFX_H__62CC06CE_9B37_4015_8F00_2E8386891128__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdio.h>
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__62CC06CE_9B37_4015_8F00_2E8386891128__INCLUDED_)
+166
View File
@@ -0,0 +1,166 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
// socket_tests.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include "iphelpers.h"
#include "tcpsocket.h"
#include "utlvector.h"
#include "fragment_channel.h"
#include "reliable_channel.h"
#include "tier0/fasttimer.h"
#if defined( _DEBUG )
#if defined( assert )
#undef assert
#endif
#define assert(x) if ( !x ) __asm int 3;
#else
#define assert(x)
#endif
bool CompareArrays( const CUtlVector<unsigned char> &a1, const CUtlVector<unsigned char> &a2 )
{
if ( a1.Count() != a2.Count() )
return false;
for ( int i=0; i < a1.Count(); i++ )
{
if ( a1[i] != a2[i] )
return false;
}
return true;
}
// Test two reliable channels that are hooked up to each other.
void TestChannels( IChannel *pChannel1, IChannel *pChannel2, int maxPacketSize, int nTests )
{
for ( int iTest=0; iTest < nTests; iTest++ )
{
float t = (float)rand() / VALVE_RAND_MAX;
int testSize = (int)( t * (maxPacketSize-1) ) + 1;
CUtlVector<unsigned char> rnd1, rnd2;
rnd1.SetSize( testSize );
rnd2.SetSize( testSize );
for ( int i=0; i < testSize; i++ )
{
rnd1[i] = rand();
rnd2[i] = rand();
}
pChannel1->Send( rnd1.Base(), testSize );
pChannel2->Send( rnd2.Base(), testSize );
// Now wait for up to 5 seconds for the data to come in.
CUtlVector<unsigned char> tmp;
tmp.SetSize( testSize );
CUtlVector<unsigned char> testVec;
bool bReceived;
if ( !( bReceived = pChannel1->Recv( testVec, 15 ) ) || !CompareArrays( testVec, rnd2 ) )
{
assert( false );
}
if ( !( bReceived = pChannel2->Recv( testVec, 15 ) ) || !CompareArrays( testVec, rnd1 ) )
{
assert( false );
}
}
}
template<class T>
void TestChannels( T *pSock[2] )
{
int iPorts[2];
for ( int iPort=0; iPort < 2; iPort++ )
{
int nTries = 150;
for ( int iTry=0; iTry < nTries; iTry++ )
{
iPorts[iPort] = 27111 + iTry;
if ( pSock[iPort]->BindToAny( iPorts[iPort] ) )
break;
}
}
// Bind them to random ports.
pSock[0]->BeginListen();
pSock[1]->BeginConnect( CIPAddr( 127, 0, 0, 1, iPorts[0] ) );
while ( !pSock[0]->IsConnected() || !pSock[1]->IsConnected() )
{
CIPAddr remoteAddr;
if ( !pSock[0]->IsConnected() )
pSock[0]->UpdateListen( &remoteAddr );
if ( !pSock[1]->IsConnected() )
pSock[1]->UpdateConnect();
}
// Measure ping-pong time.
__int64 totalMicroseconds = 0;
int nTests = 1500;
for ( int i=0; i < nTests; i++ )
{
char buf[2116];
CFastTimer timer;
timer.Start();
pSock[0]->Send( buf, sizeof( buf ) );
CUtlVector<unsigned char> recvBuf;
pSock[1]->Recv( recvBuf );
timer.End();
totalMicroseconds += timer.GetDuration().GetMicroseconds();
}
// Now, test them with the fragmentation layer.
IChannel *pFrag[2] = { CreateFragmentLayer( pSock[0] ), CreateFragmentLayer( pSock[1] ) };
TestChannels( pFrag[0], pFrag[1], 1024*300, 5 );
TestChannels( pSock[0], pSock[1], 1024, 1000 );
}
int main(int argc, char* argv[])
{
// First, test two TCP sockets.
for ( int iChannelType=0; iChannelType < 2; iChannelType++ )
{
DWORD startTime = GetTickCount();
srand( 0 );
if ( iChannelType == 0 )
{
ITCPSocket *pTCPSockets[2] = { CreateTCPSocket(), CreateTCPSocket() };
TestChannels( pTCPSockets );
}
else
{
IReliableChannel *pReliableChannels[2] = { CreateReliableChannel(), CreateReliableChannel() };
TestChannels( pReliableChannels );
}
float flElapsed = (float)( GetTickCount() - startTime ) / 1000.0;
}
return 0;
}
+226
View File
@@ -0,0 +1,226 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="socket_tests"
ProjectGUID="{88AD4E41-A904-457D-954A-11C3B2A268C7}"
SccProjectName=""
SccAuxPath=""
SccLocalPath=""
SccProvider="">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\..\public,..\common"
PreprocessorDefinitions="NDEBUG;WIN32;_CONSOLE;PROTECTED_THINGS_DISABLE"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
PrecompiledHeaderFile=".\Release/socket_tests.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib odbc32.lib odbccp32.lib"
OutputFile=".\Release/socket_tests.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
ProgramDatabaseFile=".\Release/socket_tests.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/socket_tests.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\public,..\common"
PreprocessorDefinitions="_DEBUG;WIN32;_CONSOLE;PROTECTED_THINGS_DISABLE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug/socket_tests.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib odbc32.lib odbccp32.lib"
OutputFile=".\Debug/socket_tests.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/socket_tests.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/socket_tests.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath="..\common\fragment_channel.cpp">
</File>
<File
RelativePath="..\common\iphelpers.cpp">
</File>
<File
RelativePath="..\common\loopback_channel.cpp">
</File>
<File
RelativePath="..\common\reliable_channel.cpp">
</File>
<File
RelativePath="socket_tests.cpp">
</File>
<File
RelativePath="StdAfx.cpp">
</File>
<File
RelativePath="..\common\tcpsocket.cpp">
</File>
<File
RelativePath="..\common\threadupdatemgr.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath="..\common\connectionmgr.h">
</File>
<File
RelativePath="..\common\fragment_channel.h">
</File>
<File
RelativePath="..\common\ichannel.h">
</File>
<File
RelativePath="..\common\iphelpers.h">
</File>
<File
RelativePath="..\common\loopback_channel.h">
</File>
<File
RelativePath="..\common\reliable_channel.h">
</File>
<File
RelativePath="StdAfx.h">
</File>
<File
RelativePath="..\common\tcpsocket.h">
</File>
<File
RelativePath="..\common\threadupdatemgr.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
<File
RelativePath="ReadMe.txt">
</File>
<File
RelativePath="..\..\lib\public\tier0.lib">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>