OSDN Git Service

Fix create socket error and add retry when send fail.
authorFrank Li <lznuaa@gmail.com>
Sat, 18 Apr 2009 13:41:02 +0000 (21:41 +0800)
committerFrank Li <lznuaa@gmail.com>
Sat, 18 Apr 2009 13:41:02 +0000 (21:41 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/Resources/TortoiseProcENG.rc
src/TortoiseProc/SVNProgressDlg.cpp
src/TortoiseProc/SVNProgressDlg.h
src/TortoiseProc/resource.h
src/Utils/HwSMTP.cpp

index b27fb36..299d3d8 100644 (file)
Binary files a/src/Resources/TortoiseProcENG.rc and b/src/Resources/TortoiseProcENG.rc differ
index 9e5948e..9a9e105 100644 (file)
@@ -68,17 +68,18 @@ enum SVNProgressDlgContextMenuCommands
 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)\r
 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)\r
        : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)\r
+       , m_bCancelled(FALSE)\r
+       , m_pThread(NULL)\r
 #if 0\r
        , m_Revision(_T("HEAD"))\r
        //, m_RevisionEnd(0)\r
        , m_bLockWarning(false)\r
        , m_bLockExists(false)\r
-       , m_bCancelled(FALSE)\r
        , m_bThreadRunning(FALSE)\r
        , m_nConflicts(0)\r
        , m_bErrorsOccurred(FALSE)\r
        , m_bMergesAddsDeletesOccurred(FALSE)\r
-       , m_pThread(NULL)\r
+       \r
        , m_options(ProgOptNone)\r
        , m_dwCloseOnEnd((DWORD)-1)\r
        , m_bFinishedItemAdded(false)\r
@@ -294,6 +295,12 @@ BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t actio
                data->color = m_Colors.GetColor(CColors::Modified);\r
                break;\r
 \r
+       case git_wc_notify_sendmail_retry:\r
+               data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);\r
+               data->sPathColumnText.Empty();\r
+               data->color = m_Colors.GetColor(CColors::Modified);\r
+               break;\r
+\r
 \r
        case git_wc_notify_resolved:\r
                data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);\r
@@ -2715,7 +2722,7 @@ bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*
                CTGitPath path;\r
                Notify(path,git_wc_notify_sendmail_start);\r
                CString err;\r
-               if(CPatch::Send(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,this->m_SendMailFlags&SENDMAIL_COMBINED,&err))\r
+               if(CPatch::Send(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,this->m_SendMailFlags&SENDMAIL_ATTACHMENT,&err))\r
                {\r
                        Notify(path,git_wc_notify_sendmail_error,ret,&err);\r
                        ret = false;\r
@@ -2730,16 +2737,31 @@ bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*
                {\r
                        CPatch patch;\r
                        Notify(m_targetPathList[i],git_wc_notify_sendmail_start);\r
-                       int ret=patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,\r
-                                        this->m_SendMailCC,this->m_SendMailFlags&SENDMAIL_ATTACHMENT);\r
-                       if(ret)\r
+\r
+                       int retry=0;\r
+                       while(retry<3)\r
                        {\r
-                               Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);\r
-                               ret = false;\r
+                               int ret=patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,\r
+                                        this->m_SendMailCC,this->m_SendMailFlags&SENDMAIL_ATTACHMENT);\r
+                               if(ret)\r
+                               {\r
+                                       Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);\r
+                                       ret = false;\r
+                               }else\r
+                                       break;\r
+\r
+                               Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);\r
+\r
+                               retry++;\r
+                               Sleep(2000);\r
+                               if(m_bCancelled)\r
+                               {\r
+                                       Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&CString("User Canceled"));\r
+                                   return false;\r
+                               }\r
                        }\r
                        Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);\r
-                       if(m_bCancelled)\r
-                               return false;\r
+                       \r
                }\r
        }\r
        return ret;\r
index 645e558..a99784f 100644 (file)
@@ -71,8 +71,9 @@ typedef enum
        git_wc_notify_add,\r
        git_wc_notify_sendmail_start,\r
        git_wc_notify_sendmail_error,\r
+       git_wc_notify_sendmail_retry,\r
        git_wc_notify_sendmail_done,\r
-       git_wc_notify_resolved\r
+       git_wc_notify_resolved,\r
 \r
 }git_wc_notify_action_t;\r
 typedef enum\r
index ed8db1c..e295fc9 100644 (file)
Binary files a/src/TortoiseProc/resource.h and b/src/TortoiseProc/resource.h differ
index ec51322..3228eb8 100644 (file)
@@ -97,6 +97,8 @@ CHwSMTP::CHwSMTP () :
        m_csPartBoundary = _T( "WC_MAIL_PaRt_BoUnDaRy_05151998" );\r
        m_csNoMIMEText = _T( "This is a multi-part message in MIME format." );\r
        //m_csCharSet = _T("\r\n\tcharset=\"iso-8859-1\"\r\n");\r
+\r
+       AfxSocketInit();\r
 }\r
 \r
 CHwSMTP::~CHwSMTP()\r
@@ -183,10 +185,11 @@ BOOL CHwSMTP::SendSpeedEmail
        std::map<CString,std::vector<CString>>::iterator itr1  =  Address.begin();\r
     for(  ;  itr1  !=  Address.end();  ++itr1 )\r
     {\r
-        PDNS_RECORD pDnsRecord; \r
-\r
+        PDNS_RECORD pDnsRecord;\r
+               PDNS_RECORD pNext;\r
+               \r
                DnsQuery(itr1->first ,\r
-                                   DNS_TYPE_MX,DNS_QUERY_BYPASS_CACHE,\r
+                                   DNS_TYPE_MX,DNS_QUERY_STANDARD,\r
                                            NULL,                   //Contains DNS server IP address.\r
                         &pDnsRecord,                //Resource record that contains the response.\r
                         NULL\r
@@ -202,9 +205,17 @@ BOOL CHwSMTP::SendSpeedEmail
                if(to.IsEmpty())\r
                        continue;\r
 \r
-               if(!SendEmail(pDnsRecord->Data.MX.pNameExchange,NULL,NULL,false,\r
+               pNext=pDnsRecord;\r
+               while(pNext)\r
+               {\r
+               \r
+                       if(SendEmail(pNext->Data.MX.pNameExchange,NULL,NULL,false,\r
                                lpszAddrFrom,to,lpszSubject,lpszBody,lpszCharSet,pStrAryAttach,pStrAryCC,\r
                                25,pSend,lpszAddrTo))\r
+                               break;\r
+                       pNext=pNext->pNext;\r
+               }\r
+               if(pNext == NULL)\r
                        ret = false;\r
 \r
                //SendEmail(itr1.first,NULL,NULL,false,lpszAddrFrom,,lpszFromname);\r
@@ -284,6 +295,7 @@ BOOL CHwSMTP::SendEmail (
        m_SendSock.Close();\r
        if ( !m_SendSock.Create () )\r
        {\r
+               int nResult = GetLastError();\r
                m_csLastError.Format ( _T("Create socket failed!") );\r
                return FALSE;\r
        }\r
@@ -298,8 +310,11 @@ BOOL CHwSMTP::SendEmail (
        if ( !GetResponse( _T("220") ) ) return FALSE;\r
 \r
        m_bConnected = TRUE;\r
-       return SendEmail();\r
+       BOOL ret= SendEmail();\r
+\r
+       m_SendSock.Close();\r
 \r
+       return ret;\r
 }\r
 \r
 \r