2 * Copyright © 2013-2014 Canonical Ltd.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * 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: Kevin DuBois <kevin.dubois@canonical.com>
19 #ifndef ANBOX_NETWORK_BASE_SOCKET_MESSENGER_H_
20 #define ANBOX_NETWORK_BASE_SOCKET_MESSENGER_H_
22 #include "anbox/common/fd_sets.h"
23 #include "anbox/network/socket_messenger.h"
25 #include <boost/asio.hpp>
30 template <typename stream_protocol>
31 class BaseSocketMessenger : public SocketMessenger {
34 std::shared_ptr<boost::asio::basic_stream_socket<stream_protocol>> const&
36 virtual ~BaseSocketMessenger();
38 Credentials creds() const override;
39 unsigned short local_port() const override;
41 void send(char const* data, size_t length) override;
42 ssize_t send_raw(char const* data, size_t length) override;
43 void async_receive_msg(AnboxReadHandler const& handle,
44 boost::asio::mutable_buffers_1 const& buffer) override;
45 boost::system::error_code receive_msg(
46 boost::asio::mutable_buffers_1 const& buffer) override;
47 size_t available_bytes() override;
49 void set_no_delay() override;
50 void close() override;
53 BaseSocketMessenger();
54 void setup(std::shared_ptr<
55 boost::asio::basic_stream_socket<stream_protocol>> const& s);
58 std::shared_ptr<boost::asio::basic_stream_socket<stream_protocol>> socket;
60 std::mutex message_lock;
62 } // namespace network