2#include <cosmos/limits.hxx>
3#include <cosmos/net/SockOptBase.hxx>
8template <OptLevel LEVEL>
10 const auto val = getsockopt<int>(m_sock, M_LEVEL, name);
14template <OptLevel LEVEL>
16 setIntOption(name,
int{val ? 1 : 0});
19template <OptLevel LEVEL>
21 return getsockopt<int>(m_sock, M_LEVEL, name);
24template <OptLevel LEVEL>
26 setsockopt(m_sock, M_LEVEL, name, val);
29template <OptLevel LEVEL>
31 std::string ret(max_len,
'\0');
32 max_len = getsockopt(m_sock, M_LEVEL, name, ret.data(), ret.size());
33 ret.resize(max_len - 1);
37template <OptLevel LEVEL>
39 setsockopt(m_sock, M_LEVEL, name, str.raw(), str.length());
42template <OptLevel LEVEL>
45 ret.resize(cosmos::max::NAME);
51 length = getsockopt(m_sock, M_LEVEL,
OptName{SO_PEERSEC}, ret.data(), ret.size());
53 if (ret[length-1] ==
'\0')
61 if (!ex.requiredLengthKnown() || ex.requiredLength() < ret.size()) {
66 ret.resize(ret.size());
72template class SockOptBase<OptLevel::SOCKET>;
73template class SockOptBase<OptLevel::IP>;
74template class SockOptBase<OptLevel::IPV6>;
75template class SockOptBase<OptLevel::TCP>;
76template class SockOptBase<OptLevel::UDP>;
Specialized exception type for out of range errors reported by the OS.
void setStringOption(const OptName name, const SysString str)
Set a null terminated string option.
void setBoolOption(const OptName name, const bool val)
Set a boolean style option.
int getIntOption(const OptName name) const
Return an integer option.
std::string getPeerSec() const
Returns the labeled IPSEC or NetLabel of the peer.
void setIntOption(const OptName name, const int val)
Set an integer option.
bool getBoolOption(const OptName name) const
Return a boolean style option.
std::string getStringOption(const OptName name, size_t max_len) const
Return a null terminated string option.
OptName
Representation of socket option names.
Wrapper type around a C-style string for use with system APIs.