fixes bug 287750 "provide methods to test if streams are buffered" r=biesi sr=bzbarsky

This commit is contained in:
darin%meer.net 2005-03-26 02:20:36 +00:00
Родитель 92129fb1e6
Коммит 31f754a658
3 изменённых файлов: 81 добавлений и 0 удалений

Просмотреть файл

@ -112,6 +112,8 @@ void XXXNeverCalled()
NS_NewInputStreamReadyEvent(nsnull, nsnull, nsnull);
NS_NewOutputStreamReadyEvent(nsnull, nsnull, nsnull);
NS_AsyncCopy(nsnull, nsnull, nsnull, NS_ASYNCCOPY_VIA_READSEGMENTS, 0, nsnull, nsnull);
NS_InputStreamIsBuffered(nsnull);
NS_OutputStreamIsBuffered(nsnull);
PL_DHashStubEnumRemove(nsnull, nsnull, nsnull, nsnull);
nsIDHashKey::HashKey(nsnull);
nsFixedSizeAllocator a;

Просмотреть файл

@ -1,3 +1,4 @@
/* vim:set ts=4 sw=4 sts=4 et cin: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -581,3 +582,49 @@ NS_AsyncCopy(nsIInputStream *source,
return rv;
}
//-----------------------------------------------------------------------------
static NS_METHOD
TestInputStream(nsIInputStream *inStr,
void *closure,
const char *buffer,
PRUint32 offset,
PRUint32 count,
PRUint32 *countWritten)
{
PRBool *result = NS_REINTERPRET_CAST(PRBool *, closure);
*result = PR_TRUE;
return NS_ERROR_ABORT; // don't call me anymore
}
NS_COM PRBool
NS_InputStreamIsBuffered(nsIInputStream *stream)
{
PRBool result = PR_FALSE;
PRUint32 n;
stream->ReadSegments(TestInputStream, &result, 1, &n);
return result;
}
static NS_METHOD
TestOutputStream(nsIOutputStream *outStr,
void *closure,
char *buffer,
PRUint32 offset,
PRUint32 count,
PRUint32 *countRead)
{
PRBool *result = NS_REINTERPRET_CAST(PRBool *, closure);
*result = PR_TRUE;
return NS_ERROR_ABORT; // don't call me anymore
}
NS_COM PRBool
NS_OutputStreamIsBuffered(nsIOutputStream *stream)
{
PRBool result = PR_FALSE;
PRUint32 n;
stream->WriteSegments(TestOutputStream, &result, 1, &n);
return result;
}

Просмотреть файл

@ -108,4 +108,36 @@ NS_AsyncCopy(nsIInputStream *aSource,
nsAsyncCopyCallbackFun aCallbackFun = nsnull,
void *aCallbackClosure = nsnull);
/**
* This function tests whether or not the input stream is buffered. A buffered
* input stream is one that implements readSegments. The test for this is to
* simply call readSegments, without actually consuming any data from the
* stream, to verify that it functions.
*
* NOTE: If the stream is non-blocking and has no data available yet, then this
* test will fail. In that case, we return false even though the test is not
* really conclusive.
*
* @param aInputStream
* The input stream to test.
*/
extern NS_COM PRBool
NS_InputStreamIsBuffered(nsIInputStream *aInputStream);
/**
* This function tests whether or not the output stream is buffered. A
* buffered output stream is one that implements writeSegments. The test for
* this is to simply call writeSegments, without actually writing any data into
* the stream, to verify that it functions.
*
* NOTE: If the stream is non-blocking and has no available space yet, then
* this test will fail. In that case, we return false even though the test is
* not really conclusive.
*
* @param aOutputStream
* The output stream to test.
*/
extern NS_COM PRBool
NS_OutputStreamIsBuffered(nsIOutputStream *aOutputStream);
#endif // !nsStreamUtils_h__