tcpquery.h
1.13 KB
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
//
// tcpquery.h
//
// Created by cairui01 on 20/05/11.
// Copyright (c) 2020年 baidu. All rights reserved.
//
#ifndef SDT_SRC_CHECKIMPL_TCPQUERY_H_
#define SDT_SRC_CHECKIMPL_TCPQUERY_H_
#include "sdt.h"
#include "mutex.h"
#include "unix_socket.h"
#include "netbuffer.h"
#include "socketselect.h"
class NetCheckTrafficMonitor;
namespace apirequest {
namespace sdt {
class TcpQuery {
enum TcpStatus {
kTcpInit = 0,
kTcpInitErr,
kTcpConnectErr,
kTcpConnected,
kTcpDisConnected,
};
public:
TcpQuery(const char* _ip, uint16_t _port, unsigned int connTimeout, NetCheckTrafficMonitor* trafficMonitor = NULL);
virtual ~TcpQuery();
public:
CheckErrCode tcp_send(const unsigned char* buff, unsigned int unSize, int timeoutMs);
CheckErrCode tcp_receive(NetBuffer& recvBuf, unsigned int unSize, int timeoutMs);
void send_break();
std::string getStatus();
int getErrorCode();
private:
char* ip_;
uint16_t port_;
SOCKET sock_;
SocketBreaker pipe_;
SocketSelect select_;
TcpStatus status_;
int errcode_;
unsigned int conn_timeout_;
};
}}
#endif