henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef RTC_BASE_SOCKET_SERVER_H_ |
| 12 | #define RTC_BASE_SOCKET_SERVER_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 13 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 14 | #include <memory> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 15 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 16 | #include "rtc_base/socket_factory.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 17 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 18 | namespace rtc { |
| 19 | |
Sebastian Jansson | 290de82 | 2020-01-09 13:20:23 | [diff] [blame] | 20 | class Thread; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 21 | // Needs to be forward declared because there's a circular dependency between |
| 22 | // NetworkMonitor and Thread. |
| 23 | // TODO(deadbeef): Fix this. |
| 24 | class NetworkBinderInterface; |
| 25 | |
| 26 | // Provides the ability to wait for activity on a set of sockets. The Thread |
| 27 | // class provides a nice wrapper on a socket server. |
| 28 | // |
| 29 | // The server is also a socket factory. The sockets it creates will be |
| 30 | // notified of asynchronous I/O from this server's Wait method. |
| 31 | class SocketServer : public SocketFactory { |
| 32 | public: |
| 33 | static const int kForever = -1; |
| 34 | |
| 35 | static std::unique_ptr<SocketServer> CreateDefault(); |
| 36 | // When the socket server is installed into a Thread, this function is |
| 37 | // called to allow the socket server to use the thread's message queue for |
| 38 | // any messaging that it might need to perform. |
Sebastian Jansson | 290de82 | 2020-01-09 13:20:23 | [diff] [blame] | 39 | virtual void SetMessageQueue(Thread* queue) {} |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 40 | |
| 41 | // Sleeps until: |
| 42 | // 1) cms milliseconds have elapsed (unless cms == kForever) |
| 43 | // 2) WakeUp() is called |
| 44 | // While sleeping, I/O is performed if process_io is true. |
| 45 | virtual bool Wait(int cms, bool process_io) = 0; |
| 46 | |
| 47 | // Causes the current wait (if one is in progress) to wake up. |
| 48 | virtual void WakeUp() = 0; |
| 49 | |
| 50 | // A network binder will bind the created sockets to a network. |
| 51 | // It is only used in PhysicalSocketServer. |
| 52 | void set_network_binder(NetworkBinderInterface* binder) { |
| 53 | network_binder_ = binder; |
| 54 | } |
| 55 | NetworkBinderInterface* network_binder() const { return network_binder_; } |
| 56 | |
| 57 | private: |
| 58 | NetworkBinderInterface* network_binder_ = nullptr; |
| 59 | }; |
| 60 | |
| 61 | } // namespace rtc |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 62 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 63 | #endif // RTC_BASE_SOCKET_SERVER_H_ |