G
Guest
Context:
C#
System.Net.Sockets
Socket created with constructor prarmeters Internetwork, Stream and TCP
everything else is left at the default parameters and options except linger
may be changed as I find appropriate.
I am using the socket asynchronously by calling the BeingSend and
BeginReceive calls. I would like to be able to call shutdown and close
asynchronously if possible.
As far as I understand from the MSDN documentation calling
Socket.Shutdown on a socket will ensure that all data in the send buffer will
get sent to the remote host before the socket is closed. I also understand
that the linger socket option can be used to set how long the socket will try
to send any data in the send buffer before giving up and closing the socket.
The MSDN documentation for Socket.Close states:
If you need to call Close without first calling Shutdown, you can ensure
that data queued for outgoing transmission will be sent by setting the
DontLinger Socket option to false and specifying a non-zero time-out
interval. Close will then block until this data is sent or until the
specified time-out expires.
So it appears from the documentation excerpt that a call to Socket.Shutdown
is not necessary as long as linger is enabled and set to the desired timeout
before calling Socket.Close, is this true?
My questions are these:
*Does the linger option affect Socket.Shutdown in any way? If so, what way
or ways?
*Does Socket.Shutdown block while sending the data in the socket's send
buffer or does it simply delegate the blocking to close?
If so, where is the asynchronous method for Socket.Shutdown so I don't have
to waste a thread just to babysit the shutdown.
*If Socket.Close blocks while sending the remaining data in the send buffer
(as indicated by the MSDN excerpt above) how can I call this asynchronously
close a lingering socket without tying up a threadpool thread for 10 seconds
or so (an eternity to be using a threadpool thread in a server application)?
Thanks,
C#
System.Net.Sockets
Socket created with constructor prarmeters Internetwork, Stream and TCP
everything else is left at the default parameters and options except linger
may be changed as I find appropriate.
I am using the socket asynchronously by calling the BeingSend and
BeginReceive calls. I would like to be able to call shutdown and close
asynchronously if possible.
As far as I understand from the MSDN documentation calling
Socket.Shutdown on a socket will ensure that all data in the send buffer will
get sent to the remote host before the socket is closed. I also understand
that the linger socket option can be used to set how long the socket will try
to send any data in the send buffer before giving up and closing the socket.
The MSDN documentation for Socket.Close states:
If you need to call Close without first calling Shutdown, you can ensure
that data queued for outgoing transmission will be sent by setting the
DontLinger Socket option to false and specifying a non-zero time-out
interval. Close will then block until this data is sent or until the
specified time-out expires.
So it appears from the documentation excerpt that a call to Socket.Shutdown
is not necessary as long as linger is enabled and set to the desired timeout
before calling Socket.Close, is this true?
My questions are these:
*Does the linger option affect Socket.Shutdown in any way? If so, what way
or ways?
*Does Socket.Shutdown block while sending the data in the socket's send
buffer or does it simply delegate the blocking to close?
If so, where is the asynchronous method for Socket.Shutdown so I don't have
to waste a thread just to babysit the shutdown.
*If Socket.Close blocks while sending the remaining data in the send buffer
(as indicated by the MSDN excerpt above) how can I call this asynchronously
close a lingering socket without tying up a threadpool thread for 10 seconds
or so (an eternity to be using a threadpool thread in a server application)?
Thanks,