Better buffering of FTP input.

This commit is contained in:
rjc%netscape.com 1999-06-21 23:11:17 +00:00
parent 8bb10539b7
commit 1bf5f15f2b

View File

@ -584,36 +584,39 @@ FTPDataSourceCallback::OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, P
if (aLength > 0)
{
nsString line;
if (mLine) line += mLine;
char c;
for (PRUint32 loop=0; loop<aLength; loop++)
if (mLine)
{
PRUint32 count;
if (NS_FAILED(rv = aIStream->Read(&c, 1, &count)))
line += mLine;
delete []mLine;
mLine = nsnull;
}
char buffer[257];
while (aLength > 0)
{
PRUint32 count=0, numBytes = (aLength > sizeof(buffer)-1 ? sizeof(buffer)-1 : aLength);
if (NS_FAILED(rv = aIStream->Read(buffer, numBytes, &count)))
{
printf("FTP datasource read failure.\n");
break;
}
if (count != 1) break;
line += c;
if (numBytes != count)
{
printf("FTP datasource read # of bytes failure.\n");
break;
}
buffer[count] = '\0';
line += buffer;
aLength -= count;
}
PRInt32 eol = line.FindCharInSet("\r\n");
if (eol < 0)
{
if (mLine) delete []mLine;
mLine = line.ToNewCString();
}
nsAutoString oneLiner("");
if (eol > 0)
if (eol >= 0)
{
line.Left(oneLiner, eol);
line.Cut(0, eol+1);
}
line.Cut(0, eol+1);
if (mLine) delete []mLine;
mLine = line.ToNewCString();
if (oneLiner.Length() < 1) return(rv);