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
@@ -0,0 +1,15 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
// stdafx.cpp : source file that includes just the standard includes
// ThreadedTCPSocketTest.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
@@ -0,0 +1,31 @@
//========= 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__AA10D99C_786F_4324_86C6_4D7CDE546561__INCLUDED_)
#define AFX_STDAFX_H__AA10D99C_786F_4324_86C6_4D7CDE546561__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <windows.h>
#include <conio.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__AA10D99C_786F_4324_86C6_4D7CDE546561__INCLUDED_)
@@ -0,0 +1,198 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
// ThreadedTCPSocketTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "IThreadedTCPSocket.h"
#include "threadhelpers.h"
#include "vstdlib/random.h"
CCriticalSection g_MsgCS;
IThreadedTCPSocket *g_pClientSocket = NULL;
IThreadedTCPSocket *g_pServerSocket = NULL;
CEvent g_ClientPacketEvent;
CUtlVector<char> g_ClientPacket;
SpewRetval_t MySpewFunc( SpewType_t type, char const *pMsg )
{
CCriticalSectionLock csLock( &g_MsgCS );
csLock.Lock();
printf( "%s", pMsg );
OutputDebugString( pMsg );
csLock.Unlock();
if( type == SPEW_ASSERT )
return SPEW_DEBUGGER;
else if( type == SPEW_ERROR )
return SPEW_ABORT;
else
return SPEW_CONTINUE;
}
class CHandler_Server : public ITCPSocketHandler
{
public:
virtual void Init( IThreadedTCPSocket *pSocket )
{
}
virtual void OnPacketReceived( CTCPPacket *pPacket )
{
// Echo the data back.
g_pServerSocket->Send( pPacket->GetData(), pPacket->GetLen() );
pPacket->Release();
}
virtual void OnError( int errorCode, const char *pErrorString )
{
Msg( "Server error: %s\n", pErrorString );
}
};
class CHandler_Client : public ITCPSocketHandler
{
public:
virtual void Init( IThreadedTCPSocket *pSocket )
{
}
virtual void OnPacketReceived( CTCPPacket *pPacket )
{
if ( g_ClientPacket.Count() < pPacket->GetLen() )
g_ClientPacket.SetSize( pPacket->GetLen() );
memcpy( g_ClientPacket.Base(), pPacket->GetData(), pPacket->GetLen() );
g_ClientPacketEvent.SetEvent();
pPacket->Release();
}
virtual void OnError( int errorCode, const char *pErrorString )
{
Msg( "Client error: %s\n", pErrorString );
}
};
class CHandlerCreator_Server : public IHandlerCreator
{
public:
virtual ITCPSocketHandler* CreateNewHandler()
{
return new CHandler_Server;
}
};
class CHandlerCreator_Client : public IHandlerCreator
{
public:
virtual ITCPSocketHandler* CreateNewHandler()
{
return new CHandler_Client;
}
};
int main(int argc, char* argv[])
{
SpewOutputFunc( MySpewFunc );
// Figure out a random port to use.
CCycleCount cnt;
cnt.Sample();
CUniformRandomStream randomStream;
randomStream.SetSeed( cnt.GetMicroseconds() );
int iPort = randomStream.RandomInt( 20000, 30000 );
g_ClientPacketEvent.Init( false, false );
// Setup the "server".
CHandlerCreator_Server serverHandler;
CIPAddr addr( 127, 0, 0, 1, iPort );
ITCPConnectSocket *pListener = ThreadedTCP_CreateListener(
&serverHandler,
(unsigned short)iPort );
// Setup the "client".
CHandlerCreator_Client clientCreator;
ITCPConnectSocket *pConnector = ThreadedTCP_CreateConnector(
CIPAddr( 127, 0, 0, 1, iPort ),
CIPAddr(),
&clientCreator );
// Wait for them to connect.
while ( !g_pClientSocket )
{
if ( !pConnector->Update( &g_pClientSocket ) )
{
Error( "Error in client connector!\n" );
}
}
pConnector->Release();
while ( !g_pServerSocket )
{
if ( !pListener->Update( &g_pServerSocket ) )
Error( "Error in server connector!\n" );
}
pListener->Release();
// Send some data.
__int64 totalBytes = 0;
CCycleCount startTime;
int iPacket = 1;
startTime.Sample();
CUtlVector<char> buf;
while ( (GetAsyncKeyState( VK_SHIFT ) & 0x8000) == 0 )
{
int size = randomStream.RandomInt( 1024*0, 1024*320 );
if ( buf.Count() < size )
buf.SetSize( size );
if ( g_pClientSocket->Send( buf.Base(), size ) )
{
// Server receives the data and echoes it back. Verify that the data is good.
WaitForSingleObject( g_ClientPacketEvent.GetEventHandle(), INFINITE );
Assert( memcmp( g_ClientPacket.Base(), buf.Base(), size ) == 0 );
totalBytes += size;
CCycleCount curTime, elapsed;
curTime.Sample();
CCycleCount::Sub( curTime, startTime, elapsed );
double flSeconds = elapsed.GetSeconds();
Msg( "Packet %d, %d bytes, %dk/sec\n", iPacket++, size, (int)(((totalBytes+511)/1024) / flSeconds) );
}
}
g_pClientSocket->Release();
g_pServerSocket->Release();
return 0;
}
@@ -0,0 +1,253 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="ThreadedTCPSocketTest"
ProjectGUID="{6973F221-D381-4569-901F-6D5311FB4CD5}"
SccProjectName=""
SccAuxPath=""
SccLocalPath=""
SccProvider="">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..,..\..\..\public,..\..\..\public\tier1"
PreprocessorDefinitions="_DEBUG;WIN32;_CONSOLE;PROTECTED_THINGS_DISABLE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Debug/ThreadedTCPSocketTest.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/ThreadedTCPSocketTest.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/ThreadedTCPSocketTest.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/ThreadedTCPSocketTest.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>
<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,..\..\..\public\tier1"
PreprocessorDefinitions="NDEBUG;WIN32;_CONSOLE;PROTECTED_THINGS_DISABLE"
StringPooling="TRUE"
RuntimeLibrary="0"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Release/ThreadedTCPSocketTest.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="3"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib odbc32.lib odbccp32.lib"
OutputFile=".\Release/ThreadedTCPSocketTest.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Release/ThreadedTCPSocketTest.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/ThreadedTCPSocketTest.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>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath="StdAfx.cpp">
</File>
<File
RelativePath="..\ThreadedTCPSocket.cpp">
</File>
<File
RelativePath="..\ThreadedTCPSocketEmu.cpp">
</File>
<File
RelativePath="ThreadedTCPSocketTest.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath="..\IThreadedTCPSocket.h">
</File>
<File
RelativePath="StdAfx.h">
</File>
<File
RelativePath="..\ThreadedTCPSocketEmu.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
<File
RelativePath="..\..\..\lib\public\dbg.lib">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\..\lib\public\platform.lib">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
</File>
<File
RelativePath="ReadMe.txt">
</File>
<File
RelativePath="..\..\..\lib\public\vmpi.lib">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\..\lib\public\vstdlib.lib">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCustomBuildTool"
Description=""
CommandLine=""/>
</FileConfiguration>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>