18 Sockets [socket]

18.2 Requirements [socket.reqmts]

18.2.10 Boolean socket options [socket.reqmts.opt.bool]

A type X meets the BooleanSocketOption 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]), X is contextually convertible to bool, and X satisfies 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 bool, and u denotes an identifier.

Table 29 — BooleanSocketOption requirements
expressiontypeassertion/note pre/post-conditions
X u; post: !u.value().
X u(v); post: u.value() == v.
a.value() bool Returns the current boolean value of the socket option object.
static_cast<bool>(a) bool Returns a.value().
!a bool Returns !a.value().

In this document, types that satisfy the BooleanSocketOption requirements are defined as follows.

class C{
public:
  // constructors:
  C() noexcept;
  explicit C(bool v) noexcept;

  // members:
  C& operator=(bool v) noexcept;

  bool value() const noexcept;

  explicit operator bool() const noexcept;
  bool operator!() 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(bool v) noexcept;

Postconditions: value() == v.

C& operator=(bool v) noexcept;

Returns: *this.

Postconditions: value() == v.

bool value() const noexcept;

Returns: The stored socket option value. For extensible implementations, returns value_ != 0.

explicit operator bool() const noexcept;

Returns: value().

bool operator!() const noexcept;

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.