Ocean
Loading...
Searching...
No Matches
SocketScheduler.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef FACEBOOK_NETWORK_SOCKET_SCHEDULER_H
9#define FACEBOOK_NETWORK_SOCKET_SCHEDULER_H
10
12
14#include "ocean/base/Thread.h"
15
16namespace Ocean
17{
18
19namespace Network
20{
21
22// Forward declaration.
23class Socket;
24
25/**
26 * This class implements a high performance scheduler for socket events.
27 * @ingroup network
28 */
29class OCEAN_NETWORK_EXPORT SocketScheduler :
30 public Singleton<SocketScheduler>,
31 protected Thread
32{
33 friend class Socket;
34 friend class Singleton<SocketScheduler>;
35
36 protected:
37
38 /**
39 * Definition of a set holding socket pointers.
40 */
41 typedef std::unordered_set<Socket*> SocketSet;
42
43 protected:
44
45 /**
46 * Creates a new scheduler object.
47 */
49
50 /**
51 * Destructs a scheduler object.
52 */
53 ~SocketScheduler() override;
54
55 /**
56 * Register socket.
57 * @param socket The socket to be registered
58 */
59 void registerSocket(Socket& socket);
60
61 /**
62 * Unregister socket.
63 * Beware: The unregister process is not completed immediately!<br>
64 * @param socket The socket to be unregistered
65 */
66 void unregisterSocket(Socket& socket);
67
68 /**
69 * Checks whether a specific socket has been unregistered successfully.
70 * @param socket The socket which is checked
71 * @return True, if the socket has been unregistered successfully
72 */
73 bool isSocketUnregistered(Socket& socket) const;
74
75 /**
76 * The internal run function.
77 */
78 void threadRun() override;
79
80 protected:
81
82 /// The active sockets of this scheduler.
84
85 /// The set of sockets which are requested to be registered.
87
88 /// The set of sockets which are requested to be unregistered.
90
91 /// The lock of this scheduler.
92 mutable Lock lock_;
93};
94
95}
96
97}
98
99#endif // FACEBOOK_NETWORK_SOCKET_SCHEDULER_H
This class implements a recursive lock object.
Definition Lock.h:31
This class is the base class for all sockets.
Definition Socket.h:31
This class implements a high performance scheduler for socket events.
Definition SocketScheduler.h:32
void threadRun() override
The internal run function.
~SocketScheduler() override
Destructs a scheduler object.
SocketSet unregisterSockets_
The set of sockets which are requested to be unregistered.
Definition SocketScheduler.h:89
void registerSocket(Socket &socket)
Register socket.
SocketScheduler()
Creates a new scheduler object.
std::unordered_set< Socket * > SocketSet
Definition of a set holding socket pointers.
Definition SocketScheduler.h:41
SocketSet registerSockets_
The set of sockets which are requested to be registered.
Definition SocketScheduler.h:86
SocketSet activeSockets_
The active sockets of this scheduler.
Definition SocketScheduler.h:83
Lock lock_
The lock of this scheduler.
Definition SocketScheduler.h:92
bool isSocketUnregistered(Socket &socket) const
Checks whether a specific socket has been unregistered successfully.
void unregisterSocket(Socket &socket)
Unregister socket.
This template class is the base class for all singleton objects.
Definition Singleton.h:71
This class implements a thread.
Definition Thread.h:115
The namespace covering the entire Ocean framework.
Definition Accessor.h:15