• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 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 
11 #ifndef WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_WRAPPER_H_
12 #define WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_WRAPPER_H_
13 
14 #include "webrtc/test/channel_transport/udp_transport.h"
15 
16 namespace webrtc {
17 
18 class EventWrapper;
19 
20 namespace test {
21 
22 class UdpSocketManager;
23 
24 #define SOCKET_ERROR_NO_QOS -1000
25 
26 #ifndef _WIN32
27 typedef int SOCKET;
28 #endif
29 
30 #ifndef INVALID_SOCKET
31 #define INVALID_SOCKET  (SOCKET)(~0)
32 
33 #ifndef AF_INET
34 #define AF_INET 2
35 #endif
36 
37 #endif
38 
39 typedef void* CallbackObj;
40 typedef void(*IncomingSocketCallback)(CallbackObj obj, const int8_t* buf,
41                                       int32_t len, const SocketAddress* from);
42 
43 class UdpSocketWrapper
44 {
45 public:
46     static UdpSocketWrapper* CreateSocket(const int32_t id,
47                                           UdpSocketManager* mgr,
48                                           CallbackObj obj,
49                                           IncomingSocketCallback cb,
50                                           bool ipV6Enable = false,
51                                           bool disableGQOS = false);
52 
53     // Set the unique identifier of this class to id.
54     virtual int32_t ChangeUniqueId(const int32_t id) = 0;
55 
56     // Register cb for receiving callbacks when there are incoming packets.
57     // Register obj so that it will be passed in calls to cb.
58     virtual bool SetCallback(CallbackObj obj, IncomingSocketCallback cb) = 0;
59 
60     // Socket to local address specified by name.
61     virtual bool Bind(const SocketAddress& name) = 0;
62 
63     // Start receiving UDP data.
64     virtual bool StartReceiving();
65     virtual bool StartReceiving(const uint32_t /*receiveBuffers*/);
66     // Stop receiving UDP data.
67     virtual bool StopReceiving();
68 
69     virtual bool ValidHandle() = 0;
70 
71     // Set socket options.
72     virtual bool SetSockopt(int32_t level, int32_t optname,
73                             const int8_t* optval, int32_t optlen) = 0;
74 
75     // Set TOS for outgoing packets.
76     virtual int32_t SetTOS(const int32_t serviceType) = 0;
77 
78     // Set 802.1Q PCP field (802.1p) for outgoing VLAN traffic.
79     virtual int32_t SetPCP(const int32_t /*pcp*/);
80 
81     // Send buf of length len to the address specified by to.
82     virtual int32_t SendTo(const int8_t* buf, int32_t len,
83                            const SocketAddress& to) = 0;
84 
85     virtual void SetEventToNull();
86 
87     // Close socket and don't return until completed.
CloseBlocking()88     virtual void CloseBlocking() {}
89 
90     // tokenRate is in bit/s. peakBandwidt is in byte/s
91     virtual bool SetQos(int32_t serviceType, int32_t tokenRate,
92                         int32_t bucketSize, int32_t peekBandwith,
93                         int32_t minPolicedSize, int32_t maxSduSize,
94                         const SocketAddress &stRemName,
95                         int32_t overrideDSCP = 0) = 0;
96 
97     virtual uint32_t ReceiveBuffers();
98 
99 protected:
100     // Creating the socket is done via CreateSocket().
101     UdpSocketWrapper();
102     // Destroying the socket is done via CloseBlocking().
103     virtual ~UdpSocketWrapper();
104 
105     bool _wantsIncoming;
106     EventWrapper*  _deleteEvent;
107 
108 private:
109     static bool _initiated;
110 };
111 
112 }  // namespac test
113 }  // namespace webrtc
114 
115 #endif  // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_WRAPPER_H_
116