xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Public Member Functions | List of all members
xtd::net::sockets::linger_option Class Reference

#include <linger_option.h>

Definition

Specifies whether a xtd::net::sockets::socket will remain connected after a call to the xtd::net::sockets::socket::close or xtd::net::sockets::tcp_client::close methods and the length of time it will remain connected, if data remains to be sent.

Namespace
xtd::net::sockets
Library
xtd.core
Remarks
There may still be data available in the outgoing network buffer after an application calls the xtd::net::sockets::socket or xtd::net::sockets::tcp_client method. If you want to specify the amount of time that the xtd::net::sockets::socket will attempt to transmit unsent data after closing, create a xtd::net::sockets::linger_option with the enable parameter set to true, and the seconds parameter set to the desired amount of time. The seconds parameter is used to indicate how long you would like the xtd::net::sockets::socket to remain connected before timing out. If you do not want the xtd::net::sockets::socket to stay connected for any length of time after closing, create a xtd::net::sockets::linger_option instance with the enable parameter set to true and the seconds parameter set to zero. In this case, the xtd::net::sockets::socket will close immediately and any unsent data will be lost. Once created, pass the xtd::net::sockets::linger_option to the xtd::net::sockets::socket::set_socket_option method. If you are sending and receiving data with a xtd::net::sockets::tcp_client, then set the xtd::net::sockets::linger_option instance in the xtd::net::sockets::tcp_client::linger_state property.
The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a xtd::net::sockets::socket when the xtd::net::sockets::socket::linger_state property is not set and for a xtd::net::sockets::tcp_client when the xtd::net::sockets::tcp_client::linger_state property is not set.

Inherits xtd::object.

Public Member Functions

 linger_option ()=default
 Initializes a new instance of the xtd::net::sockets::linger_option class. More...
 
 linger_option (bool enabled, uint32_t linger_time)
 Initializes a new version of the xtd::net::sockets::linger_option class for the specified IP multicast group. More...
 
bool enabled () const noexcept
 Gets a value that indicates whether to linger after the xtd::net::sockets::socket is closed. More...
 
linger_optionenabled (bool value) noexcept
 Sets a value that indicates whether to linger after the xtd::net::sockets::socket is closed. More...
 
uint32_t linger_time () const noexcept
 Gets the amount of time to remain connected after calling the xtd::net::sockets::socket::close method if data remains to be sent. More...
 
linger_optionlinger_time (uint32_t value) noexcept
 Sets the amount of time to remain connected after calling the xtd::net::sockets::socket::close method if data remains to be sent. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ linger_option() [1/2]

xtd::net::sockets::linger_option::linger_option ( )
default

Initializes a new instance of the xtd::net::sockets::linger_option class.

◆ linger_option() [2/2]

xtd::net::sockets::linger_option::linger_option ( bool  enabled,
uint32_t  linger_time 
)

Initializes a new version of the xtd::net::sockets::linger_option class for the specified IP multicast group.

Parameters
enabledtrue to remain connected after the Socket.Close method is called; otherwise, false.
linger_timeThe number of seconds to remain connected after the Socket.Close method is called.
Remarks
There may still be data available in the outgoing network buffer after you close the Socket. Use the enable parameter to specify whether you would like the Socket to continue transmitting unsent data after the close method is called. Use the seconds parameter to indicate how long you would like the Socket to attempt transferring unsent data before timing out. If you specify true for the enable parameter and 0 for the seconds parameter, the Socket will attempt to send data until there is no data left in the outgoing network buffer. If you specify false for the enable parameter, the Socket will close immediately and any unsent data will be lost.
The following table describes the behavior on the xtd::net::sockets::socket::close and xtd::net::sockets::tcp_client::close methods based on the possible values of the enable and seconds parameters when an xtd::net::sockets::linger_option instance is created and set in the xtd::net::sockets::socket::linger_state or xtd::net::sockets::socket xtd::net::sockets::tcp_client::linger_state property.
enable seconds Behavior
false (disabled), the default value The time-out is not applicable, (default). Attempts to send pending data for a connection-oriented socket (TCP, for example) until the default IP protocol time-out expires.
true (enabled) A nonzero time-out Attempts to send pending data until the specified time-out expires, and if the attempt fails, then Winsock resets the connection.
true (enabled) A zero timeout. Discards any pending data. For connection-oriented socket (TCP, for example), Winsock resets the connection.
The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a socket when the xtd::net::sockets::socket::linger_state property is not set.
When the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property is set greater than the default IP protocol time-out, the default IP protocol time-out will still apply and virtual.

Member Function Documentation

◆ enabled() [1/2]

bool xtd::net::sockets::linger_option::enabled ( ) const
noexcept

Gets a value that indicates whether to linger after the xtd::net::sockets::socket is closed.

Returns
true if the xtd::net::sockets::socket should linger after xtd::net::sockets::socket::close is called; otherwise, false.
Remarks
You can use the xtd::net::sockets::linger_option::enabled property to determine whether the xtd::net::sockets::socket will linger after closing. Change this value to true or false and pass the altered xtd::net::sockets::linger_option to the xtd::net::sockets::socket::set_socket_option method or set the xtd::net::sockets::socket::linger_state or xtd::net::sockets::tcp_client::linger_state property to disable or enable lingering.
The following table describes the behavior on the xtd::net::sockets::socket::close and xtd::net::sockets::tcp_client::close methods based on the possible values of the enable and seconds parameters when an xtd::net::sockets::linger_option instance is created and set in the xtd::net::sockets::socket::linger_state or xtd::net::sockets::socket xtd::net::sockets::tcp_client::linger_state property.
enable seconds Behavior
false (disabled), the default value The time-out is not applicable, (default). Attempts to send pending data for a connection-oriented socket (TCP, for example) until the default IP protocol time-out expires.
true (enabled) A nonzero time-out Attempts to send pending data until the specified time-out expires, and if the attempt fails, then Winsock resets the connection.
true (enabled) A zero timeout. Discards any pending data. For connection-oriented socket (TCP, for example), Winsock resets the connection.
The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a socket when the xtd::net::sockets::socket::linger_state property is not set.
When the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property is set greater than the default IP protocol time-out, the default IP protocol time-out will still apply and virtual.

◆ enabled() [2/2]

linger_option& xtd::net::sockets::linger_option::enabled ( bool  value)
noexcept

Sets a value that indicates whether to linger after the xtd::net::sockets::socket is closed.

Parameters
valuetrue if the xtd::net::sockets::socket should linger after xtd::net::sockets::socket::close is called; otherwise, false.
Remarks
You can use the xtd::net::sockets::linger_option::enabled property to determine whether the xtd::net::sockets::socket will linger after closing. Change this value to true or false and pass the altered xtd::net::sockets::linger_option to the xtd::net::sockets::socket::set_socket_option method or set the xtd::net::sockets::socket::linger_state or xtd::net::sockets::tcp_client::linger_state property to disable or enable lingering.
The following table describes the behavior on the xtd::net::sockets::socket::close and xtd::net::sockets::tcp_client::close methods based on the possible values of the enable and seconds parameters when an xtd::net::sockets::linger_option instance is created and set in the xtd::net::sockets::socket::linger_state or xtd::net::sockets::socket xtd::net::sockets::tcp_client::linger_state property.
enable seconds Behavior
false (disabled), the default value The time-out is not applicable, (default). Attempts to send pending data for a connection-oriented socket (TCP, for example) until the default IP protocol time-out expires.
true (enabled) A nonzero time-out Attempts to send pending data until the specified time-out expires, and if the attempt fails, then Winsock resets the connection.
true (enabled) A zero timeout. Discards any pending data. For connection-oriented socket (TCP, for example), Winsock resets the connection.
The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a socket when the xtd::net::sockets::socket::linger_state property is not set.
When the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property is set greater than the default IP protocol time-out, the default IP protocol time-out will still apply and virtual.

◆ linger_time() [1/2]

uint32_t xtd::net::sockets::linger_option::linger_time ( ) const
noexcept

Gets the amount of time to remain connected after calling the xtd::net::sockets::socket::close method if data remains to be sent.

Returns
The amount of time, in seconds, to remain connected after calling xtd::net::sockets::socket::close.
Remarks
Use this value if you want to determine how long a closed xtd::net::sockets::socket will attempt to transfer unsent data before timing out. You can also set this value to the desired time-out period, in seconds.
If the xtd::net::sockets::linger_option::enabled property is true, and you set xtd::net::sockets::linger_option::linger_time to 0, the xtd::net::sockets::socket discards any pending data to send in the outgoing network buffer. If you change this value, you must pass the altered xtd::net::sockets::linger_option instance to the xtd::net::sockets::socket::set_socket_option method or set the xtd::net::sockets::socket::linger_state or xtd::net::sockets::tcp_client::linger_state property.
The following table describes the behavior on the xtd::net::sockets::socket::close and xtd::net::sockets::tcp_client::close methods based on the possible values of the enable and seconds parameters when an xtd::net::sockets::linger_option instance is created and set in the xtd::net::sockets::socket::linger_state or xtd::net::sockets::socket xtd::net::sockets::tcp_client::linger_state property.
enable seconds Behavior
false (disabled), the default value The time-out is not applicable, (default). Attempts to send pending data for a connection-oriented socket (TCP, for example) until the default IP protocol time-out expires.
true (enabled) A nonzero time-out Attempts to send pending data until the specified time-out expires, and if the attempt fails, then Winsock resets the connection.
true (enabled) A zero timeout. Discards any pending data. For connection-oriented socket (TCP, for example), Winsock resets the connection.
The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a socket when the xtd::net::sockets::socket::linger_state property is not set.
When the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property is set greater than the default IP protocol time-out, the default IP protocol time-out will still apply and virtual.

◆ linger_time() [2/2]

linger_option& xtd::net::sockets::linger_option::linger_time ( uint32_t  value)
noexcept

Sets the amount of time to remain connected after calling the xtd::net::sockets::socket::close method if data remains to be sent.

Parameters
valueThe amount of time, in seconds, to remain connected after calling xtd::net::sockets::socket::close.
Remarks
Use this value if you want to determine how long a closed xtd::net::sockets::socket will attempt to transfer unsent data before timing out. You can also set this value to the desired time-out period, in seconds.
If the xtd::net::sockets::linger_option::enabled property is true, and you set xtd::net::sockets::linger_option::linger_time to 0, the xtd::net::sockets::socket discards any pending data to send in the outgoing network buffer. If you change this value, you must pass the altered xtd::net::sockets::linger_option instance to the xtd::net::sockets::socket::set_socket_option method or set the xtd::net::sockets::socket::linger_state or xtd::net::sockets::tcp_client::linger_state property.
The following table describes the behavior on the xtd::net::sockets::socket::close and xtd::net::sockets::tcp_client::close methods based on the possible values of the enable and seconds parameters when an xtd::net::sockets::linger_option instance is created and set in the xtd::net::sockets::socket::linger_state or xtd::net::sockets::socket xtd::net::sockets::tcp_client::linger_state property.
enable seconds Behavior
false (disabled), the default value The time-out is not applicable, (default). Attempts to send pending data for a connection-oriented socket (TCP, for example) until the default IP protocol time-out expires.
true (enabled) A nonzero time-out Attempts to send pending data until the specified time-out expires, and if the attempt fails, then Winsock resets the connection.
true (enabled) A zero timeout. Discards any pending data. For connection-oriented socket (TCP, for example), Winsock resets the connection.
The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a socket when the xtd::net::sockets::socket::linger_state property is not set.
When the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property is set greater than the default IP protocol time-out, the default IP protocol time-out will still apply and virtual.

The documentation for this class was generated from the following file: