libcosmos
Linux C++ System Programming Library
Loading...
Searching...
No Matches
SockOptBase.hxx
1#pragma once
2
3// cosmos
4#include <cosmos/SysString.hxx>
5#include <cosmos/dso_export.h>
6#include <cosmos/fs/FileDescriptor.hxx>
7#include <cosmos/net/types.hxx>
8
9namespace cosmos {
10
12
17template <OptLevel LEVEL>
18class COSMOS_API SockOptBase {
19protected: // functions
20
23 m_sock{fd} {}
24
26 bool getBoolOption(const OptName name) const;
28 void setBoolOption(const OptName name, const bool val);
29
31 int getIntOption(const OptName name) const;
33 void setIntOption(const OptName name, const int val);
34
36 std::string getStringOption(const OptName name, size_t max_len) const;
38 void setStringOption(const OptName name, const SysString str);
39
41
50 std::string getPeerSec() const;
51
52 /* disallow copy/assignment for option helpers */
53
54 SockOptBase(const SockOptBase &) = delete;
55 SockOptBase& operator=(const SockOptBase&) = delete;
56
57
58protected: // data
59
60 static constexpr OptLevel M_LEVEL = LEVEL;
62};
63
64extern template class COSMOS_API SockOptBase<OptLevel::SOCKET>;
65extern template class COSMOS_API SockOptBase<OptLevel::IP>;
66extern template class COSMOS_API SockOptBase<OptLevel::IPV6>;
67extern template class COSMOS_API SockOptBase<OptLevel::TCP>;
68extern template class COSMOS_API SockOptBase<OptLevel::UDP>;
69
70}; // end ns
Thin Wrapper around OS file descriptors.
Base class for Socket option helpers for different OptLevels.
SockOptBase(FileDescriptor fd)
Perform socket options on the given file descriptor.
FileDescriptor m_sock
The socket file descriptor to operate on.
OptLevel
Representation of socket option levels.
Definition types.hxx:90
OptName
Representation of socket option names.
Definition types.hxx:103
Wrapper type around a C-style string for use with system APIs.
Definition SysString.hxx:33