• 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                                       size_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     // Register cb for receiving callbacks when there are incoming packets.
54     // Register obj so that it will be passed in calls to cb.
55     virtual bool SetCallback(CallbackObj obj, IncomingSocketCallback cb) = 0;
56 
57     // Socket to local address specified by name.
58     virtual bool Bind(const SocketAddress& name) = 0;
59 
60     // Start receiving UDP data.
61     virtual bool StartReceiving();
62     virtual bool StartReceiving(const uint32_t /*receiveBuffers*/);
63     // Stop receiving UDP data.
64     virtual bool StopReceiving();
65 
66     virtual bool ValidHandle() = 0;
67 
68     // Set socket options.
69     virtual bool SetSockopt(int32_t level, int32_t optname,
70                             const int8_t* optval, int32_t optlen) = 0;
71 
72     // Set TOS for outgoing packets.
73     virtual int32_t SetTOS(const int32_t serviceType) = 0;
74 
75     // Set 802.1Q PCP field (802.1p) for outgoing VLAN traffic.
76     virtual int32_t SetPCP(const int32_t /*pcp*/);
77 
78     // Send buf of length len to the address specified by to.
79     virtual int32_t SendTo(const int8_t* buf, size_t len,
80                            const SocketAddress& to) = 0;
81 
82     virtual void SetEventToNull();
83 
84     // Close socket and don't return until completed.
CloseBlocking()85     virtual void CloseBlocking() {}
86 
87     // tokenRate is in bit/s. peakBandwidt is in byte/s
88     virtual bool SetQos(int32_t serviceType, int32_t tokenRate,
89                         int32_t bucketSize, int32_t peekBandwith,
90                         int32_t minPolicedSize, int32_t maxSduSize,
91                         const SocketAddress &stRemName,
92                         int32_t overrideDSCP = 0) = 0;
93 
94     virtual uint32_t ReceiveBuffers();
95 
96 protected:
97     // Creating the socket is done via CreateSocket().
98     UdpSocketWrapper();
99     // Destroying the socket is done via CloseBlocking().
100     virtual ~UdpSocketWrapper();
101 
102     bool _wantsIncoming;
103     EventWrapper*  _deleteEvent;
104 
105 private:
106     static bool _initiated;
107 };
108 
109 }  // namespac test
110 }  // namespace webrtc
111 
112 #endif  // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_WRAPPER_H_
113