1 Star 0 Fork 24

yeyanhong/socket

forked from eclipser/socket 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Socket.h 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
Administrator 提交于 2014-02-25 11:58 . 封装SocketApi 到 C++类中
/*
* File: Socket.h
* Author: Vicky.H
* Email: eclipser@163.com
*
* Created on 2014年2月25日, 上午11:34
*/
#ifndef CN_VICKY__SOCKET_H
#define CN_VICKY__SOCKET_H
#include "SocketAPI.h"
typedef unsigned long IP_t;
const int IP_SIZE = 24;
class Socket {
public:
// constructor
Socket();
Socket(const char* host, unsigned int port);
// destructor
virtual ~Socket();
public:
bool create();
// close connection
void close();
// try connect to remote host
bool connect();
bool connect(const char* host, unsigned int port);
// close previous connection and connect to another socket
bool reconnect(const char* host, unsigned int port);
// send data to peer
unsigned int send(const void* buf, unsigned int len, unsigned int flags = 0);
// receive data from peer
unsigned int receive(void* buf, unsigned int len, unsigned int flags = 0);
unsigned int available()const;
SOCKET accept(struct sockaddr* addr, unsigned int* addrlen);
bool bind();
bool bind(unsigned int port);
bool listen(int backlog);
public:
// get/set socket's linger status
unsigned int getLinger()const;
bool setLinger(unsigned int lingertime);
bool isReuseAddr()const;
bool setReuseAddr(bool on = true);
// get is Error
unsigned int getSockError()const;
// get/set socket's nonblocking status
bool isNonBlocking()const;
bool setNonBlocking(bool on = true);
// get/set receive buffer size
unsigned int getReceiveBufferSize()const;
bool setReceiveBufferSize(unsigned int size);
// get/set send buffer size
unsigned int getSendBufferSize()const;
bool setSendBufferSize(unsigned int size);
unsigned int getPort()const;
IP_t getHostIP()const;
// check if socket is valid
bool isValid()const;
// get socket descriptor
SOCKET getSOCKET()const;
bool isSockError()const;
public:
SOCKET m_SocketID;
// socket address structure
SOCKADDR_IN m_SockAddr;
// peer host
char m_Host[IP_SIZE];
// peer port
unsigned int m_Port;
};
#endif /* CN_VICKY__SOCKET_H */
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/ye-yanhong/socket.git
git@gitee.com:ye-yanhong/socket.git
ye-yanhong
socket
socket
master

搜索帮助