Skip to content
Snippets Groups Projects
Commit ff97dd0d authored by dutor's avatar dutor Committed by GitHub
Browse files

Fixed #37: NetworkUtils::getLocalIPs blocked in some occasions (#43)

parent 0e7e84b9
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
--stderr_log_file=stderr.log --stderr_log_file=stderr.log
########## networking ########## ########## networking ##########
# Network device to listen on
--listen_netdev=any
# Port to listen on
--port=3699 --port=3699
# seconds before we close the idle connections, 0 for infinite # seconds before we close the idle connections, 0 for infinite
--client_idle_timeout_secs=0 --client_idle_timeout_secs=0
......
...@@ -9,6 +9,8 @@ add_executable( ...@@ -9,6 +9,8 @@ add_executable(
$<TARGET_OBJECTS:fs_obj> $<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:thread_obj> $<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:parser_obj> $<TARGET_OBJECTS:parser_obj>
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:proc_obj>
) )
target_link_libraries( target_link_libraries(
......
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
* (found in the LICENSE.Apache file in the root directory) * (found in the LICENSE.Apache file in the root directory)
*/ */
#include <signal.h>
#include "base/Base.h" #include "base/Base.h"
#include "network/NetworkUtils.h"
#include <signal.h>
#include "base/Status.h" #include "base/Status.h"
#include "fs/FileUtils.h" #include "fs/FileUtils.h"
#include <thrift/lib/cpp2/server/ThriftServer.h> #include <thrift/lib/cpp2/server/ThriftServer.h>
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
using namespace nebula; using namespace nebula;
using namespace nebula::graph; using namespace nebula::graph;
using namespace nebula::fs; using namespace nebula::fs;
using namespace nebula::network;
static std::unique_ptr<apache::thrift::ThriftServer> gServer; static std::unique_ptr<apache::thrift::ThriftServer> gServer;
...@@ -37,11 +39,21 @@ int main(int argc, char *argv[]) { ...@@ -37,11 +39,21 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
std::string localIP;
{
auto result = NetworkUtils::getIPv4FromDevice(FLAGS_listen_netdev);
if (!result.ok()) {
LOG(ERROR) << result.status();
return EXIT_FAILURE;
}
localIP = std::move(result).value();
}
auto interface = std::make_shared<GraphService>(); auto interface = std::make_shared<GraphService>();
gServer = std::make_unique<apache::thrift::ThriftServer>(); gServer = std::make_unique<apache::thrift::ThriftServer>();
gServer->setInterface(interface); gServer->setInterface(interface);
gServer->setPort(FLAGS_port); gServer->setAddress(localIP, FLAGS_port);
gServer->setReusePort(FLAGS_reuse_port); gServer->setReusePort(FLAGS_reuse_port);
gServer->setIdleTimeout(std::chrono::seconds(FLAGS_client_idle_timeout_secs)); gServer->setIdleTimeout(std::chrono::seconds(FLAGS_client_idle_timeout_secs));
......
...@@ -15,6 +15,7 @@ DEFINE_int32(num_netio_threads, 0, "Number of networking threads, 0 for number o ...@@ -15,6 +15,7 @@ DEFINE_int32(num_netio_threads, 0, "Number of networking threads, 0 for number o
DEFINE_int32(num_accept_threads, 1, "Number of threads to accept incoming connections"); DEFINE_int32(num_accept_threads, 1, "Number of threads to accept incoming connections");
DEFINE_bool(reuse_port, true, "Whether to turn on the SO_REUSEPORT option"); DEFINE_bool(reuse_port, true, "Whether to turn on the SO_REUSEPORT option");
DEFINE_int32(listen_backlog, 1024, "Backlog of the listen socket"); DEFINE_int32(listen_backlog, 1024, "Backlog of the listen socket");
DEFINE_string(listen_netdev, "any", "The network device to listen on");
DEFINE_bool(redirect_stdout, true, "Whether to redirect stdout and stderr to separate files"); DEFINE_bool(redirect_stdout, true, "Whether to redirect stdout and stderr to separate files");
DEFINE_string(stdout_log_file, "graphd-stdout.log", "Destination filename of stdout"); DEFINE_string(stdout_log_file, "graphd-stdout.log", "Destination filename of stdout");
......
...@@ -17,6 +17,7 @@ DECLARE_int32(num_netio_threads); ...@@ -17,6 +17,7 @@ DECLARE_int32(num_netio_threads);
DECLARE_int32(num_accept_threads); DECLARE_int32(num_accept_threads);
DECLARE_bool(reuse_port); DECLARE_bool(reuse_port);
DECLARE_int32(listen_backlog); DECLARE_int32(listen_backlog);
DECLARE_string(listen_netdev);
DECLARE_bool(redirect_stdout); DECLARE_bool(redirect_stdout);
DECLARE_string(stdout_log_file); DECLARE_string(stdout_log_file);
......
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