From e1e85ca5ff27a9b8b6ce9a0e6dcbcde8fc126dff Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Wed, 10 Sep 2014 13:46:25 +0300 Subject: [PATCH] core: allow configuring the network stack --- build.mk | 2 +- core/reactor.cc | 20 ++++++++++++++++++++ core/reactor.hh | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/build.mk b/build.mk index dad28e6bdd..566bf941e1 100644 --- a/build.mk +++ b/build.mk @@ -11,7 +11,7 @@ opt.release = -O2 -flto sanitize = $(sanitize.$(mode)) opt = $(opt.$(mode)) -libs = -laio -ltcmalloc +libs = -laio -ltcmalloc -lboost_program_options LDFLAGS = $(libs) diff --git a/core/reactor.cc b/core/reactor.cc index d76aee2c03..232a615957 100644 --- a/core/reactor.cc +++ b/core/reactor.cc @@ -3,6 +3,7 @@ */ #include "reactor.hh" +#include "print.hh" #include #include #include @@ -48,6 +49,12 @@ reactor::reactor() receive_signal(SIGINT).then([this] { _stopped = true; }); } +void reactor::configure(boost::program_options::variables_map vm) { + _networking_stack = vm.count("network-stack") + ? networking_stack_registry::create(sstring(vm["network-stack"].as())) + : networking_stack_registry::create(); +} + future<> reactor::get_epoll_future(pollable_fd_state& pfd, promise<> pollable_fd_state::*pr, int event) { if (pfd.events_known & event) { @@ -476,6 +483,19 @@ networking_stack_registry::create(sstring name) { return _map()[name](); } +boost::program_options::options_description +reactor::get_options_description() { + namespace bpo = boost::program_options; + bpo::options_description opts("Core options"); + auto net_stack_names = networking_stack_registry::list(); + opts.add_options() + ("network-stack", bpo::value(), + sprint("select networking stack (valid values: %s)", + format_separated(net_stack_names.begin(), net_stack_names.end(), ", ")).c_str()) + ; + return opts; +} + networking_stack_registrator nsr_posix{"posix", true}; reactor the_reactor; diff --git a/core/reactor.hh b/core/reactor.hh index 0b5b0a9417..efb9580c9a 100644 --- a/core/reactor.hh +++ b/core/reactor.hh @@ -26,6 +26,7 @@ #include #include #include +#include #include "util/eclipse.hh" #include "future.hh" #include "posix.hh" @@ -354,10 +355,13 @@ private: void abort_on_error(int ret); void complete_timers(); public: + static boost::program_options::options_description get_options_description(); reactor(); reactor(const reactor&) = delete; void operator=(const reactor&) = delete; + void configure(boost::program_options::variables_map config); + server_socket listen(socket_address sa, listen_options opts = {}); pollable_fd posix_listen(socket_address sa, listen_options opts = {});