2008-08-12 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 12 Aug 2008 16:39:56 +0000 (16:39 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 12 Aug 2008 16:39:56 +0000 (16:39 -0000)
* SmtpClient.cs : fixed bug #392682, in the same spirit in the
  patch by Ted Unangst, to assure safety on socket closing.

svn path=/trunk/mcs/; revision=110263

mcs/class/System/System.Net.Mail/ChangeLog
mcs/class/System/System.Net.Mail/SmtpClient.cs

index 992efb57d688fdf1284c2fb91c1876dac6cd8e09..060f49c945250860f04452edcc7dc986e27c6336 100644 (file)
@@ -1,3 +1,8 @@
+2008-08-12  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * SmtpClient.cs : fixed bug #392682, in the same spirit in the
+         patch by Ted Unangst, to assure safety on socket closing.
+
 2008-08-07  Atsushi Enomoto  <atsushi@ximian.com>
 
        * SmtpClient.cs : Fixed bug #392809, patch by Ted Unangst. Text body
index d2b6cee83ec2e64314ee187efc44d821f9ae4f8e..99648257a08f5dd60a2e64f8223e4839a26cd8d1 100644 (file)
@@ -443,7 +443,7 @@ namespace System.Net.Mail {
                        mutex.WaitOne ();
                        try {
                                messageInProcess = message;
-                               SendCore (message);
+                               SendInternal (message);
                        } catch (CancellationException) {
                                // This exception is introduced for convenient cancellation process.
                        } finally {
@@ -453,19 +453,35 @@ namespace System.Net.Mail {
                        }
                }
 
-               private void SendCore (MailMessage message)
+               private void SendInternal (MailMessage message)
                {
-                       SmtpResponse status;
-
                        CheckCancellation ();
 
-                       client = new TcpClient (host, port);
-                       stream = client.GetStream ();
-                       // FIXME: this StreamWriter creation is bogus.
-                       // It expects as if a Stream were able to switch to SSL
-                       // mode (such behavior is only in Mainsoft Socket API).
-                       writer = new StreamWriter (stream);
-                       reader = new StreamReader (stream);
+                       try {
+                               client = new TcpClient (host, port);
+                               stream = client.GetStream ();
+                               // FIXME: this StreamWriter creation is bogus.
+                               // It expects as if a Stream were able to switch to SSL
+                               // mode (such behavior is only in Mainsoft Socket API).
+                               writer = new StreamWriter (stream);
+                               reader = new StreamReader (stream);
+
+                               SendCore (message);
+                       } finally {
+                               if (writer != null)
+                                       writer.Close ();
+                               if (reader != null)
+                                       reader.Close ();
+                               if (stream != null)
+                                       stream.Close ();
+                               if (client != null)
+                                       client.Close ();
+                       }
+               }
+
+               private void SendCore (MailMessage message)
+               {
+                       SmtpResponse status;
 
                        status = Read ();
                        if (IsError (status))
@@ -605,11 +621,6 @@ namespace System.Net.Mail {
                        } catch (System.IO.IOException) {
                                // We excuse server for the rude connection closing as a response to QUIT
                        }
-
-                       writer.Close ();
-                       reader.Close ();
-                       stream.Close ();
-                       client.Close ();
                }
 
                public void Send (string from, string to, string subject, string body)