⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iocpapi.cpp

📁 基于完成端口的TCP网络通信框架实现 工程iocp中包含了框架实现的所有代码
💻 CPP
字号:

#include "iocp.h"
using std::pair;

/****************************************
             IOCPAPI SERVER
****************************************/

//
// Server Implementation class
//
class IOCPImplServer:public MsgIOCPServer
{
public:
  IOCPImplServer(IOCPNetServer *iocp,unsigned short port)
    :MsgIOCPServer(port)
  {
    miocp=iocp;
  }
protected:
  virtual void msg_open_handler(SOCKET s);
  virtual void msg_closed_handler(SOCKET s);
  virtual void msg_message_handler(SOCKET s,NetMessage *msg);
  virtual void msg_illegal_handler(SOCKET s,int msglen);
private:
  IOCPNetServer *miocp;
};
inline void IOCPImplServer::msg_open_handler(SOCKET s)
{
  miocp->iocp_open_handler(s);
}
inline void IOCPImplServer::msg_closed_handler(SOCKET s)
{
  miocp->iocp_closed_handler(s);
}
inline void IOCPImplServer::msg_message_handler(SOCKET s,NetMessage *msg)
{
  miocp->iocp_message_handler(s,msg);
}
inline void IOCPImplServer::msg_illegal_handler(SOCKET s,int msglen)
{
  miocp->iocp_illegal_handler(s,msglen);
}

//
// Server interface class
//
IOCPNetServer::IOCPNetServer(unsigned short listenport)
{
  mimpl=new IOCPImplServer(this,listenport);
}
IOCPNetServer::~IOCPNetServer()
{
  delete mimpl;
}
void IOCPNetServer::start()
{
  mimpl->start();
}
void IOCPNetServer::stop()
{
  mimpl->stop();
}
void IOCPNetServer::runloop()
{
  mimpl->runloop();
}
void IOCPNetServer::close(SOCKET s)
{
  mimpl->close(s);
}
void IOCPNetServer::sendmessage(SOCKET s,NetMessage *m)
{
  mimpl->sendmessage(s,m);
}

/****************************************
            IOCPAPI CLIENT
****************************************/
//
// Client Implementation class
//
class IOCPImplClient:public MsgIOCPClient
{
public:
  IOCPImplClient(IOCPNetClient *iocp)
  {
    miocp=iocp;
  }
protected:
  virtual void msg_open_handler(SOCKET s);
  virtual void msg_closed_handler(SOCKET s);
  virtual void msg_message_handler(SOCKET s,NetMessage *msg);
  virtual void msg_illegal_handler(SOCKET s,int msglen);
private:
  IOCPNetClient *miocp;
};
inline void IOCPImplClient::msg_open_handler(SOCKET s)
{
  miocp->iocp_open_handler(s);
}
inline void IOCPImplClient::msg_closed_handler(SOCKET s)
{
  miocp->iocp_closed_handler(s);
}
inline void IOCPImplClient::msg_message_handler(SOCKET s,NetMessage *msg)
{
  miocp->iocp_message_handler(s,msg);
}
inline void IOCPImplClient::msg_illegal_handler(SOCKET s,int msglen)
{
  miocp->iocp_illegal_handler(s,msglen);
}

//
// Client interface class
//
IOCPNetClient::IOCPNetClient()
{
  mimpl=new IOCPImplClient(this);
}
IOCPNetClient::~IOCPNetClient()
{
  delete mimpl;
}
void IOCPNetClient::start()
{
  mimpl->start();
}
void IOCPNetClient::stop()
{
  mimpl->stop();
}
void IOCPNetClient::runloop()
{
  mimpl->runloop();
}
void IOCPNetClient::close(SOCKET s)
{
  mimpl->close(s);
}
void IOCPNetClient::sendmessage(SOCKET s,NetMessage *m)
{
  mimpl->sendmessage(s,m);
}
bool IOCPNetClient::connect(const char *dotip,unsigned short port,SOCKET *s)
{
  return mimpl->connect(dotip,port,s);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -