de251bc772c3c9f2ccc78e073f6e4033ba323d17
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / network / local_socket_messenger.cpp
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
3  *
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.
7  *
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.
12  *
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/>.
15  *
16  */
17
18 #include "anbox/network/local_socket_messenger.h"
19 #include "anbox/logger.h"
20 #include "anbox/network/socket_helper.h"
21 #include "anbox/utils.h"
22
23 #include <boost/system/error_code.hpp>
24
25 namespace anbox {
26 namespace network {
27 LocalSocketMessenger::LocalSocketMessenger(
28     std::shared_ptr<boost::asio::local::stream_protocol::socket> const &socket)
29     : BaseSocketMessenger(socket) {}
30
31 LocalSocketMessenger::LocalSocketMessenger(const std::string &path,
32                                            const std::shared_ptr<Runtime> &rt)
33     : socket_(std::make_shared<boost::asio::local::stream_protocol::socket>(
34           rt->service())) {
35   boost::system::error_code err;
36   socket_->connect(boost::asio::local::stream_protocol::endpoint(path), err);
37   if (err) {
38     const auto msg = utils::string_format("Failed to connect to socket %s: %s",
39                                           path, err.message());
40     BOOST_THROW_EXCEPTION(std::runtime_error(msg));
41   }
42
43   setup(socket_);
44 }
45
46 LocalSocketMessenger::~LocalSocketMessenger() {}
47 }  // namespace network
48 }  // namespace anbox