forked from anqin/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc_client.h
More file actions
96 lines (74 loc) · 3.21 KB
/
rpc_client.h
File metadata and controls
96 lines (74 loc) · 3.21 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
// Copyright (c) 2014 The Trident Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
#ifndef _TRIDENT_RPC_CLIENT_H_
#define _TRIDENT_RPC_CLIENT_H_
#include <trident/common.h>
namespace trident {
// Defined in other files.
class RpcClientImpl;
struct RpcClientOptions {
int work_thread_num; // num of threads used for network handing, default 4.
int callback_thread_num; // num of threads used for async callback, default 4.
int keep_alive_time; // keep alive time of idle connections.
// idle connections will be closed if no read/write for this time.
// in seconds, should >= -1, -1 means for ever, default 65.
int max_pending_buffer_size; // max buffer size of the pending send queue for each connection.
// in MB, should >= 0, 0 means no buffer, default 2.
// Network throughput limit.
// The network bandwidth is shared by all connections:
// * busy connections get more bandwidth.
// * the total bandwidth of all connections will not exceed the limit.
int max_throughput_in; // max network in throughput for all connections.
// in MB/s, should >= -1, -1 means no limit, default -1.
int max_throughput_out; // max network out throughput for all connections.
// in MB/s, should >= -1, -1 means no limit, default -1.
RpcClientOptions()
: work_thread_num(4)
, callback_thread_num(4)
, keep_alive_time(65)
, max_pending_buffer_size(2)
, max_throughput_in(-1)
, max_throughput_out(-1)
{}
};
class RpcClient
{
public:
explicit RpcClient(const RpcClientOptions& options = RpcClientOptions());
virtual ~RpcClient();
// Get the current rpc client options.
RpcClientOptions GetOptions();
// Reset the rpc client options.
//
// Current only these options can be reset (others will be ignored):
// * max_pending_buffer_size : will take effective immediately.
// * max_throughput_in : will take effective from the next time slice (0.1s).
// * max_throughput_out : will take effective from the next time slice (0.1s).
//
// Though you want to reset only part of these options, the other options also
// need to be set. Maybe you can reset by this way:
// RpcClientOptions options = rpc_client->GetOptions();
// options.max_throughput_in = new_max_throughput_in; // reset some options
// rpc_client->ResetOptions(options);
//
// The old and new value of reset options will be print to INFO log.
void ResetOptions(const RpcClientOptions& options);
// Get the count of current alive connections.
int ConnectionCount();
// Shutdown the rpc client.
void Shutdown();
public:
const trident::shared_ptr<RpcClientImpl>& impl() const
{
return _impl;
}
private:
trident::shared_ptr<RpcClientImpl> _impl;
TRIDENT_DISALLOW_EVIL_CONSTRUCTORS(RpcClient);
}; // class RpcClient
} // namespace trident
#endif // _TRIDENT_RPC_CLIENT_H_
/* vim: set ts=4 sw=4 sts=4 tw=100 */