blob: bf1326dad9fe47d58daa55417811ab891d96cdc8 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
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 Anton10542f22019-01-11 17:11:0011#ifndef RTC_BASE_SOCKET_SERVER_H_
12#define RTC_BASE_SOCKET_SERVER_H_
henrike@webrtc.orgf0488722014-05-13 18:00:2613
Henrik Kjellanderec78f1c2017-06-29 05:52:5014#include <memory>
Jonas Olssona4d87372019-07-05 17:08:3315
Markus Handell9a21c492022-08-25 11:40:1316#include "api/units/time_delta.h"
17#include "rtc_base/event.h"
Steve Anton10542f22019-01-11 17:11:0018#include "rtc_base/socket_factory.h"
henrike@webrtc.orgf0488722014-05-13 18:00:2619
Henrik Kjellanderec78f1c2017-06-29 05:52:5020namespace rtc {
21
Sebastian Jansson290de822020-01-09 13:20:2322class Thread;
Henrik Kjellanderec78f1c2017-06-29 05:52:5023// Needs to be forward declared because there's a circular dependency between
24// NetworkMonitor and Thread.
25// TODO(deadbeef): Fix this.
26class NetworkBinderInterface;
27
28// Provides the ability to wait for activity on a set of sockets. The Thread
29// class provides a nice wrapper on a socket server.
30//
31// The server is also a socket factory. The sockets it creates will be
32// notified of asynchronous I/O from this server's Wait method.
33class SocketServer : public SocketFactory {
34 public:
Markus Handell9a21c492022-08-25 11:40:1335 static constexpr webrtc::TimeDelta kForever = rtc::Event::kForever;
Henrik Kjellanderec78f1c2017-06-29 05:52:5036
37 static std::unique_ptr<SocketServer> CreateDefault();
Niels Möller9bd24572021-04-19 10:18:2738 // When the socket server is installed into a Thread, this function is called
39 // to allow the socket server to use the thread's message queue for any
40 // messaging that it might need to perform. It is also called with a null
41 // argument before the thread is destroyed.
Sebastian Jansson290de822020-01-09 13:20:2342 virtual void SetMessageQueue(Thread* queue) {}
Henrik Kjellanderec78f1c2017-06-29 05:52:5043
44 // Sleeps until:
Markus Handell9a21c492022-08-25 11:40:1345 // 1) `max_wait_duration` has elapsed (unless `max_wait_duration` ==
46 // `kForever`)
47 // 2) WakeUp() is called
Henrik Kjellanderec78f1c2017-06-29 05:52:5048 // While sleeping, I/O is performed if process_io is true.
Markus Handell9a21c492022-08-25 11:40:1349 virtual bool Wait(webrtc::TimeDelta max_wait_duration, bool process_io) = 0;
Henrik Kjellanderec78f1c2017-06-29 05:52:5050
51 // Causes the current wait (if one is in progress) to wake up.
52 virtual void WakeUp() = 0;
53
54 // A network binder will bind the created sockets to a network.
55 // It is only used in PhysicalSocketServer.
56 void set_network_binder(NetworkBinderInterface* binder) {
57 network_binder_ = binder;
58 }
59 NetworkBinderInterface* network_binder() const { return network_binder_; }
60
61 private:
62 NetworkBinderInterface* network_binder_ = nullptr;
63};
64
65} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:2666
Steve Anton10542f22019-01-11 17:11:0067#endif // RTC_BASE_SOCKET_SERVER_H_