本文整理汇总了C++中InfallibleTArray::Elements方法的典型用法代码示例。如果您正苦于以下问题:C++ InfallibleTArray::Elements方法的具体用法?C++ InfallibleTArray::Elements怎么用?C++ InfallibleTArray::Elements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InfallibleTArray
的用法示例。
在下文中一共展示了InfallibleTArray::Elements方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UDPSendResult
bool
UDPSocketParent::RecvDataWithAddress(const InfallibleTArray<uint8_t>& aData,
const mozilla::net::NetAddr& aAddr)
{
NS_ENSURE_TRUE(mSocket, true);
NS_ASSERTION(mFilter, "No packet filter");
uint32_t count;
nsresult rv;
bool allowed;
rv = mFilter->FilterPacket(&aAddr, aData.Elements(),
aData.Length(), nsIUDPSocketFilter::SF_OUTGOING,
&allowed);
// Sending unallowed data, kill content.
NS_ENSURE_SUCCESS(rv, false);
NS_ENSURE_TRUE(allowed, false);
rv = mSocket->SendWithAddress(&aAddr, aData.Elements(),
aData.Length(), &count);
mozilla::unused <<
PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("onsent"),
UDPSendResult(rv),
NS_LITERAL_CSTRING("connected"));
NS_ENSURE_SUCCESS(rv, true);
NS_ENSURE_TRUE(count > 0, true);
return true;
}
示例2: switch
void
UDPSocketParent::Send(const InfallibleTArray<uint8_t>& aData,
const UDPSocketAddr& aAddr)
{
nsresult rv;
uint32_t count;
switch(aAddr.type()) {
case UDPSocketAddr::TUDPAddressInfo: {
const UDPAddressInfo& addrInfo(aAddr.get_UDPAddressInfo());
rv = mSocket->Send(addrInfo.addr(), addrInfo.port(),
aData.Elements(), aData.Length(), &count);
break;
}
case UDPSocketAddr::TNetAddr: {
const NetAddr& addr(aAddr.get_NetAddr());
rv = mSocket->SendWithAddress(&addr, aData.Elements(),
aData.Length(), &count);
break;
}
default:
MOZ_ASSERT(false, "Invalid address type!");
return;
}
if (NS_WARN_IF(NS_FAILED(rv)) || count == 0) {
FireInternalError(__LINE__);
}
}
示例3: LOGD
bool
GMPStorageParent::RecvWrite(const nsCString& aRecordName,
const InfallibleTArray<uint8_t>& aBytes)
{
LOGD(("%s::%s: %p record=%s", __CLASS__, __FUNCTION__, this, aRecordName.get()));
if (mShutdown) {
return true;
}
if (aBytes.Length() > GMP_MAX_RECORD_SIZE) {
unused << SendWriteComplete(aRecordName, GMPQuotaExceededErr);
return true;
}
PRFileDesc* fd = mFiles.Get(aRecordName);
if (!fd) {
unused << SendWriteComplete(aRecordName, GMPGenericErr);
return true;
}
// Write operations overwrite the entire record. So re-open the file
// in truncate mode, to clear its contents.
PR_Close(fd);
mFiles.Remove(aRecordName);
if (NS_FAILED(OpenStorageFile(aRecordName, mOrigin, Truncate, &fd))) {
unused << SendWriteComplete(aRecordName, GMPGenericErr);
return true;
}
mFiles.Put(aRecordName, fd);
int32_t bytesWritten = PR_Write(fd, aBytes.Elements(), aBytes.Length());
auto res = (bytesWritten == (int32_t)aBytes.Length()) ? GMPNoErr : GMPGenericErr;
unused << SendWriteComplete(aRecordName, res);
return true;
}
示例4: sizeof
nsresult
nsLookAndFeel::CallRemoteGetSystemColors()
{
// An array has to be used to get data from remote process
InfallibleTArray<PRUint32> colors;
PRUint32 colorsCount = sizeof(AndroidSystemColors) / sizeof(nscolor);
if (!ContentChild::GetSingleton()->SendGetSystemColors(colorsCount, &colors))
return NS_ERROR_FAILURE;
NS_ASSERTION(colors.Length() == colorsCount, "System colors array is incomplete");
if (colors.Length() == 0)
return NS_ERROR_FAILURE;
if (colors.Length() < colorsCount)
colorsCount = colors.Length();
// Array elements correspond to the members of mSystemColors structure,
// so just copy the memory block
memcpy(&mSystemColors, colors.Elements(), sizeof(nscolor) * colorsCount);
mInitializedSystemColors = PR_TRUE;
return NS_OK;
}
示例5:
bool
UDPSocketChild::RecvCallbackReceivedData(const UDPAddressInfo& aAddressInfo,
const InfallibleTArray<uint8_t>& aData)
{
nsresult rv = mSocket->CallListenerReceivedData(aAddressInfo.addr(), aAddressInfo.port(),
aData.Elements(), aData.Length());
mozilla::unused << NS_WARN_IF(NS_FAILED(rv));
return true;
}
示例6: GetRecord
bool
GMPStorageChild::RecvReadComplete(const nsCString& aRecordName,
const GMPErr& aStatus,
const InfallibleTArray<uint8_t>& aBytes)
{
if (mShutdown) {
return true;
}
nsRefPtr<GMPRecordImpl> record = GetRecord(aRecordName);
if (!record) {
// Not fatal.
return true;
}
record->ReadComplete(aStatus, aBytes.Elements(), aBytes.Length());
return true;
}
示例7: ac
bool
DeserializeArrayBuffer(JS::Handle<JSObject*> aObj,
const InfallibleTArray<uint8_t>& aBuffer,
JS::MutableHandle<JS::Value> aVal)
{
mozilla::AutoSafeJSContext cx;
JSAutoCompartment ac(cx, aObj);
JS::Rooted<JSObject*> obj(cx, JS_NewArrayBuffer(cx, aBuffer.Length()));
if (!obj)
return false;
uint8_t* data = JS_GetArrayBufferData(obj);
if (!data)
return false;
memcpy(data, aBuffer.Elements(), aBuffer.Length());
aVal.set(OBJECT_TO_JSVAL(obj));
return true;
}
示例8: data
bool
DeserializeArrayBuffer(JSContext* cx,
const InfallibleTArray<uint8_t>& aBuffer,
JS::MutableHandle<JS::Value> aVal)
{
mozilla::UniquePtr<uint8_t[], JS::FreePolicy> data(js_pod_malloc<uint8_t>(aBuffer.Length()));
if (!data)
return false;
memcpy(data.get(), aBuffer.Elements(), aBuffer.Length());
JSObject* obj = JS_NewArrayBufferWithContents(cx, aBuffer.Length(), data.get());
if (!obj)
return false;
// If JS_NewArrayBufferWithContents returns non-null, the ownership of
// the data is transfered to obj, so we release the ownership here.
mozilla::Unused << data.release();
aVal.setObject(*obj);
return true;
}
示例9: memcpy
static nsresult
CallRemoteGetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize, uint8_t * const aBuf)
{
NS_ENSURE_TRUE(aBuf != nullptr, NS_ERROR_NULL_POINTER);
// An array has to be used to get data from remote process
InfallibleTArray<uint8_t> bits;
uint32_t bufSize = aIconSize * aIconSize * 4;
if (!ContentChild::GetSingleton()->SendGetIconForExtension(PromiseFlatCString(aFileExt), aIconSize, &bits))
return NS_ERROR_FAILURE;
NS_ASSERTION(bits.Length() == bufSize, "Pixels array is incomplete");
if (bits.Length() != bufSize)
return NS_ERROR_FAILURE;
memcpy(aBuf, bits.Elements(), bufSize);
return NS_OK;
}
示例10: Close
bool
GMPStorageChild::RecvReadComplete(const nsCString& aRecordName,
const GMPErr& aStatus,
const InfallibleTArray<uint8_t>& aBytes)
{
if (mShutdown) {
return true;
}
nsRefPtr<GMPRecordImpl> record;
if (!mRecords.Get(aRecordName, getter_AddRefs(record)) || !record) {
// Not fatal.
return true;
}
record->ReadComplete(aStatus,
aBytes.Elements(),
aBytes.Length());
if (GMP_FAILED(aStatus)) {
Close(record);
}
return true;
}
示例11: data
void
TCPSocketParent::FireArrayBufferDataEvent(nsTArray<uint8_t>& aBuffer, TCPReadyState aReadyState)
{
InfallibleTArray<uint8_t> arr;
arr.SwapElements(aBuffer);
if (mFilter) {
bool allowed;
mozilla::net::NetAddr addr;
nsresult nsrv = mFilter->FilterPacket(&addr, arr.Elements(), arr.Length(),
nsISocketFilter::SF_INCOMING,
&allowed);
// receiving unallowed data, drop it.
if (NS_WARN_IF(NS_FAILED(nsrv)) || !allowed) {
TCPSOCKET_LOG(("%s: Dropping incoming TCP packet", __FUNCTION__));
return;
}
}
SendableData data(arr);
SendEvent(NS_LITERAL_STRING("data"), data, aReadyState);
}