-
Notifications
You must be signed in to change notification settings - Fork 0
/
t_socket.hpp
57 lines (53 loc) · 1.05 KB
/
t_socket.hpp
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
/**
* @file: t_socket.hpp
* @brief:
* @author: wusheng Hu
* @version: v0x0001
* @date: 2018-04-23
*/
#ifndef _t_socket_hpp_
#define _t_socket_hpp_
//
#include <netinet/tcp.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
//
#include <iostream>
#include <string>
//
namespace T_TCP
{
#define SOCK_OK (0)
#define SOCK_AGAIN (0)
#define SOCK_ERR errno
class Sock
{
public:
Sock(const std::string &sIp, int iPort);
virtual ~Sock();
int GetSockFd();
bool Listen();
bool Connect();
int SockAccept(struct sockaddr* pClientAddr);
int Send(const char* pSendBuf, int iLen);
int Recv(char* pRcvBuf, int iMaxLen);
int GerErr();
private:
bool SetSockOpt();
int CreateSock();
void SetErr(int err);
private:
std::string m_sSrvIp;
int m_iSrvPort;
int m_iFd;
int m_err;
};
}
#endif