-
Notifications
You must be signed in to change notification settings - Fork 0
/
t_client.hpp
95 lines (81 loc) · 1.97 KB
/
t_client.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
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
/**
* @file: t_client.hpp
* @brief:
* tcp client 实现文件,采用多线程connect & send/recv 数据
* 每个线程去connect tcp server. 每个线程内可重复发送多次。
* 线程数和收发次数 参数化输入
*
* @author: wusheng Hu
* @version: v0x0001
* @date: 2018-04-19
*/
#ifndef _T_CLIENT_HPP_
#define _T_CLIENT_HPP_
#ifdef __cplusplus
extern "C" {
#endif
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#ifdef __cplusplus
}
#endif
#include <vector>
#include <iostream>
#include <string>
#include "t_thread.hpp"
#include "t_proto.hpp"
using namespace T_TCP;
using namespace std;
namespace T_CLIENT
{
/**
* @brief: 一个客户端实现,其实也是一个线程的实现
* 包括常规的connect, recv/send 接口的实现
*/
class TestOneClient: public PthreadBase
{
public:
TestOneClient(const std::string& sRemoteIp, int iRemotePort, int iSendTimes);
virtual ~TestOneClient();
protected:
int main();
virtual int Init();
private:
std::string m_sRemoteIp;
int m_iRemotePort;
int m_iTestNums;
int m_iFd;
struct sockaddr_in m_stDestAddr;
BusiCodec* m_pCodec;
};
//////////////////////////
/**
* @brief:
* 包括命令解析和多个client 实例的创建和启动。
*/
class TestClient
{
public:
TestClient(int argc, char **argv);
virtual ~TestClient();
int main();
private:
void Usage(const char *pBinName);
bool ParseCmd(int argc, char **argv);
private:
bool m_bOk;
int m_iClientNums;
std::string m_sRemoteIp;
int m_iRemotePort;
int m_iReqNums;
};
}
#endif