18 Sockets [socket]

18.5 Socket options [socket.opt]

In the table below, let C denote a socket option class; let L identify the POSIX macro to be passed as the level argument to POSIX setsockopt and getsockopt; let N identify the POSIX macro to be passed as the option_name argument to POSIX setsockopt and getsockopt; and let T identify the type of the value whose address will be passed as the option_value argument to POSIX setsockopt and getsockopt.

Table 34 — Socket options
CLNTRequirements, definition or notes
socket_base:: broadcast SOL_SOCKET SO_BROADCAST int Satisfies the BooleanSocketOption ([socket.reqmts.opt.bool]) type requirements. Determines whether a socket permits sending of broadcast messages, if supported by the protocol.
socket_base:: debug SOL_SOCKET SO_DEBUG int Satisfies the BooleanSocketOption ([socket.reqmts.opt.bool]) type requirements. Determines whether debugging information is recorded by the underlying protocol.
socket_base:: do_not_route SOL_SOCKET SO_DONTROUTE int Satisfies the BooleanSocketOption ([socket.reqmts.opt.bool]) type requirements. Determines whether outgoing messages bypass standard routing facilities.
socket_base:: keep_alive SOL_SOCKET SO_KEEPALIVE int Satisfies the BooleanSocketOption ([socket.reqmts.opt.bool]) type requirements. Determines whether a socket permits sending of keep_alive messages, if supported by the protocol.
socket_base:: linger ([socket.opt.linger]) SOL_SOCKET SO_LINGER linger Controls the behavior when a socket is closed and unsent data is present.
socket_base:: out_of_band_inline SOL_SOCKET SO_OOBINLINE int Satisfies the BooleanSocketOption ([socket.reqmts.opt.bool]) type requirements. Determines whether out-of-band data (also known as urgent data) is received inline.
socket_base:: receive_buffer_size SOL_SOCKET SO_RCVBUF int Satisfies the IntegerSocketOption ([socket.reqmts.opt.int]) type requirements. Specifies the size of the receive buffer associated with a socket.
socket_base:: receive_low_watermark SOL_SOCKET SO_RCVLOWAT int Satisfies the IntegerSocketOption ([socket.reqmts.opt.int]) type requirements. Specifies the minimum number of bytes to process for socket input operations.
socket_base:: reuse_address SOL_SOCKET SO_REUSEADDR int Satisfies the BooleanSocketOption ([socket.reqmts.opt.bool]) type requirements. Determines whether the validation of endpoints used for binding a socket should allow the reuse of local endpoints, if supported by the protocol.
socket_base:: send_buffer_size SOL_SOCKET SO_SNDBUF int Satisfies the IntegerSocketOption ([socket.reqmts.opt.int]) type requirements. Specifies the size of the send buffer associated with a socket.
socket_base:: send_low_watermark SOL_SOCKET SO_SNDLOWAT int Satisfies the IntegerSocketOption ([socket.reqmts.opt.int]) type requirements. Specifies the minimum number of bytes to process for socket output operations.

18.5.1 Class socket_base::linger [socket.opt.linger]

The linger class represents a socket option for controlling the behavior when a socket is closed and unsent data is present.

namespace std {
namespace experimental {
namespace net {
inline namespace v1 {

  class socket_base::linger
  {
  public:
    // constructors:
    linger() noexcept;
    linger(bool e, chrono::seconds t) noexcept;

    // members:
    bool enabled() const noexcept;
    void enabled(bool e) noexcept;

    chrono::seconds timeout() const noexcept;
    void timeout(chrono::seconds t) noexcept;
  };

} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std

linger 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]).

Extensible implementations provide the following member functions:

namespace std {
namespace experimental {
namespace net {
inline namespace v1 {

  class socket_base::linger
  {
  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:
    ::linger value_;  // exposition only
  };

} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std

linger() noexcept;

Postconditions: !enabled() && timeout() == chrono::seconds(0).

linger(bool e, chrono::seconds t) noexcept;

Postconditions: enabled() == e && timeout() == t.

bool enabled() const noexcept;

Returns: value_.l_onoff != 0.

void enabled(bool e) noexcept;

Postconditions: enabled() == e.

chrono::seconds timeout() const noexcept;

Returns: chrono::seconds(value_.l_linger).

void timeout(chrono::seconds t) noexcept;

Postconditions: timeout() == t.

template<class Protocol> int level(const Protocol& p) const noexcept;

Returns: SOL_SOCKET.

template<class Protocol> int name(const Protocol& p) const noexcept;

Returns: SO_LINGER.

template<class Protocol> void* data(const Protocol& p) const 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 != sizeof(value_).