From d5d69c4e06c1284add91012d52eeda8a45096321 Mon Sep 17 00:00:00 2001 From: "syd%netscape.com" Date: Sun, 13 May 2001 00:45:45 +0000 Subject: [PATCH] Fix for 78282 r=ssu, sr=mscott git-svn-id: svn://10.0.0.236/trunk@94799 18797224-902f-48f8-a5cc-f745e15eee43 --- .../wizard/libxpnet/src/nsFTPConn.cpp | 17 +++++- .../xpinstall/wizard/libxpnet/src/nsFTPConn.h | 2 + .../wizard/libxpnet/src/nsHTTPConn.cpp | 53 ++++++++++++++++++- .../wizard/libxpnet/src/nsHTTPConn.h | 4 ++ .../wizard/libxpnet/src/nsSocket.cpp | 17 +++++- .../xpinstall/wizard/libxpnet/src/nsSocket.h | 4 +- .../xpinstall/wizard/unix/src2/nsXIEngine.cpp | 11 ++-- .../wizard/windows/setup/xpnetHook.cpp | 28 ++++++++-- 8 files changed, 124 insertions(+), 12 deletions(-) diff --git a/mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.cpp b/mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.cpp index 95e961ae67c..6c94a43fb82 100644 --- a/mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.cpp +++ b/mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.cpp @@ -48,7 +48,18 @@ const int kKilobyte = 1024; const int kUsecsPerSec = 1000000; const int kDlBufSize = 1024; +nsFTPConn::nsFTPConn(char *aHost, int (*aEventPumpCB)(void)) : + mEventPumpCB(aEventPumpCB), + mHost(aHost), + mState(CLOSED), + mPassive(FALSE), + mCntlSock(NULL), + mDataSock(NULL) +{ +} + nsFTPConn::nsFTPConn(char *aHost) : + mEventPumpCB(NULL), mHost(aHost), mState(CLOSED), mPassive(FALSE), @@ -238,6 +249,8 @@ nsFTPConn::Get(char *aSrvPath, char *aLoclPath, int aType, int aResumePos, err = E_WRITE; goto BAIL; } + if ( mEventPumpCB ) + mEventPumpCB(); } while (err == nsSocket::E_READ_MORE || err == nsSocket::OK); if (err == nsSocket::E_EOF_FOUND) @@ -312,7 +325,9 @@ nsFTPConn::IssueCmd(char *aCmd, char *aResp, int aRespSize, nsSocket *aSock) err != nsSocket::E_EOF_FOUND) goto BAIL; DUMP(aResp); - } + if ( mEventPumpCB ) + mEventPumpCB(); + } while (err == nsSocket::E_READ_MORE); /* alternate interpretation of err codes */ diff --git a/mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.h b/mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.h index 99d020314fb..ece254a0f46 100644 --- a/mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.h +++ b/mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.h @@ -33,6 +33,7 @@ class nsFTPConn { public: nsFTPConn(char *aHost); + nsFTPConn(char *aHost, int (*aEventPumpCB)(void)); ~nsFTPConn(); /* ftp type */ @@ -88,6 +89,7 @@ private: int ParseAddr(char *aBuf, char **aHost, int *aPort); int DataInit(char *aHost, int aPort, nsSocket **aSock); + int (*mEventPumpCB)(void); char *mHost; int mState; int mPassive; diff --git a/mozilla/xpinstall/wizard/libxpnet/src/nsHTTPConn.cpp b/mozilla/xpinstall/wizard/libxpnet/src/nsHTTPConn.cpp index 6ac7e4a818f..3030a17e842 100644 --- a/mozilla/xpinstall/wizard/libxpnet/src/nsHTTPConn.cpp +++ b/mozilla/xpinstall/wizard/libxpnet/src/nsHTTPConn.cpp @@ -41,7 +41,8 @@ const char kCRLF[3] = "\r\n"; const char kHdrBodyDelim[5] = "\r\n\r\n"; const char kDefaultDestFile[11] = "index.html"; -nsHTTPConn::nsHTTPConn(char *aHost, int aPort, char *aPath) : +nsHTTPConn::nsHTTPConn(char *aHost, int aPort, char *aPath, int (*aEventPumpCB)(void)): + mEventPumpCB(aEventPumpCB), mHost(aHost), mPath(aPath), mProxiedURL(NULL), @@ -61,7 +62,53 @@ nsHTTPConn::nsHTTPConn(char *aHost, int aPort, char *aPath) : DUMP(("mPath = %s\n", mPath)); } +nsHTTPConn::nsHTTPConn(char *aHost, int aPort, char *aPath) : + mEventPumpCB(NULL), + mHost(aHost), + mPath(aPath), + mProxiedURL(NULL), + mProxyUser(NULL), + mProxyPswd(NULL), + mDestFile(NULL), + mHostPathAllocd(FALSE), + mSocket(NULL) +{ + if (aPort <= 0) + mPort = kHTTPPort; + else + mPort = aPort; + + DUMP(("mHost = %s\n", mHost)); + DUMP(("mPort = %d\n", mPort)); + DUMP(("mPath = %s\n", mPath)); +} + +nsHTTPConn::nsHTTPConn(char *aURL, int (*aEventPumpCB)(void)) : + mEventPumpCB(aEventPumpCB), + mPort(kHTTPPort), + mProxiedURL(NULL), + mProxyUser(NULL), + mProxyPswd(NULL), + mDestFile(NULL), + mHostPathAllocd(FALSE), + mSocket(NULL) +{ + // parse URL + if (ParseURL(kHTTPProto, aURL, &mHost, &mPort, &mPath) == OK) + mHostPathAllocd = TRUE; + else + { + mHost = NULL; + mPath = NULL; + } + + DUMP(("mHost = %s\n", mHost)); + DUMP(("mPort = %d\n", mPort)); + DUMP(("mPath = %s\n", mPath)); +} + nsHTTPConn::nsHTTPConn(char *aURL) : + mEventPumpCB(NULL), mPort(kHTTPPort), mProxiedURL(NULL), mProxyUser(NULL), @@ -380,7 +427,9 @@ nsHTTPConn::Response(HTTPGetCB aCallback, char *aDestFile, int aResumePos) rv = E_USER_CANCEL; // we want to ignore all errors returned // from aCallback() except E_USER_CANCEL - } while (rv == nsSocket::E_READ_MORE || rv == nsSocket::OK); + if ( mEventPumpCB ) + mEventPumpCB(); + } while (rv == nsSocket::E_READ_MORE || rv == nsSocket::OK); if (rv == nsSocket::E_EOF_FOUND) { diff --git a/mozilla/xpinstall/wizard/libxpnet/src/nsHTTPConn.h b/mozilla/xpinstall/wizard/libxpnet/src/nsHTTPConn.h index c845c8dafc3..7a275543f8b 100644 --- a/mozilla/xpinstall/wizard/libxpnet/src/nsHTTPConn.h +++ b/mozilla/xpinstall/wizard/libxpnet/src/nsHTTPConn.h @@ -34,12 +34,15 @@ class nsHTTPConn public: nsHTTPConn(char *aHost, int aPort, char *aPath); nsHTTPConn(char *aURL); + nsHTTPConn(char *aHost, int aPort, char *aPath, int (*aEventPumpCB)(void)); + nsHTTPConn(char *aURL, int (*aEventPumpCB)(void)); ~nsHTTPConn(); int Open(); int ResumeOrGet(HTTPGetCB aCallback, char *aDestFile); int Get(HTTPGetCB aCallback, char *aDestFile); int Get(HTTPGetCB aCallback, char *aDestFile, int aResumePos); + int Close(); void SetProxyInfo(char *aProxiedURL, char *aProxyUser, @@ -67,6 +70,7 @@ private: int Base64Encode(const unsigned char *in_str, int in_len, char *out_str, int out_len); + int (*mEventPumpCB)(void); char *mHost; char *mPath; int mPort; diff --git a/mozilla/xpinstall/wizard/libxpnet/src/nsSocket.cpp b/mozilla/xpinstall/wizard/libxpnet/src/nsSocket.cpp index 551fc9212f2..798cf342f11 100644 --- a/mozilla/xpinstall/wizard/libxpnet/src/nsSocket.cpp +++ b/mozilla/xpinstall/wizard/libxpnet/src/nsSocket.cpp @@ -68,8 +68,18 @@ const int kReadBufSize = 1024; static int sbWinSockInited = FALSE; #endif +nsSocket::nsSocket(char *aHost, int aPort, int (*aEventPumpCB)(void)) : + mHost(aHost), + mEventPumpCB( aEventPumpCB ), + mPort(aPort), + mFd(-1), + mListenFd(-1) +{ +} + nsSocket::nsSocket(char *aHost, int aPort) : mHost(aHost), + mEventPumpCB( NULL ), mPort(aPort), mFd(-1), mListenFd(-1) @@ -253,6 +263,8 @@ nsSocket::Send(unsigned char *aBuf, int *aBufSize) if (!FD_ISSET(mFd, &selset)) { timeout += kTimeoutSelectUsecs; + if ( mEventPumpCB != NULL ) + mEventPumpCB(); continue; /* not ready to write; retry */ } else @@ -312,8 +324,11 @@ nsSocket::Recv(unsigned char *aBuf, int *aBufSize) } // XXX TODO: prevent inf loop returning at kTimeoutThresholdUsecs - if (!FD_ISSET(mFd, &selset)) + if (!FD_ISSET(mFd, &selset)) { + if ( mEventPumpCB != NULL ) + mEventPumpCB(); continue; /* not ready to read; retry */ + } bufsize = *aBufSize - bytesrd; rv = read(mFd, lbuf, bufsize); diff --git a/mozilla/xpinstall/wizard/libxpnet/src/nsSocket.h b/mozilla/xpinstall/wizard/libxpnet/src/nsSocket.h index 79efcf208ed..557d5a3fc3c 100644 --- a/mozilla/xpinstall/wizard/libxpnet/src/nsSocket.h +++ b/mozilla/xpinstall/wizard/libxpnet/src/nsSocket.h @@ -33,6 +33,7 @@ class nsSocket { public: nsSocket(char *aHost, int aPort); + nsSocket(char *aHost, int aPort, int (*aEventPumpCB)(void) ); ~nsSocket(); //---------------------------------------------------------------------- @@ -76,7 +77,8 @@ public: float CalcRate(struct timeval *aPre, struct timeval *aPost, int aBytes); private: - char *mHost; + int (*mEventPumpCB)(void); + char *mHost; int mPort; int mFd; // connected socket int mListenFd; // listening socket (only if SrvOpen() was called) diff --git a/mozilla/xpinstall/wizard/unix/src2/nsXIEngine.cpp b/mozilla/xpinstall/wizard/unix/src2/nsXIEngine.cpp index edbcf72c28e..f02e2c5ceff 100644 --- a/mozilla/xpinstall/wizard/unix/src2/nsXIEngine.cpp +++ b/mozilla/xpinstall/wizard/unix/src2/nsXIEngine.cpp @@ -52,6 +52,11 @@ nsXIEngine::~nsXIEngine() XI_IF_FREE(mOriginalDir); } +int +EventPumpCB(void) +{ +} + int nsXIEngine::Download(int aCustom, nsComponentList *aComps) { @@ -142,7 +147,7 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps) sprintf(proxyURL, "%s%s:%s", kHTTPProto, gCtx->opt->mProxyHost, gCtx->opt->mProxyPort); - nsHTTPConn *conn = new nsHTTPConn(proxyURL); + nsHTTPConn *conn = new nsHTTPConn(proxyURL, EventPumpCB); if (!conn) { err = E_MEM; @@ -189,7 +194,7 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps) } sprintf(qualURL, "%s%s", currURL, currComp->GetArchive()); - nsHTTPConn *conn = new nsHTTPConn(qualURL); + nsHTTPConn *conn = new nsHTTPConn(qualURL, EventPumpCB); if (!conn) { err = E_MEM; @@ -228,7 +233,7 @@ nsXIEngine::Download(int aCustom, nsComponentList *aComps) } sprintf(srvPath, "%s%s", currPath, currComp->GetArchive()); - nsFTPConn *conn = new nsFTPConn(currHost); + nsFTPConn *conn = new nsFTPConn(currHost, EventPumpCB); if (!conn) { err = E_MEM; diff --git a/mozilla/xpinstall/wizard/windows/setup/xpnetHook.cpp b/mozilla/xpinstall/wizard/windows/setup/xpnetHook.cpp index a96d59b2c2e..36264c17f5f 100644 --- a/mozilla/xpinstall/wizard/windows/setup/xpnetHook.cpp +++ b/mozilla/xpinstall/wizard/windows/setup/xpnetHook.cpp @@ -445,6 +445,26 @@ void GetTotalArchivesToDownload(int *iTotalArchivesToDownload, DWORD *dwTotalEst *iTotalArchivesToDownload = iIndex; } +/* + * Name: ProcessWndMsgCB + * + * Arguments: None + * + * Description: Callback function invoked by socket code and by FTP and HTTP layers + * to give the UI a chance to breath while we are in a look processing + * incoming data, or looping in select() + * + * Author: syd@netscape.com 5/11/2001 + * +*/ + +int +ProcessWndMsgCB() +{ + ProcessWindowsMessages(); + return 0; +} + /* Function used only to send the message stream error */ int WGet(char *szUrl, char *szProxyServer, @@ -477,7 +497,7 @@ int WGet(char *szUrl, else { /* no proxy information supplied. set up normal http object */ - conn = new nsHTTPConn(szUrl); + conn = new nsHTTPConn(szUrl, ProcessWndMsgCB); if(conn == NULL) return(WIZ_OUT_OF_MEMORY); } @@ -504,7 +524,7 @@ int DownloadViaProxy(char *szUrl, char *szProxyServer, char *szProxyPort, char * memset(proxyURL, 0, kProxySrvrLen); wsprintf(proxyURL, "http://%s:%s", szProxyServer, szProxyPort); - nsHTTPConn *conn = new nsHTTPConn(proxyURL); + nsHTTPConn *conn = new nsHTTPConn(proxyURL, ProcessWndMsgCB); if(conn == NULL) { char szBuf[MAX_BUF_TINY]; @@ -538,7 +558,7 @@ int DownloadViaHTTP(char *szUrl) int rv; rv = nsHTTPConn::OK; - nsHTTPConn *conn = new nsHTTPConn(szUrl); + nsHTTPConn *conn = new nsHTTPConn(szUrl, ProcessWndMsgCB); if(conn == NULL) { char szBuf[MAX_BUF_TINY]; @@ -569,7 +589,7 @@ int DownloadViaFTP(char *szUrl) rv = nsHTTPConn::ParseURL(kFTP, szUrl, &host, &port, &path); - nsFTPConn *conn = new nsFTPConn(host); + nsFTPConn *conn = new nsFTPConn(host, ProcessWndMsgCB); if(conn == NULL) { char szBuf[MAX_BUF_TINY];