Fix for 78282 r=ssu, sr=mscott

git-svn-id: svn://10.0.0.236/trunk@94799 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
syd%netscape.com
2001-05-13 00:45:45 +00:00
parent 5bceb08149
commit d5d69c4e06
8 changed files with 124 additions and 12 deletions

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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)
{

View File

@@ -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;

View File

@@ -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);

View File

@@ -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)

View File

@@ -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;

View File

@@ -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];