System.Net.Sockets.LingerOption Class

public class LingerOption

Base Types

Object
  LingerOption

Assembly

System

Library

Networking

Summary

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.

Description

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.

See Also

System.Net.Sockets Namespace

Members

LingerOption Constructors

LingerOption Constructor

LingerOption Properties

LingerOption.Enabled Property
LingerOption.LingerTime Property


LingerOption Constructor

public LingerOption(bool enable, int seconds);

Summary

Constructs and initializes a new instance of the LingerOption class.

Parameters

enable
A Boolean where true enables the linger option and false 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.

Description

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.

See Also

System.Net.Sockets.LingerOption Class, System.Net.Sockets Namespace

LingerOption.Enabled Property

public bool Enabled { get; set; }

Summary

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.

Property Value

true to enable lingering after the System.Net.Sockets.Socket.Close method is called; otherwise false .

See Also

System.Net.Sockets.LingerOption Class, System.Net.Sockets Namespace

LingerOption.LingerTime Property

public int LingerTime { get; set; }

Summary

Gets or sets the amount of time to remain connected after the System.Net.Sockets.Socket.Close method is called.

Property Value

A Int32 that contains the amount of time, in seconds, to remain connected after calling the System.Net.Sockets.Socket.Close method.

Description

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 .

See Also

System.Net.Sockets.LingerOption Class, System.Net.Sockets Namespace