deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 1 | /* |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 2 | * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef P2P_BASE_PACKET_TRANSPORT_INTERNAL_H_ |
| 12 | #define P2P_BASE_PACKET_TRANSPORT_INTERNAL_H_ |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 18 | #include "p2p/base/port.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "rtc_base/async_packet_socket.h" |
| 20 | #include "rtc_base/network_route.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "rtc_base/socket.h" |
Mirko Bonadei | ac19414 | 2018-10-22 17:08:37 +0200 | [diff] [blame] | 22 | #include "rtc_base/system/rtc_export.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 23 | #include "rtc_base/third_party/sigslot/sigslot.h" |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 24 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 25 | namespace rtc { |
| 26 | struct PacketOptions; |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 27 | struct SentPacket; |
| 28 | |
Bjorn A Mellem | 34cd485 | 2019-05-24 10:13:10 -0700 | [diff] [blame^] | 29 | class RTC_EXPORT PacketTransportInternal : public sigslot::has_slots<> { |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 30 | public: |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 31 | virtual const std::string& transport_name() const = 0; |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 32 | |
| 33 | // The transport has been established. |
| 34 | virtual bool writable() const = 0; |
| 35 | |
| 36 | // The transport has received a packet in the last X milliseconds, here X is |
| 37 | // configured by each implementation. |
| 38 | virtual bool receiving() const = 0; |
| 39 | |
| 40 | // Attempts to send the given packet. |
| 41 | // The return value is < 0 on failure. The return value in failure case is not |
| 42 | // descriptive. Depending on failure cause and implementation details |
| 43 | // GetError() returns an descriptive errno.h error value. |
| 44 | // This mimics posix socket send() or sendto() behavior. |
| 45 | // TODO(johan): Reliable, meaningful, consistent error codes for all |
| 46 | // implementations would be nice. |
| 47 | // TODO(johan): Remove the default argument once channel code is updated. |
| 48 | virtual int SendPacket(const char* data, |
| 49 | size_t len, |
| 50 | const rtc::PacketOptions& options, |
| 51 | int flags = 0) = 0; |
| 52 | |
| 53 | // Sets a socket option. Note that not all options are |
| 54 | // supported by all transport types. |
| 55 | virtual int SetOption(rtc::Socket::Option opt, int value) = 0; |
| 56 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 57 | // TODO(pthatcher): Once Chrome's MockPacketTransportInterface implements |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 58 | // this, remove the default implementation. |
Steve Anton | 33f69db | 2017-10-30 10:01:15 -0700 | [diff] [blame] | 59 | virtual bool GetOption(rtc::Socket::Option opt, int* value); |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 60 | |
| 61 | // Returns the most recent error that occurred on this channel. |
| 62 | virtual int GetError() = 0; |
| 63 | |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 64 | // Returns the current network route with transport overhead. |
| 65 | // TODO(zhihuang): Make it pure virtual once the Chrome/remoting is updated. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 66 | virtual absl::optional<NetworkRoute> network_route() const; |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 67 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 68 | // Emitted when the writable state, represented by |writable()|, changes. |
| 69 | sigslot::signal1<PacketTransportInternal*> SignalWritableState; |
| 70 | |
| 71 | // Emitted when the PacketTransportInternal is ready to send packets. "Ready |
| 72 | // to send" is more sensitive than the writable state; a transport may be |
| 73 | // writable, but temporarily not able to send packets. For example, the |
| 74 | // underlying transport's socket buffer may be full, as indicated by |
| 75 | // SendPacket's return code and/or GetError. |
| 76 | sigslot::signal1<PacketTransportInternal*> SignalReadyToSend; |
| 77 | |
| 78 | // Emitted when receiving state changes to true. |
| 79 | sigslot::signal1<PacketTransportInternal*> SignalReceivingState; |
| 80 | |
| 81 | // Signalled each time a packet is received on this channel. |
| 82 | sigslot::signal5<PacketTransportInternal*, |
| 83 | const char*, |
| 84 | size_t, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 85 | // TODO(bugs.webrtc.org/9584): Change to passing the int64_t |
| 86 | // timestamp by value. |
| 87 | const int64_t&, |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 88 | int> |
| 89 | SignalReadPacket; |
| 90 | |
| 91 | // Signalled each time a packet is sent on this channel. |
| 92 | sigslot::signal2<PacketTransportInternal*, const rtc::SentPacket&> |
| 93 | SignalSentPacket; |
deadbeef | 225bfc0 | 2017-04-06 21:47:33 -0700 | [diff] [blame] | 94 | |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 95 | // Signalled when the current network route has changed. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 96 | sigslot::signal1<absl::optional<rtc::NetworkRoute>> SignalNetworkRouteChanged; |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 97 | |
deadbeef | 225bfc0 | 2017-04-06 21:47:33 -0700 | [diff] [blame] | 98 | protected: |
Steve Anton | 33f69db | 2017-10-30 10:01:15 -0700 | [diff] [blame] | 99 | PacketTransportInternal(); |
| 100 | ~PacketTransportInternal() override; |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | } // namespace rtc |
| 104 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 105 | #endif // P2P_BASE_PACKET_TRANSPORT_INTERNAL_H_ |