public class LingerOption
Object
LingerOption
System
Networking
Maintains information that specifies how a Socket instance with pending data behaves when the System.Net.Sockets.Socket.Close method of the socket is called.
An instance of this class is passed into the System.Net.Sockets.Socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,System.Int32) method and is returned by the System.Net.Sockets.Socket.GetSocketOption(System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName) method when the optionName parameter is set to System.Net.Sockets.SocketOptionName.Linger.When the System.Net.Sockets.LingerOption.Enabled property is
true
, any queued data continues to be sent until time equal to the setting of the System.Net.Sockets.LingerOption.LingerTime property has passed or until the input queue is empty. At this time, the connection is closed.When the System.Net.Sockets.LingerOption.LingerTime property is zero or the System.Net.Sockets.LingerOption.Enabled property is
false
, calling System.Net.Sockets.Socket.Close immediately closes the socket and any pending data is lost.When setting the System.Net.Sockets.SocketOptionName.Linger option of an instance of the Socket class, a ArgumentException exception is thrown if the System.Net.Sockets.LingerOption.LingerTime property is less than zero or greater than System.UInt16.MaxValue.
System.Net.Sockets Namespace
LingerOption Constructors
LingerOption Properties
LingerOption.Enabled Property
LingerOption.LingerTime Property
public LingerOption(bool enable, int seconds);
Constructs and initializes a new instance of the LingerOption class.
- enable
- A Boolean where
true
enables the linger option andfalse
disables the option.- seconds
- A Int32 that contains the number of seconds to remain connected after the System.Net.Sockets.Socket.Close method is called.
The LingerOption instance is created with the System.Net.Sockets.LingerOption.Enabled property set to enable and the System.Net.Sockets.LingerOption.LingerTime property set to seconds.
System.Net.Sockets.LingerOption Class, System.Net.Sockets Namespace
public bool Enabled { get; set; }
Gets or sets a Boolean value indicating whether the connection remains open (lingers) for a period of time after the System.Net.Sockets.Socket.Close method is called.
true
to enable lingering after the System.Net.Sockets.Socket.Close method is called; otherwisefalse
.
System.Net.Sockets.LingerOption Class, System.Net.Sockets Namespace
public int LingerTime { get; set; }
Gets or sets the amount of time to remain connected after the System.Net.Sockets.Socket.Close method is called.
A Int32 that contains the amount of time, in seconds, to remain connected after calling the System.Net.Sockets.Socket.Close method.
When setting the System.Net.Sockets.SocketOptionName.Linger option of an instance of the Socket class, a ArgumentException exception is thrown if the System.Net.Sockets.LingerOption.LingerTime property is less than zero or greater than System.UInt16.MaxValue .
System.Net.Sockets.LingerOption Class, System.Net.Sockets Namespace