-
Notifications
You must be signed in to change notification settings - Fork 0
/
SocketCommon.h
62 lines (42 loc) · 1.48 KB
/
SocketCommon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef _SOCKETIioweiofjiowioefioiowioefo_H__
#define _SOCKETIioweiofjiowioefioiowioefo_H__
#ifdef WIN32
#include <windows.h>
#include <winsock.h>
#else
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#endif
class CSocketCommon
{
public:
CSocketCommon();
void SetWriteFlag(bool val) { m_writeFlag = val; }
void SetReadFlag(bool val) { m_readFlag = val; }
int getWriteFlag() const { return m_writeFlag; }
int getReadFlag() const { return m_readFlag; }
CSocketCommon(int socket);
~CSocketCommon();
virtual int Recv(char* buf, int sz) ;
virtual int Send(char* buf, int sz) ;
virtual int CreateSocket(int family, int type, int protocal) ;
virtual int CloseSocket() ;
virtual int Bind(const struct sockaddr* addr) ;
virtual int Listen(int count) ;
virtual int Accept(struct sockaddr* addr) ;
virtual int GetError() ;
virtual int ConnectTo(const struct addrinfo* addr);
int GetSocket() const { return m_socket; }
virtual int KeepAlived(int keepalive, int keepidle, int keepinterval, int keepcount);
private:
bool m_readFlag;
bool m_writeFlag;
int m_socket;
};
#endif