CMNetwork/inc/hgl/network/ServerSocket.h

52 lines
2.2 KiB
C
Raw Normal View History

2022-05-25 19:03:06 +08:00
#ifndef HGL_NETWORK_ThisSocket_INCLUDE
#define HGL_NETWORK_ThisSocket_INCLUDE
#include<hgl/network/Socket.h>
namespace hgl
{
namespace network
{
/**
* Socket共用基类
*/
class ServerSocket ///服务器端Socket共用基类
{
protected:
int ThisSocket;
IPAddress *server_address;
virtual int CreateServerSocket()=0; ///<创建Server Socket
public:
ServerSocket();
virtual ~ServerSocket();
const IPAddress *GetServerAddress()const{return server_address;} ///<取得服务器IP地址
IPAddress *CreateIPAddress()const
{return server_address?server_address->Create():nullptr;} ///<创建一个空的IP地址空间
bool CreateIPAddress(IPAddress **ip_buffer,int count)const; ///<创建多个空的IP地址空间
virtual bool CreateServer(const IPAddress *,const uint ml=HGL_SERVER_LISTEN_COUNT,bool reuse=false); ///<创建服务器
virtual void CloseServer(); ///<关闭服务器
/**
* 使
* @param block 使(true/false)
* @param sto (: )
* @param rto (: )
*/
void SetBlock(bool block,double sto=HGL_NETWORK_TIME_OUT,
double rto=HGL_NETWORK_TIME_OUT) ///<设置是否使用堵塞方式
{
SetSocketBlock(ThisSocket,block,sto,rto);
}
bool SetIPv6Only(bool); ///<设置仅使用IPv6
};//class ServerSocket
}//namespace network
}//namespace hgl
#endif//HGL_NETWORK_ThisSocket_INCLUDE