sdt.h
2.24 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// sdt.h
//
// Created by cairui01 on 18/11/9.
// Copyright (c) 2018年 baidu. All rights reserved.
//
#ifndef SDT_INTERFACE_SDT_H_
#define SDT_INTERFACE_SDT_H_
#include <stdlib.h>
#include <stdint.h>
#include <map>
#include <string>
#include <vector>
namespace apirequest {
namespace sdt {
struct CheckResultProfile;
struct CheckIPPort {
CheckIPPort() {
Reset();
}
CheckIPPort(std::string _ip, uint16_t _port)
: ip(_ip), port(_port){}
bool operator < (const CheckIPPort& _rhs) const {
return ip < _rhs.ip;
}
CheckIPPort& operator = (const CheckIPPort& _rhs) {
ip = _rhs.ip;
port = _rhs.port;
return (*this);
}
void Reset() {
ip.clear();
port = 0;
}
std::string ip;
uint16_t port;
};
typedef std::map< std::string, std::vector<CheckIPPort> > CheckIPPorts;
typedef std::map< std::string, std::vector<CheckIPPort> >::iterator CheckIPPorts_Iterator;
#define DEFAULT_PING_HOST "mbd.baidu.com"
#define DEFAULT_PING_COUNT (2) // times
// For DNS
#define DEFAULT_DNS_TIMEOUT (3*1000) // 3000ms
// For net check timeout
#define UNUSE_TIMEOUT (INT_MAX) // ms
// For Log
#define SDT_LOG "### sdt-log:"
#define SDT_ALTER_INTERFACE_LOG "### sdt-log-bind-interface:"
enum NetCheckStatus {
kNone = 0,
kChecking = 1,
kCheckEnd,
};
enum NetCheckType {
kPingCheck = 0,
kDnsCheck = 1,
kHttpDnsCheck,
kTracertCheck,
kTcpCheck
};
enum CheckErrCode {
kCheckOK = 0,
kTCPNonErr = 1,
kSendDnsQueryError = -1,
kReceiveDnsQueryError = -2,
kDnsUnknownHostError = -3,
kDnsError = -4,
kDnsUDPSocketError = -5,
kDnsNoDnsServer = -6,
kPingGetDefaultGatewayError = -7,
kPingDestHostIsNullError = -8,
kPingInitICMPError = -9,
kPingReadWriteError = -10,
kPingLossRateError = -11,
kTCPSelectErr = -12,
kTCPPipeIntr = -13,
kTCPSndRcvErr = -14,
kTCPAssertErr = -15,
kTCPTimeoutErr = -16,
kTCPSelectExpErr = -17,
kTCPPipeExp = -18,
kTCPConnectErr = -19,
kTCPRespErr = -20,
kBindInterfaceErr = -21
};
enum CheckStatus {
kCheckContinue = 0,
kCheckFinish = 1,
} ;
extern void (*ReportNetCheckResult)(const std::vector<CheckResultProfile>& _check_results);
}}
#endif