1af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org/* 2af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * 4af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * Use of this source code is governed by a BSD-style license 5af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * that can be found in the LICENSE file in the root of the source 6af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * tree. An additional intellectual property rights grant can be found 7af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * in the file PATENTS. All contributing project authors may 8af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * be found in the AUTHORS file in the root of the source tree. 9af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org */ 10af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 11af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifndef WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_WRAPPER_H_ 12af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#define WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_WRAPPER_H_ 13af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 14af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/test/channel_transport/udp_transport.h" 15af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 16af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgnamespace webrtc { 17af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 18af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgclass EventWrapper; 19af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 20af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgnamespace test { 21af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 22af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgclass UdpSocketManager; 23af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 24af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#define SOCKET_ERROR_NO_QOS -1000 25af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 26af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifndef _WIN32 27af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgtypedef int SOCKET; 28af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 29af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 30af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifndef INVALID_SOCKET 31af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#define INVALID_SOCKET (SOCKET)(~0) 32af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 33af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifndef AF_INET 34af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#define AF_INET 2 35af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 36af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 37af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 38af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 39af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgtypedef void* CallbackObj; 4091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgtypedef void(*IncomingSocketCallback)(CallbackObj obj, const int8_t* buf, 4191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t len, const SocketAddress* from); 42af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 43af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgclass UdpSocketWrapper 44af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 45af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgpublic: 4691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org static UdpSocketWrapper* CreateSocket(const int32_t id, 47af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketManager* mgr, 48af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CallbackObj obj, 49af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IncomingSocketCallback cb, 50af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org bool ipV6Enable = false, 51af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org bool disableGQOS = false); 52af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 53af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Set the unique identifier of this class to id. 5491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org virtual int32_t ChangeUniqueId(const int32_t id) = 0; 55af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 56af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Register cb for receiving callbacks when there are incoming packets. 57af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Register obj so that it will be passed in calls to cb. 58af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org virtual bool SetCallback(CallbackObj obj, IncomingSocketCallback cb) = 0; 59af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 60af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Socket to local address specified by name. 61af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org virtual bool Bind(const SocketAddress& name) = 0; 62af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 63af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Start receiving UDP data. 64af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org virtual bool StartReceiving(); 6577c6d714d2f8f700170218784553df1a48f17885pbos@webrtc.org virtual bool StartReceiving(const uint32_t /*receiveBuffers*/); 66af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Stop receiving UDP data. 67af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org virtual bool StopReceiving(); 68af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 69af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org virtual bool ValidHandle() = 0; 70af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 71af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Set socket options. 7291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org virtual bool SetSockopt(int32_t level, int32_t optname, 7391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int8_t* optval, int32_t optlen) = 0; 74af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 75af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Set TOS for outgoing packets. 7691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org virtual int32_t SetTOS(const int32_t serviceType) = 0; 77af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 78af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Set 802.1Q PCP field (802.1p) for outgoing VLAN traffic. 7977c6d714d2f8f700170218784553df1a48f17885pbos@webrtc.org virtual int32_t SetPCP(const int32_t /*pcp*/); 80af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 81af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Send buf of length len to the address specified by to. 8291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org virtual int32_t SendTo(const int8_t* buf, int32_t len, 8391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const SocketAddress& to) = 0; 84af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 85af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org virtual void SetEventToNull(); 86af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 87af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Close socket and don't return until completed. 88af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org virtual void CloseBlocking() {} 89af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 90af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // tokenRate is in bit/s. peakBandwidt is in byte/s 9191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org virtual bool SetQos(int32_t serviceType, int32_t tokenRate, 9291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t bucketSize, int32_t peekBandwith, 9391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t minPolicedSize, int32_t maxSduSize, 94af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const SocketAddress &stRemName, 9591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t overrideDSCP = 0) = 0; 96af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 9777c6d714d2f8f700170218784553df1a48f17885pbos@webrtc.org virtual uint32_t ReceiveBuffers(); 98af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 99af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgprotected: 100af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Creating the socket is done via CreateSocket(). 101af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper(); 102af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Destroying the socket is done via CloseBlocking(). 103af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org virtual ~UdpSocketWrapper(); 104af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 105af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org bool _wantsIncoming; 106af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org EventWrapper* _deleteEvent; 107af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 108af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgprivate: 109af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org static bool _initiated; 110af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org}; 111af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 112af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} // namespac test 113af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} // namespace webrtc 114af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 115af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_WRAPPER_H_ 116