packet_transport_internal.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2017 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef P2P_BASE_PACKET_TRANSPORT_INTERNAL_H_
  11. #define P2P_BASE_PACKET_TRANSPORT_INTERNAL_H_
  12. #include <string>
  13. #include <vector>
  14. #include "absl/types/optional.h"
  15. #include "p2p/base/port.h"
  16. #include "rtc_base/async_packet_socket.h"
  17. #include "rtc_base/network_route.h"
  18. #include "rtc_base/socket.h"
  19. #include "rtc_base/system/rtc_export.h"
  20. #include "rtc_base/third_party/sigslot/sigslot.h"
  21. namespace rtc {
  22. struct PacketOptions;
  23. struct SentPacket;
  24. class RTC_EXPORT PacketTransportInternal : public sigslot::has_slots<> {
  25. public:
  26. virtual const std::string& transport_name() const = 0;
  27. // The transport has been established.
  28. virtual bool writable() const = 0;
  29. // The transport has received a packet in the last X milliseconds, here X is
  30. // configured by each implementation.
  31. virtual bool receiving() const = 0;
  32. // Attempts to send the given packet.
  33. // The return value is < 0 on failure. The return value in failure case is not
  34. // descriptive. Depending on failure cause and implementation details
  35. // GetError() returns an descriptive errno.h error value.
  36. // This mimics posix socket send() or sendto() behavior.
  37. // TODO(johan): Reliable, meaningful, consistent error codes for all
  38. // implementations would be nice.
  39. // TODO(johan): Remove the default argument once channel code is updated.
  40. virtual int SendPacket(const char* data,
  41. size_t len,
  42. const rtc::PacketOptions& options,
  43. int flags = 0) = 0;
  44. // Sets a socket option. Note that not all options are
  45. // supported by all transport types.
  46. virtual int SetOption(rtc::Socket::Option opt, int value) = 0;
  47. // TODO(pthatcher): Once Chrome's MockPacketTransportInterface implements
  48. // this, remove the default implementation.
  49. virtual bool GetOption(rtc::Socket::Option opt, int* value);
  50. // Returns the most recent error that occurred on this channel.
  51. virtual int GetError() = 0;
  52. // Returns the current network route with transport overhead.
  53. // TODO(zhihuang): Make it pure virtual once the Chrome/remoting is updated.
  54. virtual absl::optional<NetworkRoute> network_route() const;
  55. // Emitted when the writable state, represented by |writable()|, changes.
  56. sigslot::signal1<PacketTransportInternal*> SignalWritableState;
  57. // Emitted when the PacketTransportInternal is ready to send packets. "Ready
  58. // to send" is more sensitive than the writable state; a transport may be
  59. // writable, but temporarily not able to send packets. For example, the
  60. // underlying transport's socket buffer may be full, as indicated by
  61. // SendPacket's return code and/or GetError.
  62. sigslot::signal1<PacketTransportInternal*> SignalReadyToSend;
  63. // Emitted when receiving state changes to true.
  64. sigslot::signal1<PacketTransportInternal*> SignalReceivingState;
  65. // Signalled each time a packet is received on this channel.
  66. sigslot::signal5<PacketTransportInternal*,
  67. const char*,
  68. size_t,
  69. // TODO(bugs.webrtc.org/9584): Change to passing the int64_t
  70. // timestamp by value.
  71. const int64_t&,
  72. int>
  73. SignalReadPacket;
  74. // Signalled each time a packet is sent on this channel.
  75. sigslot::signal2<PacketTransportInternal*, const rtc::SentPacket&>
  76. SignalSentPacket;
  77. // Signalled when the current network route has changed.
  78. sigslot::signal1<absl::optional<rtc::NetworkRoute>> SignalNetworkRouteChanged;
  79. // Signalled when the transport is closed.
  80. sigslot::signal1<PacketTransportInternal*> SignalClosed;
  81. protected:
  82. PacketTransportInternal();
  83. ~PacketTransportInternal() override;
  84. };
  85. } // namespace rtc
  86. #endif // P2P_BASE_PACKET_TRANSPORT_INTERNAL_H_