A type X meets the IntegerSocketOption requirements if it satisfies the requirements of Destructible (C++ 2014 [destructible]), DefaultConstructible (C++ 2014 [defaultconstructible]), CopyConstructible (C++ 2014 [copyconstructible]), CopyAssignable (C++ 2014 [copyassignable]), GettableSocketOption ([socket.reqmts.gettablesocketoption]), and SettableSocketOption ([socket.reqmts.settablesocketoption]), as well as the additional requirements listed below.
In the table below, a denotes a (possibly const) value of type X, v denotes a (possibly const) value of type int, and u denotes an identifier.
expression | type | assertion/note pre/post-conditions |
X u; | post: u.value() == 0. | |
X u(v); | post: u.value() == v. | |
a.value() | int | Returns the current integer value of the socket option object. |
In this document, types that satisfy the IntegerSocketOption requirements are defined as follows.
class C{ public: // constructors: C() noexcept; explicit C(int v) noexcept; // members: C& operator=(int v) noexcept; int value() const noexcept; };
Extensible implementations provide the following member functions:
class C{ public: template<class Protocol> int level(const Protocol& p) const noexcept; template<class Protocol> int name(const Protocol& p) const noexcept; template<class Protocol> void* data(const Protocol& p) noexcept; template<class Protocol> const void* data(const Protocol& p) const noexcept; template<class Protocol> size_t size(const Protocol& p) const noexcept; template<class Protocol> void resize(const Protocol& p, size_t s); // remainder unchanged private: int value_; // exposition only };
Let L and N identify the POSIX macros to be passed as the level and option_name arguments, respectively, to POSIX setsockopt and getsockopt.
C() noexcept;
Postconditions: !value().
explicit C(int v) noexcept;
Postconditions: value() == v.
C& operator=(int v) noexcept;
Returns: *this.
Postconditions: value() == v.
int value() const noexcept;
Returns: The stored socket option value. For extensible implementations, returns value_.
template<class Protocol> int level(const Protocol& p) const noexcept;
Returns: L.
template<class Protocol> int name(const Protocol& p) const noexcept;
Returns: N.
template<class Protocol> void* data(const Protocol& p) noexcept;
Returns: std::addressof(value_).
template<class Protocol> const void* data(const Protocol& p) const noexcept;
Returns: std::addressof(value_).
template<class Protocol> size_t size(const Protocol& p) const noexcept;
Returns: sizeof(value_).
template<class Protocol> void resize(const Protocol& p, size_t s);
Remarks: length_error if s is not a valid data size for the protocol specified by p.