18 Sockets [socket]

18.5 Socket options [socket.opt]

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_).