forked from enpengxu/libiocp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
enpeng xu
committed
Jul 12, 2012
1 parent
7fddd2f
commit c027235
Showing
50 changed files
with
4,394 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type='text/xsl' href='_UpgradeReport_Files/UpgradeReport.xslt'?><UpgradeLog> | ||
<Properties><Property Name="Solution" Value="iocp"> | ||
</Property><Property Name="Solution File" Value="C:\working\iocp\examples\iocp.sln"> | ||
</Property><Property Name="Date" Value="Wednesday, July 11, 2012"> | ||
</Property><Property Name="Time" Value="20:36 PM"> | ||
</Property></Properties><Event ErrorLevel="0" Project="" Source="iocp.sln" Description="File successfully backed up as C:\working\iocp\examples\iocp.sln.old"> | ||
</Event><Event ErrorLevel="0" Project="server" Source="server\server.vcproj" Description="Converting project file 'C:\working\iocp\examples\server\server.vcproj'."> | ||
</Event><Event ErrorLevel="1" Project="server" Source="server\server.vcproj" Description="VCWebServiceProxyGeneratorTool is no longer supported. The tool has been removed from your project settings."> | ||
</Event><Event ErrorLevel="1" Project="server" Source="server\server.vcproj" Description="MSB8012: $(TargetName) ('server') does not match the Linker's OutputFile property value 'C:\working\iocp\examples\bin\server_d.exe' ('server_d') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetName) property value matches the value specified in %(Link.OutputFile)."> | ||
</Event><Event ErrorLevel="1" Project="server" Source="server\server.vcproj" Description="MSB8012: $(TargetPath) ('C:\working\iocp\examples\bin\server.exe') does not match the Linker's OutputFile property value 'C:\working\iocp\examples\bin\server_d.exe' ('C:\working\iocp\examples\bin\server_d.exe') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetPath) property value matches the value specified in %(Link.OutputFile)."> | ||
</Event><Event ErrorLevel="0" Project="server" Source="server\server.vcproj" Description="Done converting to new project file 'C:\working\iocp\examples\server\server.vcxproj'."> | ||
</Event><Event ErrorLevel="3" Project="server" Source="server\server.vcproj" Description="Converted"> | ||
</Event><Event ErrorLevel="0" Project="client" Source="client\client.vcproj" Description="Converting project file 'C:\working\iocp\examples\client\client.vcproj'."> | ||
</Event><Event ErrorLevel="1" Project="client" Source="client\client.vcproj" Description="VCWebServiceProxyGeneratorTool is no longer supported. The tool has been removed from your project settings."> | ||
</Event><Event ErrorLevel="1" Project="client" Source="client\client.vcproj" Description="MSB8012: $(TargetName) ('client') does not match the Linker's OutputFile property value 'C:\working\iocp\examples\bin\client_d.exe' ('client_d') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetName) property value matches the value specified in %(Link.OutputFile)."> | ||
</Event><Event ErrorLevel="1" Project="client" Source="client\client.vcproj" Description="MSB8012: $(TargetPath) ('C:\working\iocp\examples\bin\client.exe') does not match the Linker's OutputFile property value 'C:\working\iocp\examples\bin\client_d.exe' ('C:\working\iocp\examples\bin\client_d.exe') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetPath) property value matches the value specified in %(Link.OutputFile)."> | ||
</Event><Event ErrorLevel="0" Project="client" Source="client\client.vcproj" Description="Done converting to new project file 'C:\working\iocp\examples\client\client.vcxproj'."> | ||
</Event><Event ErrorLevel="3" Project="client" Source="client\client.vcproj" Description="Converted"> | ||
</Event><Event ErrorLevel="0" Project="" Source="iocp.sln" Description="Solution converted successfully"> | ||
</Event><Event ErrorLevel="3" Project="" Source="iocp.sln" Description="Converted"> | ||
</Event></UpgradeLog> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// client.cpp : Defines the entry point for the console application. | ||
// | ||
#include "sglib/iocp/iocp_client.h" | ||
#include "sglib/iocp/iocp_loop.h" | ||
#include "sglib/thread/sglib_thread.h" | ||
|
||
#include <windows.h> | ||
#define sleep //Sleep(10) | ||
|
||
#define RECV_BUF_LEN 512 | ||
|
||
typedef struct { | ||
int id; | ||
char * buf; | ||
int buf_len; | ||
int recv_count; | ||
FILE * pf; | ||
}session_data_t; | ||
|
||
class client_loop : public sglib::net::iocp_loop<client_loop> | ||
{ | ||
friend class sglib::net::iocp_loop<client_loop>; | ||
protected: | ||
|
||
void on_connected() { | ||
session_data_t * sdata = new session_data_t; | ||
memset(sdata, 0, sizeof(session_data_t)); | ||
sdata->id = _session->get_id(); | ||
sdata->buf_len = RECV_BUF_LEN; | ||
sdata->buf = new char [sdata->buf_len]; | ||
|
||
std::cout << "\nsession["<< sdata->id<<"] NET_connected"; | ||
|
||
char path[128]; | ||
sprintf(path, "test\\client_session_%d.txt", sdata->id); | ||
sdata->pf = fopen(path, "w"); | ||
_session->set_session_data(sdata); | ||
_session->recv(sdata->buf, RECV_BUF_LEN); | ||
sleep; | ||
} | ||
void on_disconnected() { | ||
session_data_t * sdata = (session_data_t *)_session->get_session_data(); | ||
std::cout << "\nsession["<< sdata->id <<"] NET_disconnected"; | ||
if(sdata->pf) // too many files opened, maybe failed | ||
fclose(sdata->pf); | ||
|
||
delete sdata; | ||
delete _session; //!!! | ||
|
||
if (0 == connections()) | ||
quit_loop(true); | ||
sleep; | ||
} | ||
void on_send_finished() { | ||
assert(0); | ||
} | ||
|
||
void on_recv_finished() { | ||
session_data_t * sdata = (session_data_t *)_session->get_session_data(); | ||
std::cout << "\nsession["<< sdata->id <<"] NET_recv_finished"; | ||
|
||
if(sdata->pf) // too many files opened, maybe failed | ||
fwrite(sdata->buf, 1, _pack.pack_size, sdata->pf); | ||
if (strcmp(sdata->buf, "quit") == 0) | ||
quit_cur_session(); //_session->quit(); | ||
else {//continue receive | ||
_session->recv(sdata->buf, sdata->buf_len); | ||
sleep; | ||
} | ||
} | ||
void on_recv_failed(){ | ||
// buf's size is not enough! | ||
session_data_t * sdata = (session_data_t *)_session->get_session_data(); | ||
int pack_size = _pack.pack_size; | ||
|
||
ASSERT(pack_size > sdata->buf_len); | ||
sdata->buf_len = pack_size * 2; | ||
delete []sdata->buf; | ||
sdata->buf = new char[sdata->buf_len] ; | ||
_session->recv(sdata->buf, sdata->buf_len); | ||
} | ||
|
||
void on_send_error() { | ||
std::cout << "\nsession["<< _session->get_id()<<"] NET_send_error"; | ||
sleep; | ||
} | ||
void on_recv_error() { | ||
std::cout << "\nsession["<< _session->get_id()<<"] NET_recv_error"; | ||
sleep; | ||
} | ||
void on_protocal_error(){ | ||
std::cout << "\n ******* session["<< _session->get_id()<<"] NET_protocol_error ******"; | ||
sleep; | ||
} | ||
void on_noop(){ | ||
} | ||
void on_unhandled() { | ||
std::cout << "\nsession["<< _session->get_id()<<"] **** NET_unhandled ! ****"; | ||
} | ||
}; | ||
|
||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
int port = 5001; | ||
|
||
// create the package queue first. | ||
// server or clients will create io threads to read or write data from the queue. | ||
// the loop also read & remove items from the queue. | ||
// server and client are the producer of the queue | ||
// the loop is the consumer of the queue | ||
// so the queue should be created first and be deleted at last! | ||
sglib::net::msg_queue::init(); | ||
|
||
sglib::net::iocp_client client("127.0.0.1", port); | ||
client_loop loop; | ||
loop.init(); | ||
|
||
if (!client.open()) { // 5000 clients | ||
client.close(); | ||
return 0; | ||
} | ||
if(false== client.sessions_open(1)){ | ||
client.close(); | ||
return 0; | ||
} | ||
|
||
int count = 0; | ||
int quit = 0; | ||
|
||
while(true){ | ||
if(loop.isquit()) | ||
break; | ||
if(!loop.peek()){ | ||
continue; | ||
} | ||
if(!loop.tick()) | ||
break; | ||
} | ||
sglib::net::msg_queue::get_singleton()->quit(); // release consumer & producer threads. | ||
client.close(); | ||
sglib::net::msg_queue::get_singleton()->deref(); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
<?xml version="1.0" encoding="gb2312"?> | ||
<VisualStudioProject | ||
ProjectType="Visual C++" | ||
Version="9.00" | ||
Name="client" | ||
ProjectGUID="{F686FA56-5C37-42D4-9C7F-38EAB42A423D}" | ||
RootNamespace="client" | ||
Keyword="Win32Proj" | ||
TargetFrameworkVersion="196613" | ||
> | ||
<Platforms> | ||
<Platform | ||
Name="Win32" | ||
/> | ||
</Platforms> | ||
<ToolFiles> | ||
</ToolFiles> | ||
<Configurations> | ||
<Configuration | ||
Name="Debug|Win32" | ||
OutputDirectory="$(SolutionDir)bin" | ||
IntermediateDirectory="$(ConfigurationName)" | ||
ConfigurationType="1" | ||
CharacterSet="1" | ||
> | ||
<Tool | ||
Name="VCPreBuildEventTool" | ||
/> | ||
<Tool | ||
Name="VCCustomBuildTool" | ||
/> | ||
<Tool | ||
Name="VCXMLDataGeneratorTool" | ||
/> | ||
<Tool | ||
Name="VCWebServiceProxyGeneratorTool" | ||
/> | ||
<Tool | ||
Name="VCMIDLTool" | ||
/> | ||
<Tool | ||
Name="VCCLCompilerTool" | ||
Optimization="0" | ||
AdditionalIncludeDirectories=""$(LIB_SGLIB)"" | ||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" | ||
MinimalRebuild="true" | ||
BasicRuntimeChecks="3" | ||
RuntimeLibrary="3" | ||
UsePrecompiledHeader="0" | ||
WarningLevel="3" | ||
DebugInformationFormat="4" | ||
/> | ||
<Tool | ||
Name="VCManagedResourceCompilerTool" | ||
/> | ||
<Tool | ||
Name="VCResourceCompilerTool" | ||
/> | ||
<Tool | ||
Name="VCPreLinkEventTool" | ||
/> | ||
<Tool | ||
Name="VCLinkerTool" | ||
OutputFile="$(OutDir)\$(ProjectName)_d.exe" | ||
LinkIncremental="2" | ||
AdditionalLibraryDirectories="$(LIB_BOOST)\build_libs\lib" | ||
GenerateDebugInformation="true" | ||
SubSystem="1" | ||
TargetMachine="1" | ||
/> | ||
<Tool | ||
Name="VCALinkTool" | ||
/> | ||
<Tool | ||
Name="VCManifestTool" | ||
/> | ||
<Tool | ||
Name="VCXDCMakeTool" | ||
/> | ||
<Tool | ||
Name="VCBscMakeTool" | ||
/> | ||
<Tool | ||
Name="VCFxCopTool" | ||
/> | ||
<Tool | ||
Name="VCAppVerifierTool" | ||
/> | ||
<Tool | ||
Name="VCPostBuildEventTool" | ||
/> | ||
</Configuration> | ||
<Configuration | ||
Name="Release|Win32" | ||
OutputDirectory="$(SolutionDir)$(ConfigurationName)" | ||
IntermediateDirectory="$(ConfigurationName)" | ||
ConfigurationType="1" | ||
CharacterSet="1" | ||
WholeProgramOptimization="1" | ||
> | ||
<Tool | ||
Name="VCPreBuildEventTool" | ||
/> | ||
<Tool | ||
Name="VCCustomBuildTool" | ||
/> | ||
<Tool | ||
Name="VCXMLDataGeneratorTool" | ||
/> | ||
<Tool | ||
Name="VCWebServiceProxyGeneratorTool" | ||
/> | ||
<Tool | ||
Name="VCMIDLTool" | ||
/> | ||
<Tool | ||
Name="VCCLCompilerTool" | ||
Optimization="2" | ||
EnableIntrinsicFunctions="true" | ||
AdditionalIncludeDirectories=""$(LIB_SGLIB)";"$(LIB_BOOST)"" | ||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" | ||
RuntimeLibrary="2" | ||
EnableFunctionLevelLinking="true" | ||
UsePrecompiledHeader="0" | ||
WarningLevel="3" | ||
DebugInformationFormat="3" | ||
/> | ||
<Tool | ||
Name="VCManagedResourceCompilerTool" | ||
/> | ||
<Tool | ||
Name="VCResourceCompilerTool" | ||
/> | ||
<Tool | ||
Name="VCPreLinkEventTool" | ||
/> | ||
<Tool | ||
Name="VCLinkerTool" | ||
LinkIncremental="1" | ||
AdditionalLibraryDirectories="$(LIB_BOOST)\build_libs\lib" | ||
GenerateDebugInformation="true" | ||
SubSystem="1" | ||
OptimizeReferences="2" | ||
EnableCOMDATFolding="2" | ||
TargetMachine="1" | ||
/> | ||
<Tool | ||
Name="VCALinkTool" | ||
/> | ||
<Tool | ||
Name="VCManifestTool" | ||
/> | ||
<Tool | ||
Name="VCXDCMakeTool" | ||
/> | ||
<Tool | ||
Name="VCBscMakeTool" | ||
/> | ||
<Tool | ||
Name="VCFxCopTool" | ||
/> | ||
<Tool | ||
Name="VCAppVerifierTool" | ||
/> | ||
<Tool | ||
Name="VCPostBuildEventTool" | ||
/> | ||
</Configuration> | ||
</Configurations> | ||
<References> | ||
</References> | ||
<Files> | ||
<Filter | ||
Name="Source Files" | ||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" | ||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" | ||
> | ||
<File | ||
RelativePath=".\client.cpp" | ||
> | ||
</File> | ||
</Filter> | ||
<Filter | ||
Name="Header Files" | ||
Filter="h;hpp;hxx;hm;inl;inc;xsd" | ||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" | ||
> | ||
</Filter> | ||
<Filter | ||
Name="Resource Files" | ||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" | ||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" | ||
> | ||
</Filter> | ||
</Files> | ||
<Globals> | ||
</Globals> | ||
</VisualStudioProject> |
Oops, something went wrong.