Commit 035cce37 authored by gejun's avatar gejun

Allow dummy_port to be zero and fix an issue on reading from dummy_server.port

parent 7c28b568
...@@ -36,7 +36,7 @@ DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in src/brpc/options ...@@ -36,7 +36,7 @@ DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in src/brpc/options
DEFINE_int32(depth, 0, "number of loop calls"); DEFINE_int32(depth, 0, "number of loop calls");
// Don't send too frequently in this example // Don't send too frequently in this example
DEFINE_int32(sleep_ms, 100, "milliseconds to sleep after each RPC"); DEFINE_int32(sleep_ms, 100, "milliseconds to sleep after each RPC");
DEFINE_int32(dummy_port, 0, "Launch dummy server at this port"); DEFINE_int32(dummy_port, -1, "Launch dummy server at this port");
bvar::LatencyRecorder g_latency_recorder("client"); bvar::LatencyRecorder g_latency_recorder("client");
...@@ -122,7 +122,7 @@ int main(int argc, char* argv[]) { ...@@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {
} }
} }
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
...@@ -30,7 +30,7 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing"); ...@@ -30,7 +30,7 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing");
DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds"); DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)"); DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
DEFINE_bool(dont_fail, false, "Print fatal when some call failed"); DEFINE_bool(dont_fail, false, "Print fatal when some call failed");
DEFINE_int32(dummy_port, 0, "Launch dummy server at this port"); DEFINE_int32(dummy_port, -1, "Launch dummy server at this port");
DEFINE_string(protocol, "http", "http or h2c"); DEFINE_string(protocol, "http", "http or h2c");
bvar::LatencyRecorder g_latency_recorder("client"); bvar::LatencyRecorder g_latency_recorder("client");
...@@ -106,7 +106,7 @@ int main(int argc, char* argv[]) { ...@@ -106,7 +106,7 @@ int main(int argc, char* argv[]) {
} }
} }
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
...@@ -33,7 +33,7 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing"); ...@@ -33,7 +33,7 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing");
DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds"); DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)"); DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
DEFINE_bool(dont_fail, false, "Print fatal when some call failed"); DEFINE_bool(dont_fail, false, "Print fatal when some call failed");
DEFINE_int32(dummy_port, 0, "Launch dummy server at this port"); DEFINE_int32(dummy_port, -1, "Launch dummy server at this port");
DEFINE_string(http_content_type, "application/json", "Content type of http request"); DEFINE_string(http_content_type, "application/json", "Content type of http request");
std::string g_request; std::string g_request;
...@@ -113,7 +113,7 @@ int main(int argc, char* argv[]) { ...@@ -113,7 +113,7 @@ int main(int argc, char* argv[]) {
} }
g_request.resize(FLAGS_request_size, 'r'); g_request.resize(FLAGS_request_size, 'r');
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
...@@ -36,7 +36,7 @@ DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds"); ...@@ -36,7 +36,7 @@ DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
DEFINE_int32(backup_timeout_ms, -1, "backup timeout in milliseconds"); DEFINE_int32(backup_timeout_ms, -1, "backup timeout in milliseconds");
DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)"); DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
DEFINE_bool(dont_fail, false, "Print fatal when some call failed"); DEFINE_bool(dont_fail, false, "Print fatal when some call failed");
DEFINE_int32(dummy_port, 0, "Launch dummy server at this port"); DEFINE_int32(dummy_port, -1, "Launch dummy server at this port");
DEFINE_string(http_content_type, "application/json", "Content type of http request"); DEFINE_string(http_content_type, "application/json", "Content type of http request");
std::string g_attachment; std::string g_attachment;
...@@ -115,7 +115,7 @@ int main(int argc, char* argv[]) { ...@@ -115,7 +115,7 @@ int main(int argc, char* argv[]) {
g_attachment.resize(FLAGS_attachment_size, 'a'); g_attachment.resize(FLAGS_attachment_size, 'a');
} }
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
...@@ -31,7 +31,7 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing"); ...@@ -31,7 +31,7 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing");
DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds"); DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)"); DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
DEFINE_bool(dont_fail, false, "Print fatal when some call failed"); DEFINE_bool(dont_fail, false, "Print fatal when some call failed");
DEFINE_int32(dummy_port, 0, "Launch dummy server at this port"); DEFINE_int32(dummy_port, -1, "Launch dummy server at this port");
std::string g_request; std::string g_request;
std::string g_attachment; std::string g_attachment;
...@@ -109,7 +109,7 @@ int main(int argc, char* argv[]) { ...@@ -109,7 +109,7 @@ int main(int argc, char* argv[]) {
} }
g_request.resize(FLAGS_request_size, 'r'); g_request.resize(FLAGS_request_size, 'r');
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
...@@ -37,7 +37,7 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing"); ...@@ -37,7 +37,7 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing");
DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds"); DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)"); DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
DEFINE_bool(dont_fail, false, "Print fatal when some call failed"); DEFINE_bool(dont_fail, false, "Print fatal when some call failed");
DEFINE_int32(dummy_port, 0, "Launch dummy server at this port"); DEFINE_int32(dummy_port, -1, "Launch dummy server at this port");
std::string g_request; std::string g_request;
std::string g_attachment; std::string g_attachment;
...@@ -161,7 +161,7 @@ int main(int argc, char* argv[]) { ...@@ -161,7 +161,7 @@ int main(int argc, char* argv[]) {
} }
g_request.resize(FLAGS_request_size, 'r'); g_request.resize(FLAGS_request_size, 'r');
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
...@@ -139,7 +139,7 @@ int main(int argc, char* argv[]) { ...@@ -139,7 +139,7 @@ int main(int argc, char* argv[]) {
} }
LOG(INFO) << "Set " << FLAGS_batch * FLAGS_thread_num << " values"; LOG(INFO) << "Set " << FLAGS_batch * FLAGS_thread_num << " values";
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
...@@ -126,7 +126,7 @@ static long ReadPortOfDummyServer(const char* filename) { ...@@ -126,7 +126,7 @@ static long ReadPortOfDummyServer(const char* filename) {
<< (nr == 0 ? "nothing to read" : berror()); << (nr == 0 ? "nothing to read" : berror());
return -1; return -1;
} }
port_str[sizeof(port_str)-1] = '\0'; port_str[std::min((size_t)nr, sizeof(port_str)-1)] = '\0';
const char* p = port_str; const char* p = port_str;
for (; isspace(*p); ++p) {} for (; isspace(*p); ++p) {}
char* endptr = NULL; char* endptr = NULL;
......
...@@ -1645,7 +1645,7 @@ static pthread_mutex_t g_dummy_server_mutex = PTHREAD_MUTEX_INITIALIZER; ...@@ -1645,7 +1645,7 @@ static pthread_mutex_t g_dummy_server_mutex = PTHREAD_MUTEX_INITIALIZER;
static Server* g_dummy_server = NULL; static Server* g_dummy_server = NULL;
int StartDummyServerAt(int port, ProfilerLinker) { int StartDummyServerAt(int port, ProfilerLinker) {
if (port <= 0 || port >= 65536) { if (port < 0 || port >= 65536) {
LOG(ERROR) << "Invalid port=" << port; LOG(ERROR) << "Invalid port=" << port;
return -1; return -1;
} }
......
...@@ -89,7 +89,7 @@ int main(int argc, char* argv[]) { ...@@ -89,7 +89,7 @@ int main(int argc, char* argv[]) {
GFLAGS_NS::ParseCommandLineFlags(&argc, &argv, true); GFLAGS_NS::ParseCommandLineFlags(&argc, &argv, true);
// set global log option // set global log option
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
...@@ -208,7 +208,7 @@ int main(int argc, char* argv[]) { ...@@ -208,7 +208,7 @@ int main(int argc, char* argv[]) {
return -1; return -1;
} }
if (FLAGS_dummy_port > 0) { if (FLAGS_dummy_port >= 0) {
brpc::StartDummyServerAt(FLAGS_dummy_port); brpc::StartDummyServerAt(FLAGS_dummy_port);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment