OLD | NEW |
(Empty) | |
| 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_MANAGER_POSIX_H_ |
| 12 #define WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_MANAGER_POSIX_H_ |
| 13 |
| 14 #include <sys/types.h> |
| 15 #include <unistd.h> |
| 16 |
| 17 #include <list> |
| 18 #include <map> |
| 19 |
| 20 #include "webrtc/base/platform_thread.h" |
| 21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 22 #include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h" |
| 23 #include "webrtc/test/channel_transport/udp_socket_wrapper.h" |
| 24 |
| 25 namespace webrtc { |
| 26 namespace test { |
| 27 |
| 28 class UdpSocketPosix; |
| 29 class UdpSocketManagerPosixImpl; |
| 30 #define MAX_NUMBER_OF_SOCKET_MANAGERS_LINUX 8 |
| 31 |
| 32 class UdpSocketManagerPosix : public UdpSocketManager |
| 33 { |
| 34 public: |
| 35 UdpSocketManagerPosix(); |
| 36 virtual ~UdpSocketManagerPosix(); |
| 37 |
| 38 bool Init(int32_t id, uint8_t& numOfWorkThreads) override; |
| 39 |
| 40 bool Start() override; |
| 41 bool Stop() override; |
| 42 |
| 43 bool AddSocket(UdpSocketWrapper* s) override; |
| 44 bool RemoveSocket(UdpSocketWrapper* s) override; |
| 45 |
| 46 private: |
| 47 int32_t _id; |
| 48 CriticalSectionWrapper* _critSect; |
| 49 uint8_t _numberOfSocketMgr; |
| 50 uint8_t _incSocketMgrNextTime; |
| 51 uint8_t _nextSocketMgrToAssign; |
| 52 UdpSocketManagerPosixImpl* _socketMgr[MAX_NUMBER_OF_SOCKET_MANAGERS_LINUX]; |
| 53 }; |
| 54 |
| 55 class UdpSocketManagerPosixImpl |
| 56 { |
| 57 public: |
| 58 UdpSocketManagerPosixImpl(); |
| 59 virtual ~UdpSocketManagerPosixImpl(); |
| 60 |
| 61 virtual bool Start(); |
| 62 virtual bool Stop(); |
| 63 |
| 64 virtual bool AddSocket(UdpSocketWrapper* s); |
| 65 virtual bool RemoveSocket(UdpSocketWrapper* s); |
| 66 |
| 67 protected: |
| 68 static bool Run(void* obj); |
| 69 bool Process(); |
| 70 void UpdateSocketMap(); |
| 71 |
| 72 private: |
| 73 typedef std::list<UdpSocketWrapper*> SocketList; |
| 74 typedef std::list<SOCKET> FdList; |
| 75 rtc::PlatformThread _thread; |
| 76 CriticalSectionWrapper* _critSectList; |
| 77 |
| 78 fd_set _readFds; |
| 79 |
| 80 std::map<SOCKET, UdpSocketPosix*> _socketMap; |
| 81 SocketList _addList; |
| 82 FdList _removeList; |
| 83 }; |
| 84 |
| 85 } // namespace test |
| 86 } // namespace webrtc |
| 87 |
| 88 #endif // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_MANAGER_POSIX_H_ |
OLD | NEW |