代码拉取完成,页面将自动刷新
/*
* a wrap for non-block socket class for Windows, LINUX and MacOS X platform
*/
#ifndef __SOCKET_H__
#define __SOCKET_H__
#include "ostype.h"
#include "util.h"
enum
{
SOCKET_STATE_IDLE,
SOCKET_STATE_LISTENING,
SOCKET_STATE_CONNECTING,
SOCKET_STATE_CONNECTED,
SOCKET_STATE_CLOSING
};
class CBaseSocket : public CRefObject
{
public:
CBaseSocket();
virtual ~CBaseSocket();
SOCKET GetSocket() { return m_socket; }
void SetSocket(SOCKET fd) { m_socket = fd; }
void SetState(uint8_t state) { m_state = state; }
void SetCallback(callback_t callback) { m_callback = callback; }
void SetCallbackData(void* data) { m_callback_data = data; }
void SetRemoteIP(char* ip) { m_remote_ip = ip; }
void SetRemotePort(uint16_t port) { m_remote_port = port; }
void SetSendBufSize(uint32_t send_size);
void SetRecvBufSize(uint32_t recv_size);
const char* GetRemoteIP() { return m_remote_ip.c_str(); }
uint16_t GetRemotePort() { return m_remote_port; }
const char* GetLocalIP() { return m_local_ip.c_str(); }
uint16_t GetLocalPort() { return m_local_port; }
public:
int Listen(
const char* server_ip,
uint16_t port,
callback_t callback,
void* callback_data);
net_handle_t Connect(
const char* server_ip,
uint16_t port,
callback_t callback,
void* callback_data);
int Send(void* buf, int len);
int Recv(void* buf, int len);
int Close();
public:
void OnRead();
void OnWrite();
void OnClose();
private:
int _GetErrorCode();
bool _IsBlock(int error_code);
void _SetNonblock(SOCKET fd);
void _SetReuseAddr(SOCKET fd);
void _SetNoDelay(SOCKET fd);
void _SetAddr(const char* ip, const uint16_t port, sockaddr_in* pAddr);
void _AcceptNewSocket();
private:
string m_remote_ip;
uint16_t m_remote_port;
string m_local_ip;
uint16_t m_local_port;
callback_t m_callback;
void* m_callback_data;
uint8_t m_state;
SOCKET m_socket;
};
CBaseSocket* FindBaseSocket(net_handle_t fd);
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。