• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2011 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_POSIX_H_
12 #define WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_POSIX_H_
13 
14 #include <arpa/inet.h>
15 #include <netinet/in.h>
16 #include <sys/socket.h>
17 #include <sys/types.h>
18 
19 #include "webrtc/system_wrappers/interface/condition_variable_wrapper.h"
20 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
21 #include "webrtc/test/channel_transport/udp_socket_wrapper.h"
22 
23 namespace webrtc {
24 namespace test {
25 
26 #define SOCKET_ERROR -1
27 
28 class UdpSocketPosix : public UdpSocketWrapper
29 {
30 public:
31     UdpSocketPosix(const int32_t id, UdpSocketManager* mgr,
32                    bool ipV6Enable = false);
33 
34     virtual ~UdpSocketPosix();
35 
36     virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;
37 
38     virtual bool SetCallback(CallbackObj obj,
39                              IncomingSocketCallback cb) OVERRIDE;
40 
41     virtual bool Bind(const SocketAddress& name) OVERRIDE;
42 
43     virtual bool SetSockopt(int32_t level, int32_t optname,
44                             const int8_t* optval, int32_t optlen) OVERRIDE;
45 
46     virtual int32_t SetTOS(const int32_t serviceType) OVERRIDE;
47 
48     virtual int32_t SendTo(const int8_t* buf, int32_t len,
49                            const SocketAddress& to) OVERRIDE;
50 
51     // Deletes socket in addition to closing it.
52     // TODO (hellner): make destructor protected.
53     virtual void CloseBlocking() OVERRIDE;
54 
55     virtual SOCKET GetFd();
56     virtual int32_t GetError();
57 
58     virtual bool ValidHandle() OVERRIDE;
59 
60     virtual bool SetQos(int32_t /*serviceType*/,
61                         int32_t /*tokenRate*/,
62                         int32_t /*bucketSize*/,
63                         int32_t /*peekBandwith*/,
64                         int32_t /*minPolicedSize*/,
65                         int32_t /*maxSduSize*/,
66                         const SocketAddress& /*stRemName*/,
67                         int32_t /*overrideDSCP*/) OVERRIDE;
68 
69     bool CleanUp();
70     void HasIncoming();
71     bool WantsIncoming();
72     void ReadyForDeletion();
73 private:
74     friend class UdpSocketManagerPosix;
75 
76     int32_t _id;
77     IncomingSocketCallback _incomingCb;
78     CallbackObj _obj;
79     int32_t _error;
80 
81     SOCKET _socket;
82     UdpSocketManager* _mgr;
83     ConditionVariableWrapper* _closeBlockingCompletedCond;
84     ConditionVariableWrapper* _readyForDeletionCond;
85 
86     bool _closeBlockingActive;
87     bool _closeBlockingCompleted;
88     bool _readyForDeletion;
89 
90     CriticalSectionWrapper* _cs;
91 };
92 
93 }  // namespace test
94 }  // namespace webrtc
95 
96 #endif  // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_POSIX_H_
97