For Programmers: Free Programming Magazines  


Home > Archive > C# > January 2006 > A question about Socket.Close Method [C#] - misbehaviour in MSDN









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author A question about Socket.Close Method [C#] - misbehaviour in MSDN
Dmitry Klymenko

2005-07-28, 9:09 am

Please see the Socket.Close page in MSDN.
There are such line in Remarks:

"The Close method closes the the remote host connection and releases all managed and unmanaged resources associated with the Socket.
Upon closing, the Connected property is set to false."

Please note the last (bold) sentence.
And see the example (on same page):
The following example closes a Socket.
[C#]
aSocket.Shutdown(SocketShutdown.Both);
aSocket.Close();
if (aSocket.Connected) {
Console.WriteLine("Winsock error: " + Convert.ToString(System.Runtime.InteropServices.Marshal.GetLastWin32Error()) );
}What is the sence of checking Connected property of the socket if a method line up will set this property false !
To my opinion the only reason is incorrect error hadling in method Close(). Why it doesn't throw an exception if it failed to do it's work?
Same in beta 2.0 doc.

Could some one describe this?
Ciaran

2006-01-10, 4:09 am

This does appear to be necessary as the Close method will always set the Connected property to false but if the disconnection fails the is a method
internal void UpdateStatusAfterSocketError()


which seems to try to empty the buffer. If this works fine or fails with a particular set of error codes, the property is set back to true.

This is from what I can work out in about 10 minutes.

Ciaran
"Dmitry Klymenko" <test@proofingonline.com> wrote in message news:dca9ql$878$1@news.dg.net.ua...
Please see the Socket.Close page in MSDN.
There are such line in Remarks:

"The Close method closes the the remote host connection and releases all managed and unmanaged resources associated with the Socket.
Upon closing, the Connected property is set to false."

Please note the last (bold) sentence.
And see the example (on same page):
The following example closes a Socket.
[C#]
aSocket.Shutdown(SocketShutdown.Both);
aSocket.Close();
if (aSocket.Connected) {
Console.WriteLine("Winsock error: " + Convert.ToString(System.Runtime.InteropServices.Marshal.GetLastWin32Error()) );
}What is the sence of checking Connected property of the socket if a method line up will set this property false !
To my opinion the only reason is incorrect error hadling in method Close(). Why it doesn't throw an exception if it failed to do it's work?
Same in beta 2.0 doc.

Could some one describe this?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com