henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [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 | |
| 11 | #ifndef WEBRTC_BASE_SOCKETSERVER_H_ |
| 12 | #define WEBRTC_BASE_SOCKETSERVER_H_ |
| 13 | |
| 14 | #include "webrtc/base/socketfactory.h" |
| 15 | |
| 16 | namespace rtc { |
| 17 | |
| 18 | class MessageQueue; |
honghaiz | cec0a08 | 2016-01-15 14:49:09 -0800 | [diff] [blame^] | 19 | class NetworkBinderInterface; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 20 | |
| 21 | // Provides the ability to wait for activity on a set of sockets. The Thread |
| 22 | // class provides a nice wrapper on a socket server. |
| 23 | // |
| 24 | // The server is also a socket factory. The sockets it creates will be |
| 25 | // notified of asynchronous I/O from this server's Wait method. |
| 26 | class SocketServer : public SocketFactory { |
| 27 | public: |
andresp@webrtc.org | 53d9012 | 2015-02-09 14:19:09 +0000 | [diff] [blame] | 28 | static const int kForever = -1; |
| 29 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 30 | // When the socket server is installed into a Thread, this function is |
| 31 | // called to allow the socket server to use the thread's message queue for |
| 32 | // any messaging that it might need to perform. |
| 33 | virtual void SetMessageQueue(MessageQueue* queue) {} |
| 34 | |
| 35 | // Sleeps until: |
| 36 | // 1) cms milliseconds have elapsed (unless cms == kForever) |
| 37 | // 2) WakeUp() is called |
| 38 | // While sleeping, I/O is performed if process_io is true. |
| 39 | virtual bool Wait(int cms, bool process_io) = 0; |
| 40 | |
| 41 | // Causes the current wait (if one is in progress) to wake up. |
| 42 | virtual void WakeUp() = 0; |
honghaiz | cec0a08 | 2016-01-15 14:49:09 -0800 | [diff] [blame^] | 43 | |
| 44 | // A network binder will bind the created sockets to a network. |
| 45 | // It is only used in PhysicalSocketServer. |
| 46 | void set_network_binder(NetworkBinderInterface* binder) { |
| 47 | network_binder_ = binder; |
| 48 | } |
| 49 | NetworkBinderInterface* network_binder() const { return network_binder_; } |
| 50 | |
| 51 | private: |
| 52 | NetworkBinderInterface* network_binder_ = nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | } // namespace rtc |
| 56 | |
| 57 | #endif // WEBRTC_BASE_SOCKETSERVER_H_ |