core: allow configuring the network stack

This commit is contained in:
Avi Kivity
2014-09-10 13:46:25 +03:00
parent 82cf2eff7c
commit e1e85ca5ff
3 changed files with 25 additions and 1 deletions

View File

@@ -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)

View File

@@ -3,6 +3,7 @@
*/
#include "reactor.hh"
#include "print.hh"
#include <cassert>
#include <unistd.h>
#include <fcntl.h>
@@ -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<std::string>()))
: 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<std::string>(),
sprint("select networking stack (valid values: %s)",
format_separated(net_stack_names.begin(), net_stack_names.end(), ", ")).c_str())
;
return opts;
}
networking_stack_registrator<posix_networking_stack> nsr_posix{"posix", true};
reactor the_reactor;

View File

@@ -26,6 +26,7 @@
#include <atomic>
#include <boost/lockfree/queue.hpp>
#include <boost/optional.hpp>
#include <boost/program_options.hpp>
#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 = {});