IOCP服务器压力测试程序

  • I8_557164
    了解作者
  • 6.3MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-25 05:00
    上传日期
利用完成端口来做的一个服务器,来测试服务器的压力测试。
testconnect.rar
  • Debug_Unicode
  • testrunnerd.dll
    370.5KB
  • testconnect.exe
    415.5KB
  • testrunnerud.dll
    371KB
  • testconnect.pdb
    4MB
  • testconnect.ilk
    2MB
  • testconnect
  • Debug_Unicode
  • testrunnerd.dll
    370.5KB
  • vc90.pdb
    956KB
  • vc90.idb
    1.2MB
  • TestApp.obj
    106.7KB
  • VirtualClient.obj
    143.4KB
  • TestFakeserver.obj
    425.9KB
  • BuildLog.htm
    10.3KB
  • Fakeserver.obj
    259.7KB
  • mt.dep
    67B
  • testconnect.obj
    267.2KB
  • TestVirtual.obj
    507.3KB
  • testconnect.exe.embed.manifest
    920B
  • testconnect.exe.embed.manifest.res
    984B
  • Multiconnectserver.obj
    291.7KB
  • testrunnerud.dll
    371KB
  • TestMulticonnectserver.obj
    400.5KB
  • testconnect.exe.intermediate.manifest
    861B
  • Multiconnectserver.cpp
    10.4KB
  • TestApp.h
    271B
  • TestFakeserver.h
    1.1KB
  • VirtualClient.h
    1008B
  • Fakeserver.h
    958B
  • TestMulticonnectserver.cpp
    5.4KB
  • testconnect.h
    638B
  • Fakeserver.cpp
    11.4KB
  • TestMulticonnectserver.h
    1KB
  • testconnect.vcproj.3BE38360F9FA4DE.Administrator.user
    2.6KB
  • TestVirtual.cpp
    166B
  • testconnect.vcproj
    8KB
  • TestApp.cpp
    1KB
  • testconnect.cpp
    218B
  • TestVirtual.h
    8.7KB
  • Multiconnectserver.h
    1.3KB
  • TestFakeserver.cpp
    4.6KB
  • VirtualClient.cpp
    2.2KB
  • testconnect.ncb
    17.4MB
  • testconnect.sln
    1.3KB
内容介绍
#include "FakeServer.h" #include <windows.h> #include <winsock2.h> #include <atlstr.h rel='nofollow' onclick='return false;'> CString m_string; HANDLE m_fEvent_Exit_Conn; typedef struct _Processparam { HANDLE handle; int num; }Processparam; CFakeServer::CFakeServer(void) { serverSocket = NULL; socketNum = 0; m_fEvent_Exit_Conn = CreateEvent(NULL,TRUE,FALSE,NULL); completionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE,NULL,0,0); } CFakeServer::~CFakeServer(void) { } BOOL CFakeServer::CreateSocket() { SOCKADDR_IN addrSrv,addrClinet; memset(&addrSrv,0,sizeof(SOCKADDR_IN)); memset(&addrClinet,0,sizeof(SOCKADDR_IN)); serverSocket = socket(AF_INET, SOCK_STREAM, 0); return TRUE; } DWORD WINAPI CFakeServer::Acceptconnect(LPVOID parm) { SOCKADDR_IN addrClinet; int addrClinetlen = sizeof(addrClinet); //SOCKET sock = accept(pServer->serverSocket, (sockaddr*)&addrClinet, &addrClinetlen); int i=0; CFakeServer *pServer = (CFakeServer*)parm; //int j = 1; while(1) { SOCKET sock = accept(pServer->serverSocket, (sockaddr*)&addrClinet, &addrClinetlen); if (INVALID_SOCKET != sock) { pServer->clientList.push_back(sock); pServer->socketNum++; CHAR c[200]; sprintf(c, "server %d connect succ\r\n",i); OutputDebugString((CString)c); i++; } //else //{ // CHAR c[200]; // sprintf(c, "server %d connect fail\r\n",i); // OutputDebugString(c); // i++; // //Sleep(100); //} } return 0; } //DWORD WINAPI CFakeServer::serverThread(LPVOID lpParm) //{ // char *sendmess = "I received"; // int sendLen = strlen(sendmess); // sockaddr_in addrofSocket; // ULONG u_ip; // int num = 0; // HANDLE handle; // struct in_addr addr1; // // handle = *(HANDLE*)lpParm; // /*Processparam *m_param = (Processparam*)lpParm; // handle = m_param->handle;*/ // if (handle == NULL) // { // return -1; // } // // DWORD dwTrans = 0; // PPER_HANDLE_DATA pPerHandle; // PPER_IO_DATA pPerlo; // // pPerHandle = (PPER_HANDLE_DATA)GlobalAlloc(GPTR, sizeof(PER_HANDLE_DATA)); // pPerlo = (PPER_IO_DATA)GlobalAlloc(GPTR, sizeof(PER_IO_DATA)); // //OVERLAPPED *overlapp; // // CHAR c[200]; // int LEN; // int error; // //sprintf(c, "server %s connect succ\r\n",pPerlo->buf); // //OutputDebugString(sendmess); // // int j = 0; // //Sleep(2000); // // while (true) // { // //if (num == m_param->num) // //{ // // //closesocket(pPerHandle->sock); // // SetEvent(m_fEvent_Exit_Conn); // //} // // bool bRet = GetQueuedCompletionStatus((HANDLE)handle,&dwTrans,(PULONG_PTR)&pPerHandle, // (LPOVERLAPPED*)&pPerlo,WSA_INFINITE);//WSA_INFINITE // int err = GetLastError(); // // if (!bRet) // { // continue; // } // // if (dwTrans == 0) // { // continue; // } // // if(pPerlo->operatorType == OP_READ) // { // pPerlo->buf[dwTrans] = 0; // int len = sizeof(addrofSocket); // getpeername( pPerHandle->sock, ( struct sockaddr* )&addrofSocket, &len ); // u_ip = addrofSocket.sin_addr.s_addr; // memcpy(&addr1,&u_ip,sizeof(ULONG)); // char *pIPAddr = inet_ntoa(addr1); // // m_string += "\""; // m_string += pPerlo->buf; // m_string += "\""; // m_string += "send by"; // m_string += ":"; // m_string += pIPAddr; // m_string += ".\r\n"; // //OutputDebugString(sendmess); // // //CHAR c[200]; // //sprintf(c, "server %d connect succ\r\n",dwTrans); // //OutputDebugString("longliangj"); // //OutputDebugString(pPerlo->buf); // // WSABUF buff; // DWORD dwsend = 0; // DWORD dwsnedflag = 0; // // buff.buf = "I received"; // buff.len = strlen( "I received"); // // memset(pPerlo,0,sizeof(PER_IO_DATA)); // // pPerlo->operatorType = OP_WRITE; // // Sleep(150); // // LEN = WSASend(pPerHandle->sock,&buff,1,&dwsend,dwsnedflag,&(pPerlo->overlap),NULL); // // error = GetLastError(); // //LEN = send((SOCKET)(pPerHandle->sock),"I received",strlen("I received"),0); // if (!LEN) // { // OutputDebugString("I have received\n"); // } // // } // } // //OutputDebugString("I end\n"); // // // return 1; //} BOOL CFakeServer::Aceept() { //HANDLE hThread; DWORD threadId; hThread = CreateThread(NULL,0,this->Acceptconnect, (LPVOID)this, 0, &threadId); if (hThread != NULL) { return true; } else { return false; } } BOOL CFakeServer::Listen(USHORT portval) { SOCKADDR_IN addrSrv; port = portval; addrSrv.sin_addr.S_un.S_addr = htonl(INADDR_ANY); addrSrv.sin_family = AF_INET; addrSrv.sin_port = htons(port); bind(serverSocket, (sockaddr*)&addrSrv, sizeof(addrSrv)); listen(serverSocket,5); return true; } BOOL CFakeServer::processClientConnect() { //HANDLE completionPort; LONG retval; LONG errorval; //Processparam m_processParam; CString m_cstring; /*HANDLE completionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE,NULL,0,0); if (!completionPort) { return FALSE; }*/ //m_processParam = new Processparam; //m_processParam.handle = completionPort; //m_processParam.num = clientList.size(); HANDLE handle = CreateThread(NULL,0,serverThread,(LPVOID)&completionPort,0,0); if (!handle) { return FALSE; } //HANDLE handle1 = CreateThread(NULL,0,serverThread,(LPVOID)&completionPort,0,0); //HANDLE handle2 = CreateThread(NULL,0,serverThread,(LPVOID)&completionPort,0,0); for (size_t n = 0;n<clientList.size();n++) // while(TRUE) { PPER_HANDLE_DATA pPerHandle; SOCKET sock; sock = clientList[n]; /*SOCKADDR_IN addrClinet; int addrClinetlen = sizeof(addrClinet); SOCKET sock = accept(serverSocket, (sockaddr*)&addrClinet, &addrClinetlen);*/ pPerHandle = (PPER_HANDLE_DATA)GlobalAlloc(GPTR, sizeof(PER_HANDLE_DATA)) ; pPerHandle->sock = clientList[n]; //pPerHandle->sock = sock; CreateIoCompletionPort((HANDLE)sock,completionPort,(DWORD)pPerHandle,0); PPER_IO_DATA pioData = (PPER_IO_DATA)GlobalAlloc(GPTR, sizeof(PER_IO_DATA)); ZeroMemory(&(pioData->overlap), sizeof(OVERLAPPED)); pioData->operatorType = OP_READ; WSABUF wsaBuf; wsaBuf.buf = pioData->buf; wsaBuf.len = BUFFER_SIZE; DWORD dwRecvLen; DWORD dwFlag = 0; retval = WSARecv((SOCKET)pPerHandle->sock,&wsaBuf,1,&dwRecvLen,&dwFlag,&pioData->overlap,NULL); if (retval == -1) { errorval = GetLastError(); if (errorval != ERROR_IO_PENDING) return FALSE; } } // errorval = GetLastError(); //Sleep(5000); //WaitForSingleObject(m_fEvent_Exit_Conn,INFINITE); // OutputDebugString(m_string); // m_cstring = m_string; return TRUE; } //CString CFakeServer::processClientConnect() //{ // HANDLE completionPort; // LONG retval; // LONG errorval; // Processparam m_processParam; // CString m_cstring; // // completionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE,NULL,0,0); // // //m_processParam = new Processparam; // m_processParam.handle = completionPort; // m_processParam.num = clientList.size(); // HANDLE handle = CreateThread(NULL,0,serverThread,(LPVOID)&completionPort,0,0); // //HANDLE handle1 = CreateThread(NULL,0,serverThread,(LPVOID)&completionPort,0,0); // //HANDLE handle2 = CreateThread(NULL,0,serverThread,(LPVOID)&completionPort,0,0); // // while (TRUE) // { // SOCKADDR_IN addrClinet; // int addrClinetlen = sizeof(addrClinet); // int i=0; // // //CFakeServer *pServer = (CFakeServer*)parm; // // //int j = 1; // SOCKET sock = accept(serverSocket, (sockaddr*)&addrClinet, &addrClinetlen); // OutputDebugString((CString)"接收成功"); // // PPER_HANDLE_DATA pPerHandle; // //SOCKET sock; // //sock = clientList[n]; // // pPerHandle = (PPER_HANDLE_DATA)GlobalAlloc(GPTR, sizeof(PER_HANDLE_DATA)) ; // //pPerHandle->sock = clientList[n]; // CreateIoCompletionPort((HANDLE)sock,completionPort,(DWORD)pPerHandle,0); // // PPER_IO_DATA pioData = (PPER_IO_DATA)GlobalAlloc(GPTR, sizeof(PER_IO_DATA)); //
评论
    相关推荐