/src/Fast-DDS/src/cpp/rtps/transport/TCPChannelResourceBasic.h
Line | Count | Source |
1 | | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef _FASTDDS_TCP_CHANNEL_RESOURCE_BASIC_ |
16 | | #define _FASTDDS_TCP_CHANNEL_RESOURCE_BASIC_ |
17 | | |
18 | | #include <mutex> |
19 | | #include <asio.hpp> |
20 | | #include <rtps/transport/TCPChannelResource.h> |
21 | | |
22 | | namespace eprosima { |
23 | | namespace fastdds { |
24 | | namespace rtps { |
25 | | |
26 | | class TCPChannelResourceBasic : public TCPChannelResource |
27 | | { |
28 | | asio::io_context& context_; |
29 | | |
30 | | std::mutex send_mutex_; |
31 | | std::mutex read_mutex_; |
32 | | std::shared_ptr<asio::ip::tcp::socket> socket_; |
33 | | |
34 | | public: |
35 | | |
36 | | // Constructor called when trying to connect to a remote server |
37 | | TCPChannelResourceBasic( |
38 | | TCPTransportInterface* parent, |
39 | | asio::io_context& context, |
40 | | const Locator& locator, |
41 | | uint32_t maxMsgSize); |
42 | | |
43 | | // Constructor called when local server accepted connection |
44 | | TCPChannelResourceBasic( |
45 | | TCPTransportInterface* parent, |
46 | | asio::io_context& context, |
47 | | std::shared_ptr<asio::ip::tcp::socket> socket, |
48 | | uint32_t maxMsgSize); |
49 | | |
50 | | virtual ~TCPChannelResourceBasic(); |
51 | | |
52 | | void connect( |
53 | | const std::shared_ptr<TCPChannelResource>& myself) override; |
54 | | |
55 | | void disconnect() override; |
56 | | |
57 | | uint32_t read( |
58 | | octet* buffer, |
59 | | std::size_t size, |
60 | | asio::error_code& ec) override; |
61 | | |
62 | | size_t send( |
63 | | const octet* header, |
64 | | size_t header_size, |
65 | | const std::vector<NetworkBuffer>& buffers, |
66 | | uint32_t total_bytes, |
67 | | asio::error_code& ec) override; |
68 | | |
69 | | // Throwing asio calls |
70 | | asio::ip::tcp::endpoint remote_endpoint() const override; |
71 | | asio::ip::tcp::endpoint local_endpoint() const override; |
72 | | |
73 | | // Non-throwing asio calls |
74 | | asio::ip::tcp::endpoint remote_endpoint( |
75 | | asio::error_code& ec) const override; |
76 | | asio::ip::tcp::endpoint local_endpoint( |
77 | | asio::error_code& ec) const override; |
78 | | |
79 | | void set_options( |
80 | | const TCPTransportDescriptor* options) override; |
81 | | |
82 | | void cancel() override; |
83 | | void close() override; |
84 | | void shutdown( |
85 | | asio::socket_base::shutdown_type what) override; |
86 | | |
87 | | inline std::shared_ptr<asio::ip::tcp::socket> socket() |
88 | 0 | { |
89 | 0 | return socket_; |
90 | 0 | } |
91 | | |
92 | | private: |
93 | | |
94 | | TCPChannelResourceBasic( |
95 | | const TCPChannelResourceBasic&) = delete; |
96 | | TCPChannelResourceBasic& operator =( |
97 | | const TCPChannelResourceBasic&) = delete; |
98 | | }; |
99 | | |
100 | | |
101 | | } // namespace rtps |
102 | | } // namespace fastdds |
103 | | } // namespace eprosima |
104 | | |
105 | | #endif // _FASTDDS_TCP_CHANNEL_RESOURCE_BASIC_ |