mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-24 22:45:17 +02:00
streaming app for stress testing ssh transport
This commit is contained in:
parent
d4938e3cc4
commit
03f9475b85
152
contrib/win32/prototypes/WinsockClient/WinsockClient.vcxproj
Normal file
152
contrib/win32/prototypes/WinsockClient/WinsockClient.vcxproj
Normal file
@ -0,0 +1,152 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{FB6C3DD6-8AE3-4115-8178-95646161878C}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>WinsockClient</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
<ProjectName>sock-app</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>st</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="sock-app.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="sock-app.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
225
contrib/win32/prototypes/WinsockClient/sock-app.cpp
Normal file
225
contrib/win32/prototypes/WinsockClient/sock-app.cpp
Normal file
@ -0,0 +1,225 @@
|
||||
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
|
||||
#pragma comment (lib, "Ws2_32.lib")
|
||||
#pragma comment (lib, "Mswsock.lib")
|
||||
#pragma comment (lib, "AdvApi32.lib")
|
||||
|
||||
|
||||
#define DEFAULT_BUFLEN 512*1024 //512 KB
|
||||
char recvbuf[DEFAULT_BUFLEN];
|
||||
char sendbuf[DEFAULT_BUFLEN];
|
||||
bool keep_going = true;
|
||||
__int64 rec_bytes = 0, sent_bytes = 0;
|
||||
bool server = true;
|
||||
|
||||
|
||||
void prep_send_buf()
|
||||
{
|
||||
int *buf = (int*)sendbuf;
|
||||
for (int i = 0; i < DEFAULT_BUFLEN; i += sizeof(int))
|
||||
*buf++ = rand();
|
||||
}
|
||||
|
||||
SOCKET ConnectSocket = INVALID_SOCKET;
|
||||
|
||||
DWORD WINAPI RecvThread(
|
||||
_In_ LPVOID lpParameter
|
||||
) {
|
||||
int rec = 1;
|
||||
while (keep_going && (rec>0)) {
|
||||
rec = recv(ConnectSocket, recvbuf, DEFAULT_BUFLEN, 0);
|
||||
rec_bytes += rec;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD WINAPI SendThread(
|
||||
_In_ LPVOID lpParameter
|
||||
) {
|
||||
int rec = 1, rnd;
|
||||
while (keep_going && (rec>0)) {
|
||||
rnd = rand();
|
||||
rec = send(ConnectSocket, sendbuf + rnd, DEFAULT_BUFLEN - rnd, 0);
|
||||
sent_bytes += rec;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __cdecl main(int argc, char **argv)
|
||||
{
|
||||
WSADATA wsaData;
|
||||
|
||||
struct addrinfo *result = NULL,
|
||||
*ptr = NULL,
|
||||
hints;
|
||||
|
||||
int iResult;
|
||||
|
||||
|
||||
// Validate the parameters
|
||||
if ((argc < 2) || (strlen(argv[1]) > 1)) {
|
||||
printf("usage: %s [c|s] IP port\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argv[1][0] == 'c')
|
||||
server = false;
|
||||
|
||||
// Initialize Winsock
|
||||
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (iResult != 0) {
|
||||
printf("WSAStartup failed with error: %d\n", iResult);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
|
||||
// Resolve the server address and port
|
||||
iResult = getaddrinfo(argv[2], argv[3], &hints, &result);
|
||||
if (iResult != 0) {
|
||||
printf("getaddrinfo failed with error: %d\n", iResult);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!server) {
|
||||
// Attempt to connect to an address until one succeeds
|
||||
for (ptr = result; ptr != NULL; ptr = ptr->ai_next) {
|
||||
|
||||
// Create a SOCKET for connecting to server
|
||||
ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype,
|
||||
ptr->ai_protocol);
|
||||
if (ConnectSocket == INVALID_SOCKET) {
|
||||
printf("socket failed with error: %ld\n", WSAGetLastError());
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Connect to server.
|
||||
iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
|
||||
if (iResult == SOCKET_ERROR) {
|
||||
closesocket(ConnectSocket);
|
||||
ConnectSocket = INVALID_SOCKET;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (ConnectSocket == INVALID_SOCKET) {
|
||||
printf("Unable to connect to server!\n");
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
SOCKET ListenSocket;
|
||||
// Create a SOCKET for connecting to server
|
||||
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
|
||||
if (ListenSocket == INVALID_SOCKET) {
|
||||
printf("socket failed with error: %ld\n", WSAGetLastError());
|
||||
freeaddrinfo(result);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Setup the TCP listening socket
|
||||
iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
|
||||
if (iResult == SOCKET_ERROR) {
|
||||
printf("bind failed with error: %d\n", WSAGetLastError());
|
||||
freeaddrinfo(result);
|
||||
closesocket(ListenSocket);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
iResult = listen(ListenSocket, SOMAXCONN);
|
||||
if (iResult == SOCKET_ERROR) {
|
||||
printf("listen failed with error: %d\n", WSAGetLastError());
|
||||
closesocket(ListenSocket);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Accept a client socket
|
||||
ConnectSocket = accept(ListenSocket, NULL, NULL);
|
||||
if (ConnectSocket == INVALID_SOCKET) {
|
||||
printf("accept failed with error: %d\n", WSAGetLastError());
|
||||
closesocket(ListenSocket);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
// No longer need server socket
|
||||
closesocket(ListenSocket);
|
||||
|
||||
|
||||
}
|
||||
|
||||
freeaddrinfo(result);
|
||||
|
||||
HANDLE rt = CreateThread(NULL, 0, RecvThread, NULL, 0, NULL);
|
||||
if (rt == NULL) {
|
||||
printf("Unable to create read thread!\n");
|
||||
closesocket(ConnectSocket);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
HANDLE wt = CreateThread(NULL, 0, SendThread, NULL, 0, NULL);
|
||||
if (wt == NULL) {
|
||||
printf("Unable to create send thread!\n");
|
||||
closesocket(ConnectSocket);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
HANDLE timer = CreateWaitableTimer(NULL, FALSE, NULL);
|
||||
if (timer == NULL){
|
||||
printf("Unable to create timer!\n");
|
||||
closesocket(ConnectSocket);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
LARGE_INTEGER liDueTime;
|
||||
liDueTime.QuadPart = 0;
|
||||
if(!SetWaitableTimer(timer, &liDueTime, 2000, NULL, NULL, false)) {
|
||||
printf("Unable to set timer!\n");
|
||||
closesocket(ConnectSocket);
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("\t Recv(Kb/s) \t\t Sent(Kb/s)\n");
|
||||
__int64 last_recv = 0;
|
||||
__int64 last_send = 0;
|
||||
while (1) {
|
||||
if (WAIT_OBJECT_0 != WaitForSingleObject(timer, INFINITE)) {
|
||||
printf("wait failed %d\n", GetLastError());
|
||||
break;
|
||||
}
|
||||
__int64 now_recv = rec_bytes;
|
||||
__int64 now_send = sent_bytes;
|
||||
|
||||
printf("\r\t %lld \t\t %lld", (now_recv - last_recv) / 2048, (now_send - last_send) / 2048);
|
||||
last_recv = now_recv;
|
||||
last_send = now_send;
|
||||
|
||||
}
|
||||
|
||||
closesocket(ConnectSocket);
|
||||
WSACleanup();
|
||||
|
||||
return 0;
|
||||
}
|
28
contrib/win32/prototypes/prototypes.sln
Normal file
28
contrib/win32/prototypes/prototypes.sln
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinsockClient", "WinsockClient\WinsockClient.vcxproj", "{FB6C3DD6-8AE3-4115-8178-95646161878C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FB6C3DD6-8AE3-4115-8178-95646161878C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{FB6C3DD6-8AE3-4115-8178-95646161878C}.Debug|x64.Build.0 = Debug|x64
|
||||
{FB6C3DD6-8AE3-4115-8178-95646161878C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{FB6C3DD6-8AE3-4115-8178-95646161878C}.Debug|x86.Build.0 = Debug|Win32
|
||||
{FB6C3DD6-8AE3-4115-8178-95646161878C}.Release|x64.ActiveCfg = Release|x64
|
||||
{FB6C3DD6-8AE3-4115-8178-95646161878C}.Release|x64.Build.0 = Release|x64
|
||||
{FB6C3DD6-8AE3-4115-8178-95646161878C}.Release|x86.ActiveCfg = Release|Win32
|
||||
{FB6C3DD6-8AE3-4115-8178-95646161878C}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
x
Reference in New Issue
Block a user