From d896e8ed89041c97a3a1777986caf61c946f153e Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 12 Aug 2008 16:39:56 +0000 Subject: [PATCH] 2008-08-12 Atsushi Enomoto * 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 | 5 +++ .../System/System.Net.Mail/SmtpClient.cs | 43 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/mcs/class/System/System.Net.Mail/ChangeLog b/mcs/class/System/System.Net.Mail/ChangeLog index 992efb57d68..060f49c9452 100644 --- a/mcs/class/System/System.Net.Mail/ChangeLog +++ b/mcs/class/System/System.Net.Mail/ChangeLog @@ -1,3 +1,8 @@ +2008-08-12 Atsushi Enomoto + + * 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 * SmtpClient.cs : Fixed bug #392809, patch by Ted Unangst. Text body diff --git a/mcs/class/System/System.Net.Mail/SmtpClient.cs b/mcs/class/System/System.Net.Mail/SmtpClient.cs index d2b6cee83ec..99648257a08 100644 --- a/mcs/class/System/System.Net.Mail/SmtpClient.cs +++ b/mcs/class/System/System.Net.Mail/SmtpClient.cs @@ -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) -- 2.25.1