1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-19 09:42:06 +03:00

Test keep-alive in testclient

This commit is contained in:
bel
2015-04-13 21:44:41 +02:00
parent 4aad970422
commit 1d611a7ba5
2 changed files with 46 additions and 8 deletions

View File

@@ -19,6 +19,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ex_websocket_client", "ex_w
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "upload", "upload\upload.vcxproj", "{882EC43C-2EEE-434B-A711-C845678D29C6}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testclient", "..\testutils\testclient\testclient.vcxproj", "{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Browser", "..\testutils\Browser\Browser.vcxproj", "{277772B0-D4B3-451E-86B6-261FBC645793}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
@@ -131,6 +135,26 @@ Global
{882EC43C-2EEE-434B-A711-C845678D29C6}.Release|Win32.ActiveCfg = Release|Win32
{882EC43C-2EEE-434B-A711-C845678D29C6}.Release|Win32.Build.0 = Release|Win32
{882EC43C-2EEE-434B-A711-C845678D29C6}.Release|x64.ActiveCfg = Release|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Debug|Win32.ActiveCfg = Debug|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Debug|Win32.Build.0 = Debug|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Debug|x64.ActiveCfg = Debug|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Release|Mixed Platforms.Build.0 = Release|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Release|Win32.ActiveCfg = Release|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Release|Win32.Build.0 = Release|Win32
{15D6AAA6-36CE-453B-ABBF-3C52BD247EBE}.Release|x64.ActiveCfg = Release|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Debug|Win32.ActiveCfg = Debug|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Debug|Win32.Build.0 = Debug|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Debug|x64.ActiveCfg = Debug|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Release|Mixed Platforms.Build.0 = Release|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Release|Win32.ActiveCfg = Release|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Release|Win32.Build.0 = Release|Win32
{277772B0-D4B3-451E-86B6-261FBC645793}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -4,13 +4,11 @@
#include <time.h>
char * HOST = "127.0.0.1";
unsigned short PORT = 80;
unsigned short PORT = 8080;
static const char * RESOURCELIST[] = {
"/ajax/echo.cgi",
"/hello.txt",
"/imagetest/00.png",
"/args.cgi",
"/_stat",
"/_echo"
"/"
};
static const char * METHODLIST[] = {
"GET",
@@ -55,6 +53,7 @@ static unsigned bad = 0;
unsigned long postSize = 0;
unsigned long extraHeadSize = 0;
unsigned long queryStringSize = 0;
unsigned long keep_alive = 1;
int WINAPI ClientMain(void * clientNo) {
@@ -116,7 +115,7 @@ int WINAPI ClientMain(void * clientNo) {
return 4;
}
for (i=0; i<((keep_alive>0)?keep_alive:1); i++) {
// HTTP request
if (queryStringSize>0) {
sockprintf(soc, "%s %s?", method, resource);
@@ -124,10 +123,15 @@ int WINAPI ClientMain(void * clientNo) {
for (i=0;i<(queryStringSize/10);i++) {sockprintf(soc, "1234567890");}
for (i=0;i<(queryStringSize%10);i++) {sockprintf(soc, "_");}
sockprintf(soc, " HTTP/1.1\r\nHost: %s\r\nConnection: Close\r\n", HOST);
sockprintf(soc, " HTTP/1.1\r\nHost: %s\r\n", HOST);
} else {
sockprintf(soc, "%s %s HTTP/1.1\r\nHost: %s\r\nConnection: Close\r\n", method, resource, HOST);
}
if (keep_alive) {
sockprintf(soc, "Connection: Keep-Alive\r\n");
} else {
sockprintf(soc, "Connection: Close\r\n");
}
for (i=0;i<(extraHeadSize/25);i++) {sockprintf(soc, "Comment%04u: 1234567890\r\n", i % 10000);} /* omit (extraHeadSize%25) */
@@ -143,9 +147,14 @@ int WINAPI ClientMain(void * clientNo) {
timeOut += postSize/10000;
}
shutdown(soc, SD_SEND);
if (!keep_alive) {
shutdown(soc, SD_SEND);
} else {
timeOut = 2;
}
// wait for response from the server
totalData = 0;
lastData = time(0);
for (;;) {
char buf[2048];
@@ -183,6 +192,11 @@ int WINAPI ClientMain(void * clientNo) {
}
}
if (keep_alive) {
Sleep(1000);
}
}
shutdown(soc, SD_BOTH);
closesocket(soc);