/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// All good! if (NS_SUCCEEDED(rv)) {
*aLength = length; returntrue;
}
// Already closed stream or an error occurred. if (rv == NS_BASE_STREAM_CLOSED ||
NS_WARN_IF(rv == NS_ERROR_NOT_AVAILABLE) ||
NS_WARN_IF(rv != NS_BASE_STREAM_WOULD_BLOCK)) { returntrue;
}
}
nsCOMPtr<nsIAsyncInputStreamLength> asyncStreamLength =
do_QueryInterface(aStream); if (asyncStreamLength) { // GetAsyncLength should be used. returnfalse;
}
// We cannot calculate the length of an async stream.
nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(aStream); if (asyncStream) { returnfalse;
}
// For main-thread only, we want to avoid calling ::Available() for blocking // streams. if (NS_IsMainThread()) { bool nonBlocking = false; if (NS_WARN_IF(NS_FAILED(aStream->IsNonBlocking(&nonBlocking)))) { // Let's return -1. There is nothing else we can do here. returntrue;
}
if (!nonBlocking) { returnfalse;
}
}
// Fallback using available().
uint64_t available = 0;
nsresult rv = aStream->Available(&available); if (NS_WARN_IF(NS_FAILED(rv))) { // Let's return -1. There is nothing else we can do here. returntrue;
}
// We don't want to allow this class to be used on workers because we are not // using the correct Runnable types.
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread() ||
!dom::IsCurrentThreadRunningWorker());
RefPtr<InputStreamLengthHelper> helper = new InputStreamLengthHelper(aStream, aCallback);
// Let's be sure that we don't call ::Available() on main-thread. if (NS_IsMainThread()) {
nsCOMPtr<nsIInputStreamLength> streamLength = do_QueryInterface(aStream);
nsCOMPtr<nsIAsyncInputStreamLength> asyncStreamLength =
do_QueryInterface(aStream); if (!streamLength && !asyncStreamLength) { // We cannot calculate the length of an async stream. We must fix the // caller if this happens. #ifdef DEBUG
nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(aStream);
MOZ_DIAGNOSTIC_ASSERT(!asyncStream); #endif
// Let's go async in order to have similar behaviors for sync and async // nsIInputStreamLength implementations.
GetCurrentSerialEventTarget()->Dispatch(helper, NS_DISPATCH_NORMAL);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.