M build-tests.xml
- comment in all tests M classes_spec/org/mozilla/webclient/Navigation2.java M classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java - add loadFromStreamBlocking, until we have DocumentLoadListener working M src_moz/InputStreamShim.cpp M src_moz/InputStreamShim.h - rollback the nsIAsyncInputStream changes. M test/automated/src/classes/org/mozilla/webclient/NavigationTest.java - test from a FileInputStream M test/automated/src/classes/org/mozilla/webclient/RandomHTMLInputStream.java - Allow notification when read completes. git-svn-id: svn://10.0.0.236/trunk@157311 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -30,9 +30,6 @@
|
||||
|
||||
#include "ns_globals.h"
|
||||
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsStreamUtils.h"
|
||||
|
||||
static const PRInt32 buffer_increment = 1024;
|
||||
static const PRInt32 do_close_code = -524;
|
||||
|
||||
@@ -41,8 +38,7 @@ InputStreamShim::InputStreamShim(jobject yourJavaStreamRef,
|
||||
mJavaStream(yourJavaStreamRef), mContentLength(yourContentLength),
|
||||
mBuffer(nsnull), mBufferLength(0), mCountFromJava(0),
|
||||
mCountFromMozilla(0), mAvailable(0), mAvailableForMozilla(0), mNumRead(0),
|
||||
mDoClose(PR_FALSE), mDidClose(PR_FALSE), mLock(nsnull),
|
||||
mCloseStatus(NS_OK), mCallback(nsnull), mCallbackFlags(0)
|
||||
mDoClose(PR_FALSE), mDidClose(PR_FALSE), mLock(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mLock = PR_NewLock();
|
||||
@@ -131,18 +127,6 @@ nsresult InputStreamShim::doReadFromJava()
|
||||
}
|
||||
rv = NS_OK;
|
||||
|
||||
// if we have bytes available for mozilla, and they it has requested
|
||||
// a callback when bytes are available.
|
||||
if (mCallback && 0 < mAvailableForMozilla
|
||||
&& !(mCallbackFlags & WAIT_CLOSURE_ONLY)) {
|
||||
rv = mCallback->OnInputStreamReady(this);
|
||||
mCallback = nsnull;
|
||||
mCallbackFlags = nsnull;
|
||||
if (NS_FAILED(rv)) {
|
||||
goto DRFJ_CLEANUP;
|
||||
}
|
||||
}
|
||||
|
||||
// finally, do another check for available bytes
|
||||
if (NS_FAILED(doAvailable())) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
@@ -296,6 +280,9 @@ InputStreamShim::doRead(void)
|
||||
mCountFromJava += mNumRead;
|
||||
mAvailableForMozilla = mCountFromJava - mCountFromMozilla;
|
||||
}
|
||||
printf("InputStreamShim::doRead: read %d bytes\n", mNumRead);
|
||||
fflush(stdout);
|
||||
|
||||
rv = NS_OK;
|
||||
#endif
|
||||
|
||||
@@ -334,13 +321,6 @@ InputStreamShim::doClose(void)
|
||||
}
|
||||
rv = NS_OK;
|
||||
#endif
|
||||
if (mCallback && mAvailableForMozilla &&
|
||||
!(mCallbackFlags & WAIT_CLOSURE_ONLY)) {
|
||||
rv = mCallback->OnInputStreamReady(this);
|
||||
mCallback = nsnull;
|
||||
mCallbackFlags = nsnull;
|
||||
}
|
||||
|
||||
mDidClose = PR_TRUE;
|
||||
return rv;
|
||||
}
|
||||
@@ -356,12 +336,10 @@ InputStreamShim::Available(PRUint32* aResult)
|
||||
if (!aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (mDoClose) {
|
||||
return mCloseStatus;
|
||||
}
|
||||
PR_ASSERT(mLock);
|
||||
PR_Lock(mLock);
|
||||
*aResult = mAvailableForMozilla;
|
||||
// *aResult = mAvailableForMozilla;
|
||||
*aResult = PR_UINT32_MAX;
|
||||
rv = NS_OK;
|
||||
PR_Unlock(mLock);
|
||||
|
||||
@@ -375,7 +353,6 @@ InputStreamShim::Close()
|
||||
PR_ASSERT(mLock);
|
||||
PR_Lock(mLock);
|
||||
mDoClose = PR_TRUE;
|
||||
mCloseStatus = NS_BASE_STREAM_CLOSED;
|
||||
rv = NS_OK;
|
||||
PR_Unlock(mLock);
|
||||
|
||||
@@ -391,17 +368,28 @@ InputStreamShim::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead)
|
||||
}
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("InputStreamShim::Read: entering\n"));
|
||||
if (mDoClose) {
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("InputStreamShim::Read: exiting, already closed\n"));
|
||||
return mCloseStatus;
|
||||
}
|
||||
*aNumRead = 0;
|
||||
PR_ASSERT(mLock);
|
||||
PR_ASSERT(mCountFromMozilla <= mCountFromJava);
|
||||
|
||||
PR_Lock(mLock);
|
||||
|
||||
// wait for java to load the buffer with some data
|
||||
do {
|
||||
if (mAvailableForMozilla == 0) {
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("InputStreamShim::Read: wait for java: release lock\n"));
|
||||
PR_Unlock(mLock);
|
||||
PR_Sleep(PR_INTERVAL_MIN);
|
||||
PR_Lock(mLock);
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("InputStreamShim::Read: wait for java: acquire lock\n"));
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
} while ((!mDidClose) && (-1 != mNumRead));
|
||||
|
||||
if (mAvailableForMozilla) {
|
||||
if (aCount <= (mCountFromJava - mCountFromMozilla)) {
|
||||
// what she's asking for is less than or equal to what we have
|
||||
@@ -418,14 +406,13 @@ InputStreamShim::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead)
|
||||
mCountFromMozilla += (mCountFromJava - mCountFromMozilla);
|
||||
}
|
||||
mAvailableForMozilla -= *aNumRead;
|
||||
rv = NS_OK;
|
||||
}
|
||||
else {
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("InputStreamShim::Read: exiting, would block\n"));
|
||||
rv = NS_BASE_STREAM_WOULD_BLOCK;
|
||||
}
|
||||
|
||||
printf("InputStreamShim::Read: read %d bytes\n", *aNumRead);
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
rv = NS_OK;
|
||||
PR_Unlock(mLock);
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("InputStreamShim::Read: exiting\n"));
|
||||
@@ -443,47 +430,9 @@ InputStreamShim::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32
|
||||
NS_IMETHODIMP
|
||||
InputStreamShim::IsNonBlocking(PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
// NS_NOTREACHED("IsNonBlocking");
|
||||
// return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputStreamShim::CloseWithStatus(nsresult astatus)
|
||||
{
|
||||
this->Close();
|
||||
mCloseStatus = astatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputStreamShim::AsyncWait(nsIInputStreamCallback *aCallback,
|
||||
PRUint32 aFlags, PRUint32 aRequestedCount,
|
||||
nsIEventTarget *aEventTarget)
|
||||
{
|
||||
PR_Lock(mLock);
|
||||
|
||||
mCallback = nsnull;
|
||||
mCallbackFlags = nsnull;
|
||||
|
||||
nsCOMPtr<nsIInputStreamCallback> proxy;
|
||||
if (aEventTarget) {
|
||||
nsresult rv = NS_NewInputStreamReadyEvent(getter_AddRefs(proxy),
|
||||
aCallback, aEventTarget);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
aCallback = proxy;
|
||||
}
|
||||
if (NS_FAILED(mCloseStatus) ||
|
||||
(mAvailableForMozilla && !(aFlags & WAIT_CLOSURE_ONLY))) {
|
||||
// stream is already closed or readable; post event.
|
||||
aCallback->OnInputStreamReady(this);
|
||||
}
|
||||
else {
|
||||
// queue up callback object to be notified when data becomes available
|
||||
mCallback = aCallback;
|
||||
mCallbackFlags = aFlags;
|
||||
}
|
||||
|
||||
PR_Unlock(mLock);
|
||||
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user