blob: 3dc27d58fd78bd17d462aa849cb8b3d06989ee97 [file] [log] [blame]
deadbeef9e0bedc2017-02-10 19:31:501/*
deadbeefad5d1e62017-02-26 02:15:092 * Copyright 2017 The WebRTC Project Authors. All rights reserved.
deadbeef9e0bedc2017-02-10 19:31:503 *
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
11#ifndef WEBRTC_P2P_BASE_PACKETTRANSPORTINTERNAL_H_
12#define WEBRTC_P2P_BASE_PACKETTRANSPORTINTERNAL_H_
13
14#include <string>
15#include <vector>
16
17// This is included for PacketOptions.
deadbeef9f932992017-04-07 04:47:3318#include "webrtc/api/ortc/packettransportinterface.h"
Edward Lemur76de83e2017-07-06 17:44:3419#include "webrtc/rtc_base/asyncpacketsocket.h"
20#include "webrtc/rtc_base/sigslot.h"
21#include "webrtc/rtc_base/socket.h"
deadbeef9e0bedc2017-02-10 19:31:5022
23namespace cricket {
24class TransportChannel;
25}
26
27namespace rtc {
28struct PacketOptions;
29struct PacketTime;
30struct SentPacket;
31
deadbeef9f932992017-04-07 04:47:3332class PacketTransportInternal : public virtual webrtc::PacketTransportInterface,
33 public sigslot::has_slots<> {
deadbeef9e0bedc2017-02-10 19:31:5034 public:
deadbeef9e0bedc2017-02-10 19:31:5035 // Identify the object for logging and debug purpose.
36 virtual std::string debug_name() const = 0;
37
38 // The transport has been established.
39 virtual bool writable() const = 0;
40
41 // The transport has received a packet in the last X milliseconds, here X is
42 // configured by each implementation.
43 virtual bool receiving() const = 0;
44
45 // Attempts to send the given packet.
46 // The return value is < 0 on failure. The return value in failure case is not
47 // descriptive. Depending on failure cause and implementation details
48 // GetError() returns an descriptive errno.h error value.
49 // This mimics posix socket send() or sendto() behavior.
50 // TODO(johan): Reliable, meaningful, consistent error codes for all
51 // implementations would be nice.
52 // TODO(johan): Remove the default argument once channel code is updated.
53 virtual int SendPacket(const char* data,
54 size_t len,
55 const rtc::PacketOptions& options,
56 int flags = 0) = 0;
57
58 // Sets a socket option. Note that not all options are
59 // supported by all transport types.
60 virtual int SetOption(rtc::Socket::Option opt, int value) = 0;
61
deadbeefad5d1e62017-02-26 02:15:0962 // TODO(pthatcher): Once Chrome's MockPacketTransportInterface implements
deadbeef9e0bedc2017-02-10 19:31:5063 // this, remove the default implementation.
64 virtual bool GetOption(rtc::Socket::Option opt, int* value) { return false; }
65
66 // Returns the most recent error that occurred on this channel.
67 virtual int GetError() = 0;
68
69 // Emitted when the writable state, represented by |writable()|, changes.
70 sigslot::signal1<PacketTransportInternal*> SignalWritableState;
71
72 // Emitted when the PacketTransportInternal is ready to send packets. "Ready
73 // to send" is more sensitive than the writable state; a transport may be
74 // writable, but temporarily not able to send packets. For example, the
75 // underlying transport's socket buffer may be full, as indicated by
76 // SendPacket's return code and/or GetError.
77 sigslot::signal1<PacketTransportInternal*> SignalReadyToSend;
78
79 // Emitted when receiving state changes to true.
80 sigslot::signal1<PacketTransportInternal*> SignalReceivingState;
81
82 // Signalled each time a packet is received on this channel.
83 sigslot::signal5<PacketTransportInternal*,
84 const char*,
85 size_t,
86 const rtc::PacketTime&,
87 int>
88 SignalReadPacket;
89
90 // Signalled each time a packet is sent on this channel.
91 sigslot::signal2<PacketTransportInternal*, const rtc::SentPacket&>
92 SignalSentPacket;
deadbeef9f932992017-04-07 04:47:3393
94 protected:
95 PacketTransportInternal* GetInternal() override { return this; }
deadbeef9e0bedc2017-02-10 19:31:5096};
97
98} // namespace rtc
99
100#endif // WEBRTC_P2P_BASE_PACKETTRANSPORTINTERNAL_H_