2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "anbox/network/published_socket_connector.h"
19 #include "anbox/network/connection_context.h"
20 #include "anbox/network/socket_helper.h"
21 #include "anbox/logger.h"
25 PublishedSocketConnector::PublishedSocketConnector(
26 const std::string& socket_file, const std::shared_ptr<Runtime>& rt,
27 const std::shared_ptr<ConnectionCreator<
28 boost::asio::local::stream_protocol>>& connection_creator)
29 : socket_file_(remove_socket_if_stale(socket_file)),
31 connection_creator_(connection_creator),
32 acceptor_(rt->service(), socket_file_) {
36 PublishedSocketConnector::~PublishedSocketConnector() noexcept {}
38 void PublishedSocketConnector::start_accept() {
39 auto socket = std::make_shared<boost::asio::local::stream_protocol::socket>(runtime_->service());
41 acceptor_.async_accept(*socket,
42 [this, socket](boost::system::error_code const& err) {
43 on_new_connection(socket, err);
47 void PublishedSocketConnector::on_new_connection(std::shared_ptr<boost::asio::local::stream_protocol::socket> const& socket,
48 boost::system::error_code const& err) {
50 connection_creator_->create_connection_for(socket);
52 if (err.value() == boost::asio::error::operation_aborted)
57 } // namespace network