blob: 7071f2252687c9b4e31471bb1f0af0ef9f326672 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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
danilchapbebf54c2016-04-28 01:32:48 -070014#include <memory>
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000015#include "webrtc/base/socketfactory.h"
16
17namespace rtc {
18
19class MessageQueue;
honghaizcec0a082016-01-15 14:49:09 -080020class NetworkBinderInterface;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000021
22// Provides the ability to wait for activity on a set of sockets. The Thread
23// class provides a nice wrapper on a socket server.
24//
25// The server is also a socket factory. The sockets it creates will be
26// notified of asynchronous I/O from this server's Wait method.
27class SocketServer : public SocketFactory {
28 public:
andresp@webrtc.org53d90122015-02-09 14:19:09 +000029 static const int kForever = -1;
30
danilchapbebf54c2016-04-28 01:32:48 -070031 static std::unique_ptr<SocketServer> CreateDefault();
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000032 // When the socket server is installed into a Thread, this function is
33 // called to allow the socket server to use the thread's message queue for
34 // any messaging that it might need to perform.
35 virtual void SetMessageQueue(MessageQueue* queue) {}
36
37 // Sleeps until:
38 // 1) cms milliseconds have elapsed (unless cms == kForever)
39 // 2) WakeUp() is called
40 // While sleeping, I/O is performed if process_io is true.
41 virtual bool Wait(int cms, bool process_io) = 0;
42
43 // Causes the current wait (if one is in progress) to wake up.
44 virtual void WakeUp() = 0;
honghaizcec0a082016-01-15 14:49:09 -080045
46 // A network binder will bind the created sockets to a network.
47 // It is only used in PhysicalSocketServer.
48 void set_network_binder(NetworkBinderInterface* binder) {
49 network_binder_ = binder;
50 }
51 NetworkBinderInterface* network_binder() const { return network_binder_; }
52
53 private:
54 NetworkBinderInterface* network_binder_ = nullptr;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000055};
56
57} // namespace rtc
58
59#endif // WEBRTC_BASE_SOCKETSERVER_H_