TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / network / stream_socket_transport.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/stream_socket_transport.h"
19 #include "anbox/common/variable_length_array.h"
20 #include "anbox/network/fd_socket_transmission.h"
21
22 #include <system_error>
23
24 #include <errno.h>
25 #include <sys/epoll.h>
26 #include <sys/socket.h>
27 #include <sys/types.h>
28 #include <sys/un.h>
29
30 #include <boost/exception/errinfo_errno.hpp>
31 #include <boost/throw_exception.hpp>
32
33 namespace anbox {
34 namespace network {
35
36 StreamSocketTransport::StreamSocketTransport(const std::string& socket_path,
37                                              const std::shared_ptr<Runtime>& rt)
38     : socket_(std::make_shared<boost::asio::local::stream_protocol::socket>(
39           rt->service())),
40 {
41   socket_.connect(boost::asio::local::stream_protocol::endpoint(socket_path));
42   read_next_message();
43 }
44
45 void StreamSocketTransport::register_observer(
46     std::shared_ptr<Observer> const& observer) {
47   this->observer_ = observer;
48 }
49
50 void StreamSocketTransport::unregister_observer(
51     std::shared_ptr<Observer> const& observer) {
52   if (this->observer_ != observer) return;
53
54   this->observer_.reset();
55 }
56
57 void StreamSocketTransport::send_message(std::vector<uint8_t> const& buffer) {}
58
59 void StreamSocketTransport::read_next_message() {
60   auto callback = std::bind(&StreamSocketTransport::on_read_size, this,
61                             std::placeholders::_1, std::placeholders::_2);
62 }
63
64 void StreamSocketTransport::on_read_size(const boost::system::error_code& ec,
65                                          std::size_t bytes_read) {}
66
67 }  // namespace network
68 }  // namespace anbox