文件名称:sf_200562516252
介绍说明--下载内容来自于网络,使用问题请自行百度
一个线程驰的类, 下面的是基本的使用方法 struct TSession { SOCKET socket int id } class myIocp:public CIOCP { public: void OnRead(void * p, char * buf, int len) void OnAccept(SOCKET socket) void OnClose(void * p) } void myIocp::OnAccept(SOCKET socket) { TSession *s = new TSession s->socket = socket //这里可以对连接的session进行自己的操作,例如给id找一个唯一的值 SetIoCompletionPort(socket, s) // 使连接socket与一个自定义结构体关联 } void myIocp::OnRead(void * p, char * buf, int len) { TSession *s = (TSession *)p send(s->socket, buf, len, 0) // 这里只是简单的把收到的消息返回给客户端 ... } void myIocp::OnClose(void * p) { delete p } myIoncp iocp main() { ... iocp.listen(4311) // 开始监听网络端口,等待客户端连接 ... }-A class for thread pool,basic usage below:
struct TSession { SOCKET socket int id } class myIocp:public CIOCP
{ public:
void OnRead(void * p, char * buf, int len)
void OnAccept(SOCKET socket)
void OnClose(void * p) }
void myIocp::OnAccept(SOCKET socket)
{ TSession *s = new TSession s->socket = socket
//here you can do something about connection session,such as find a unique id.
SetIoCompletionPort(socket, s)
// make connection socket associate with a custom structure }
void myIocp::OnRead(void * p, char * buf, int len)
{ TSession *s = (TSession *)p send(s->socket, buf, len, 0)
// return received message to client
void myIocp::OnClose(void * p) { delete p } myIoncp iocp main() { ... iocp.listen(4311)
//start listenning net port,wait for client connect.
struct TSession { SOCKET socket int id } class myIocp:public CIOCP
{ public:
void OnRead(void * p, char * buf, int len)
void OnAccept(SOCKET socket)
void OnClose(void * p) }
void myIocp::OnAccept(SOCKET socket)
{ TSession *s = new TSession s->socket = socket
//here you can do something about connection session,such as find a unique id.
SetIoCompletionPort(socket, s)
// make connection socket associate with a custom structure }
void myIocp::OnRead(void * p, char * buf, int len)
{ TSession *s = (TSession *)p send(s->socket, buf, len, 0)
// return received message to client
void myIocp::OnClose(void * p) { delete p } myIoncp iocp main() { ... iocp.listen(4311)
//start listenning net port,wait for client connect.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
IOCP.cpp
IOCP.h
IOCP.h
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.