SNode.C
Loading...
Searching...
No Matches
EventMultiplexer.cpp
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "core/multiplexer/select/EventMultiplexer.h"
21
22#ifndef DOXYGEN_SHOULD_SKIP_THIS
23
24#include "core/system/select.h"
25#include "log/Logger.h"
26#include "utils/Timeval.h"
27
28#include <array>
29#include <ctime>
30
31#endif /* DOXYGEN_SHOULD_SKIP_THIS */
32
34 static core::multiplexer::select::EventMultiplexer eventMultiplexer;
35
36 return eventMultiplexer;
37}
38
39namespace core::multiplexer::select {
40
41 EventMultiplexer::EventMultiplexer()
42 : core::EventMultiplexer(new core::multiplexer::select::DescriptorEventPublisher("READ", //
43 fdSets[core::EventMultiplexer::DISP_TYPE::RD]),
44 new core::multiplexer::select::DescriptorEventPublisher("WRITE", //
45 fdSets[core::EventMultiplexer::DISP_TYPE::WR]),
46 new core::multiplexer::select::DescriptorEventPublisher("EXCEPT", //
47 fdSets[core::EventMultiplexer::DISP_TYPE::EX])) {
48 LOG(DEBUG) << "Core::multiplexer: select";
49 }
50
51 int EventMultiplexer::monitorDescriptors(utils::Timeval& tickTimeOut, const sigset_t& sigMask) {
52 const timespec timeSpec = tickTimeOut.getTimespec();
53
54 return core::system::pselect(maxFd() + 1,
55 &fdSets[core::EventMultiplexer::DISP_TYPE::RD].get(),
56 &fdSets[core::EventMultiplexer::DISP_TYPE::WR].get(),
57 &fdSets[core::EventMultiplexer::DISP_TYPE::EX].get(),
58 &timeSpec,
59 &sigMask);
60 }
61
62 void EventMultiplexer::spanActiveEvents(int activeDescriptorCount) {
63 if (activeDescriptorCount > 0) {
64 for (core::DescriptorEventPublisher* const descriptorEventPublisher : descriptorEventPublishers) {
65 descriptorEventPublisher->spanActiveEvents();
66 }
67 }
68 }
69
70} // namespace core::multiplexer::select
core::EventMultiplexer & EventMultiplexer()