Skip to content

Commit ce8cc54

Browse files
authored
[RPC] Report correct port from C++ RPC to tracker. (apache#9642)
1 parent 6c8ed60 commit ce8cc54

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

apps/cpp_rpc/rpc_server.cc

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,33 @@ static std::string getNextString(std::stringstream* iss) {
8686

8787
/*!
8888
* \brief RPCServer RPC Server class.
89+
*
8990
* \param host The hostname of the server, Default=0.0.0.0
90-
* \param port The port of the RPC, Default=9090
91-
* \param port_end The end search port of the RPC, Default=9099
92-
* \param tracker The address of RPC tracker in host:port format e.g. 10.77.1.234:9190 Default=""
93-
* \param key The key used to identify the device type in tracker. Default=""
94-
* \param custom_addr Custom IP Address to Report to RPC Tracker. Default=""
91+
*
92+
* \param port_search_start The low end of the search range for an
93+
* available port for the RPC, Default=9090
94+
*
95+
* \param port_search_end The high search the search range for an
96+
* available port for the RPC, Default=9099
97+
*
98+
* \param tracker The address of RPC tracker in host:port format
99+
* (e.g. "10.77.1.234:9190")
100+
*
101+
* \param key The key used to identify the device type in tracker.
102+
*
103+
* \param custom_addr Custom IP Address to Report to RPC Tracker.
95104
*/
96105
class RPCServer {
97106
public:
98107
/*!
99108
* \brief Constructor.
100109
*/
101-
RPCServer(std::string host, int port, int port_end, std::string tracker_addr, std::string key,
102-
std::string custom_addr, std::string work_dir)
110+
RPCServer(std::string host, int port_search_start, int port_search_end, std::string tracker_addr,
111+
std::string key, std::string custom_addr, std::string work_dir)
103112
: host_(std::move(host)),
104-
port_(port),
113+
port_search_start_(port_search_start),
105114
my_port_(0),
106-
port_end_(port_end),
115+
port_search_end_(port_search_end),
107116
tracker_addr_(std::move(tracker_addr)),
108117
key_(std::move(key)),
109118
custom_addr_(std::move(custom_addr)),
@@ -126,7 +135,7 @@ class RPCServer {
126135
*/
127136
void Start() {
128137
listen_sock_.Create();
129-
my_port_ = listen_sock_.TryBindHost(host_, port_, port_end_);
138+
my_port_ = listen_sock_.TryBindHost(host_, port_search_start_, port_search_end_);
130139
LOG(INFO) << "bind to " << host_ << ":" << my_port_;
131140
listen_sock_.Listen(1);
132141
std::future<void> proc(std::async(std::launch::async, &RPCServer::ListenLoopProc, this));
@@ -140,7 +149,7 @@ class RPCServer {
140149
* \brief ListenLoopProc The listen process.
141150
*/
142151
void ListenLoopProc() {
143-
TrackerClient tracker(tracker_addr_, key_, custom_addr_, port_);
152+
TrackerClient tracker(tracker_addr_, key_, custom_addr_, my_port_);
144153
while (true) {
145154
support::TCPSocket conn;
146155
support::SockAddr addr("0.0.0.0", 0);
@@ -340,9 +349,9 @@ class RPCServer {
340349
}
341350

342351
std::string host_;
343-
int port_;
352+
int port_search_start_;
344353
int my_port_;
345-
int port_end_;
354+
int port_search_end_;
346355
std::string tracker_addr_;
347356
std::string key_;
348357
std::string custom_addr_;

0 commit comments

Comments
 (0)