SNode.C
Loading...
Searching...
No Matches
ConfigSocketServer.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 "net/in/stream/config/ConfigSocketServer.h"
21
22#include "net/config/stream/ConfigSocketServer.hpp"
23
24#ifndef DOXYGEN_SHOULD_SKIP_THIS
25
26#ifdef __GNUC__
27#pragma GCC diagnostic push
28#pragma GCC diagnostic ignored "-Wfloat-equal"
29#ifdef __has_warning
30#if __has_warning("-Wweak-vtables")
31#pragma GCC diagnostic ignored "-Wweak-vtables"
32#endif
33#if __has_warning("-Wcovered-switch-default")
34#pragma GCC diagnostic ignored "-Wcovered-switch-default"
35#endif
36#endif
37#endif
38#include "utils/CLI11.hpp"
39#ifdef __GNUC__
40#pragma GCC diagnostic pop
41#endif
42
43#include "core/system/netdb.h"
44
45#include <netinet/in.h>
46#include <string>
47
48#endif /* DOXYGEN_SHOULD_SKIP_THIS */
49
50#define XSTR(s) STR(s)
51#define STR(s) #s
52
53namespace net::in::stream::config {
54
55 ConfigSocketServer::ConfigSocketServer(net::config::ConfigInstance* instance)
57 net::in::config::ConfigAddress<net::config::ConfigAddressLocal>::setPortRequired();
58 net::in::config::ConfigAddress<net::config::ConfigAddressLocal>::setAiFlags(AI_PASSIVE);
59 net::in::config::ConfigAddress<net::config::ConfigAddressLocal>::setAiSockType(SOCK_STREAM);
60 net::in::config::ConfigAddress<net::config::ConfigAddressLocal>::setAiProtocol(IPPROTO_TCP);
61
62 reusePortOpt = net::config::ConfigPhysicalSocket::addSocketOption( //
63 "--reuse-port{true}",
64 SOL_SOCKET,
65 SO_REUSEPORT,
66 "Reuse port number",
67 "bool",
68 XSTR(REUSE_PORT),
69 CLI::IsMember({"true", "false"}));
70 }
71
74
76 if (reusePort) {
77 addSocketOption(SOL_SOCKET, SO_REUSEPORT, 1);
78 } else {
79 removeSocketOption(SO_REUSEPORT);
80 }
81
83 ->default_val(reusePort ? "true" : "false")
84 ->clear();
85
86 return *this;
87 }
88
90 return reusePortOpt->as<bool>();
91 }
92
93} // namespace net::in::stream::config
94
95template class net::config::stream::ConfigSocketServer<net::in::config::ConfigAddress, net::in::config::ConfigAddressReverse>;
#define XSTR(s)
ConfigSocketServer & setReusePort(bool reusePort=true)
ConfigSocketServer(net::config::ConfigInstance *instance)
#define STR(a)
Definition clients.h:26