Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / test / channel_transport / udp_socket_posix.h
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     SOCKET GetFd();
56
57     virtual bool ValidHandle() OVERRIDE;
58
59     virtual bool SetQos(int32_t /*serviceType*/,
60                         int32_t /*tokenRate*/,
61                         int32_t /*bucketSize*/,
62                         int32_t /*peekBandwith*/,
63                         int32_t /*minPolicedSize*/,
64                         int32_t /*maxSduSize*/,
65                         const SocketAddress& /*stRemName*/,
66                         int32_t /*overrideDSCP*/) OVERRIDE;
67
68     bool CleanUp();
69     void HasIncoming();
70     bool WantsIncoming();
71     void ReadyForDeletion();
72 private:
73     friend class UdpSocketManagerPosix;
74
75     int32_t _id;
76     IncomingSocketCallback _incomingCb;
77     CallbackObj _obj;
78
79     SOCKET _socket;
80     UdpSocketManager* _mgr;
81     ConditionVariableWrapper* _closeBlockingCompletedCond;
82     ConditionVariableWrapper* _readyForDeletionCond;
83
84     bool _closeBlockingActive;
85     bool _closeBlockingCompleted;
86     bool _readyForDeletion;
87
88     CriticalSectionWrapper* _cs;
89 };
90
91 }  // namespace test
92 }  // namespace webrtc
93
94 #endif  // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_POSIX_H_