2 * Copyright © 2012-2014 Canonical Ltd.
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,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
19 #ifndef ANBOX_NETWORK_SOCKET_CONNECTION_H_
20 #define ANBOX_NETWORK_SOCKET_CONNECTION_H_
22 #include "anbox/network/connections.h"
23 #include "anbox/network/message_processor.h"
24 #include "anbox/network/message_receiver.h"
25 #include "anbox/network/message_sender.h"
27 #include <boost/asio.hpp>
29 #include <sys/types.h>
33 class SocketConnection {
36 std::shared_ptr<MessageReceiver> const& message_receiver,
37 std::shared_ptr<MessageSender> const& message_sender, int id,
38 std::shared_ptr<Connections<SocketConnection>> const& connections,
39 std::shared_ptr<MessageProcessor> const& processor);
41 ~SocketConnection() noexcept;
43 void set_name(const std::string& name) { name_ = name; }
45 int id() const { return id_; }
47 void send(char const* data, size_t length);
48 void read_next_message();
51 void on_read_size(const boost::system::error_code& ec,
52 std::size_t bytes_read);
54 std::shared_ptr<MessageReceiver> const message_receiver_;
55 std::shared_ptr<MessageSender> const message_sender_;
57 std::shared_ptr<Connections<SocketConnection>> const connections_;
58 std::shared_ptr<MessageProcessor> processor_;
59 std::array<std::uint8_t, 8192> buffer_;
63 } // namespace network