You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ww...@apache.org on 2023/02/06 10:10:42 UTC
[brpc] branch master updated: Revert "Merge pull request #2108 from chenBright/invalid_port"
This is an automated email from the ASF dual-hosted git repository.
wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 96f0f02c Revert "Merge pull request #2108 from chenBright/invalid_port"
96f0f02c is described below
commit 96f0f02c72237b6fb220092fa6f0997dd2920d2e
Author: wwbmmm <ww...@163.com>
AuthorDate: Mon Feb 6 18:09:24 2023 +0800
Revert "Merge pull request #2108 from chenBright/invalid_port"
This reverts commit 14ff36a2cd9257c8f06e87e56cbab7f4cd0c8a3c, reversing
changes made to b502fb7ef11def3dc641692e39c5e7ccce088a6f.
---
src/brpc/server.cpp | 12 ++++--------
test/brpc_server_unittest.cpp | 20 --------------------
2 files changed, 4 insertions(+), 28 deletions(-)
diff --git a/src/brpc/server.cpp b/src/brpc/server.cpp
index bf4227c3..a7db3193 100644
--- a/src/brpc/server.cpp
+++ b/src/brpc/server.cpp
@@ -998,10 +998,6 @@ int Server::StartInternal(const butil::EndPoint& endpoint,
}
_listen_addr = endpoint;
for (int port = port_range.min_port; port <= port_range.max_port; ++port) {
- if (port < 0 || port > 65535) {
- LOG(ERROR) << "Invalid port=" << port;
- return -1;
- }
_listen_addr.port = port;
butil::fd_guard sockfd(tcp_listen(_listen_addr));
if (sockfd < 0) {
@@ -1051,10 +1047,6 @@ int Server::StartInternal(const butil::EndPoint& endpoint,
break; // stop trying
}
if (_options.internal_port >= 0 && _options.has_builtin_services) {
- if (_options.internal_port < 0 || _options.internal_port > 65535) {
- LOG(ERROR) << "Invalid internal port=" << _options.internal_port;
- return -1;
- }
if (_options.internal_port == _listen_addr.port) {
LOG(ERROR) << "ServerOptions.internal_port=" << _options.internal_port
<< " is same with port=" << _listen_addr.port << " to Start()";
@@ -1151,6 +1143,10 @@ int Server::Start(const char* ip_port_str, const ServerOptions* opt) {
}
int Server::Start(int port, const ServerOptions* opt) {
+ if (port < 0 || port > 65535) {
+ LOG(ERROR) << "Invalid port=" << port;
+ return -1;
+ }
return Start(butil::EndPoint(butil::IP_ANY, port), opt);
}
diff --git a/test/brpc_server_unittest.cpp b/test/brpc_server_unittest.cpp
index ce5e0448..c22b6b53 100644
--- a/test/brpc_server_unittest.cpp
+++ b/test/brpc_server_unittest.cpp
@@ -206,32 +206,12 @@ TEST_F(ServerTest, sanity) {
ASSERT_EQ(-1, server.Start(99999, NULL));
ASSERT_EQ(0, server.Start(8613, NULL));
}
-
- {
- brpc::Server server1;
- brpc::PortRange range1(65534, 65535);
- ASSERT_EQ(0, server1.Start(range1, NULL));
-
- brpc::Server server2;
- ASSERT_EQ(0, server2.Start(range1, NULL));
-
- brpc::Server server3;
- ASSERT_EQ(-1, server3.Start(range1, NULL));
-
- brpc::Server server4;
- brpc::PortRange range4(65535, 65536);
- ASSERT_EQ(-1, server4.Start(range4, NULL));
- }
-
{
brpc::Server server;
brpc::ServerOptions options;
options.internal_port = 8613; // The same as service port
ASSERT_EQ(-1, server.Start("127.0.0.1:8613", &options));
ASSERT_FALSE(server.IsRunning()); // Revert server's status
- options.internal_port = 65536; // Invalid port
- ASSERT_EQ(-1, server.Start("127.0.0.1:8613", &options));
- ASSERT_FALSE(server.IsRunning()); // Revert server's status
// And release the listen port
ASSERT_EQ(0, server.Start("127.0.0.1:8613", NULL));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org