TCPChannelResourceBasic.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #ifndef _FASTDDS_TCP_CHANNEL_RESOURCE_BASIC_
  15. #define _FASTDDS_TCP_CHANNEL_RESOURCE_BASIC_
  16. #include <asio.hpp>
  17. #include <fastdds/rtps/transport/TCPChannelResource.h>
  18. namespace eprosima{
  19. namespace fastdds{
  20. namespace rtps{
  21. class TCPChannelResourceBasic : public TCPChannelResource
  22. {
  23. asio::io_service& service_;
  24. std::shared_ptr<asio::ip::tcp::socket> socket_;
  25. public:
  26. // Constructor called when trying to connect to a remote server
  27. TCPChannelResourceBasic(
  28. TCPTransportInterface* parent,
  29. asio::io_service& service,
  30. const fastrtps::rtps::Locator_t& locator,
  31. uint32_t maxMsgSize);
  32. // Constructor called when local server accepted connection
  33. TCPChannelResourceBasic(
  34. TCPTransportInterface* parent,
  35. asio::io_service& service,
  36. std::shared_ptr<asio::ip::tcp::socket> socket,
  37. uint32_t maxMsgSize);
  38. virtual ~TCPChannelResourceBasic();
  39. void connect(
  40. const std::shared_ptr<TCPChannelResource>& myself) override;
  41. void disconnect() override;
  42. uint32_t read(
  43. fastrtps::rtps::octet* buffer,
  44. std::size_t size,
  45. asio::error_code& ec) override;
  46. size_t send(
  47. const fastrtps::rtps::octet* header,
  48. size_t header_size,
  49. const fastrtps::rtps::octet* data,
  50. size_t size,
  51. asio::error_code& ec) override;
  52. asio::ip::tcp::endpoint remote_endpoint() const override;
  53. asio::ip::tcp::endpoint local_endpoint() const override;
  54. void set_options(const TCPTransportDescriptor* options) override;
  55. void cancel() override;
  56. void close() override;
  57. void shutdown(asio::socket_base::shutdown_type what) override;
  58. inline std::shared_ptr<asio::ip::tcp::socket> socket()
  59. {
  60. return socket_;
  61. }
  62. private:
  63. TCPChannelResourceBasic(const TCPChannelResourceBasic&) = delete;
  64. TCPChannelResourceBasic& operator=(const TCPChannelResourceBasic&) = delete;
  65. };
  66. } // namespace rtps
  67. } // namespace fastdds
  68. } // namespace eprosima
  69. #endif // _FASTDDS_TCP_CHANNEL_RESOURCE_BASIC_