本文整理汇总了C++中InfallibleTArray::SwapElements方法的典型用法代码示例。如果您正苦于以下问题:C++ InfallibleTArray::SwapElements方法的具体用法?C++ InfallibleTArray::SwapElements怎么用?C++ InfallibleTArray::SwapElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InfallibleTArray
的用法示例。
在下文中一共展示了InfallibleTArray::SwapElements方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendData
NS_IMETHODIMP
TCPSocketChild::Send(const JS::Value& aData,
uint32_t aByteOffset,
uint32_t aByteLength,
JSContext* aCx)
{
if (aData.isString()) {
JSString* jsstr = aData.toString();
nsDependentJSString str;
bool ok = str.init(aCx, jsstr);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
SendData(str);
} else {
NS_ENSURE_TRUE(aData.isObject(), NS_ERROR_FAILURE);
JS::Rooted<JSObject*> obj(aCx, &aData.toObject());
NS_ENSURE_TRUE(JS_IsArrayBufferObject(obj), NS_ERROR_FAILURE);
uint32_t buflen = JS_GetArrayBufferByteLength(obj);
aByteOffset = std::min(buflen, aByteOffset);
uint32_t nbytes = std::min(buflen - aByteOffset, aByteLength);
uint8_t* data = JS_GetArrayBufferData(obj);
if (!data) {
return NS_ERROR_OUT_OF_MEMORY;
}
FallibleTArray<uint8_t> fallibleArr;
if (!fallibleArr.InsertElementsAt(0, data, nbytes)) {
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> arr;
arr.SwapElements(fallibleArr);
SendData(arr);
}
return NS_OK;
}
示例2: data
void
TCPSocketParent::FireArrayBufferDataEvent(nsTArray<uint8_t>& aBuffer, TCPReadyState aReadyState)
{
InfallibleTArray<uint8_t> arr;
arr.SwapElements(aBuffer);
SendableData data(arr);
SendEvent(NS_LITERAL_STRING("data"), data, aReadyState);
}
示例3: FireInternalError
NS_IMETHODIMP
UDPSocketParent::OnPacketReceived(nsIUDPSocket* aSocket, nsIUDPMessage* aMessage)
{
// receiving packet from remote host, forward the message content to child process
if (!mIPCOpen) {
return NS_OK;
}
uint16_t port;
nsCString ip;
nsCOMPtr<nsINetAddr> fromAddr;
aMessage->GetFromAddr(getter_AddRefs(fromAddr));
fromAddr->GetPort(&port);
fromAddr->GetAddress(ip);
nsCString data;
aMessage->GetData(data);
const char* buffer = data.get();
uint32_t len = data.Length();
UDPSOCKET_LOG(("%s: %s:%u, length %u", __FUNCTION__, ip.get(), port, len));
if (mFilter) {
bool allowed;
mozilla::net::NetAddr addr;
fromAddr->GetNetAddr(&addr);
nsresult rv = mFilter->FilterPacket(&addr,
(const uint8_t*)buffer, len,
nsIUDPSocketFilter::SF_INCOMING,
&allowed);
// Receiving unallowed data, drop.
if (NS_WARN_IF(NS_FAILED(rv)) || !allowed) {
if (!allowed) {
UDPSOCKET_LOG(("%s: not allowed", __FUNCTION__));
}
return NS_OK;
}
}
FallibleTArray<uint8_t> fallibleArray;
if (!fallibleArray.InsertElementsAt(0, buffer, len)) {
FireInternalError(__LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> infallibleArray;
infallibleArray.SwapElements(fallibleArray);
// compose callback
mozilla::unused << SendCallbackReceivedData(UDPAddressInfo(ip, port), infallibleArray);
return NS_OK;
}
示例4: FireInternalError
NS_IMETHODIMP
UDPSocketParent::OnPacketReceived(nsIUDPSocket* aSocket, nsIUDPMessage* aMessage)
{
// receiving packet from remote host, forward the message content to child process
if (!mIPCOpen) {
return NS_OK;
}
NS_ASSERTION(mFilter, "No packet filter");
uint16_t port;
nsCString ip;
nsCOMPtr<nsINetAddr> fromAddr;
aMessage->GetFromAddr(getter_AddRefs(fromAddr));
fromAddr->GetPort(&port);
fromAddr->GetAddress(ip);
nsCString data;
aMessage->GetData(data);
const char* buffer = data.get();
uint32_t len = data.Length();
bool allowed;
mozilla::net::NetAddr addr;
fromAddr->GetNetAddr(&addr);
nsresult rv = mFilter->FilterPacket(&addr,
(const uint8_t*)buffer, len,
nsIUDPSocketFilter::SF_INCOMING,
&allowed);
// Receiving unallowed data, drop.
NS_ENSURE_SUCCESS(rv, NS_OK);
NS_ENSURE_TRUE(allowed, NS_OK);
FallibleTArray<uint8_t> fallibleArray;
if (!fallibleArray.InsertElementsAt(0, buffer, len)) {
FireInternalError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> infallibleArray;
infallibleArray.SwapElements(fallibleArray);
// compose callback
mozilla::unused <<
PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("ondata"),
UDPMessage(ip, port, infallibleArray),
NS_LITERAL_CSTRING("connected"));
return NS_OK;
}
示例5: SendData
nsresult
TCPSocketChild::SendSend(const ArrayBuffer& aData,
uint32_t aByteOffset,
uint32_t aByteLength,
uint32_t aTrackingNumber)
{
uint32_t buflen = aData.Length();
uint32_t offset = std::min(buflen, aByteOffset);
uint32_t nbytes = std::min(buflen - aByteOffset, aByteLength);
FallibleTArray<uint8_t> fallibleArr;
if (!fallibleArr.InsertElementsAt(0, aData.Data() + offset, nbytes, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> arr;
arr.SwapElements(fallibleArr);
SendData(arr, aTrackingNumber);
return NS_OK;
}
示例6: SendOutgoingData
nsresult
UDPSocketChild::SendDataInternal(const UDPSocketAddr& aAddr,
const uint8_t* aData,
const uint32_t aByteLength)
{
NS_ENSURE_ARG(aData);
FallibleTArray<uint8_t> fallibleArray;
if (!fallibleArray.InsertElementsAt(0, aData, aByteLength)) {
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> array;
array.SwapElements(fallibleArray);
SendOutgoingData(array, aAddr);
return NS_OK;
}
示例7: SendData
NS_IMETHODIMP
UDPSocketChild::Send(const nsACString& aHost,
uint16_t aPort,
const uint8_t *aData,
uint32_t aByteLength)
{
NS_ENSURE_ARG(aData);
FallibleTArray<uint8_t> fallibleArray;
if (!fallibleArray.InsertElementsAt(0, aData, aByteLength)) {
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> array;
array.SwapElements(fallibleArray);
SendData(array, nsCString(aHost), aPort);
return NS_OK;
}
示例8: SendDataWithAddress
NS_IMETHODIMP
UDPSocketChild::SendWithAddress(const NetAddr *aAddr,
const uint8_t *aData,
uint32_t aByteLength)
{
NS_ENSURE_ARG(aAddr);
NS_ENSURE_ARG(aData);
FallibleTArray<uint8_t> fallibleArray;
if (!fallibleArray.InsertElementsAt(0, aData, aByteLength)) {
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> array;
array.SwapElements(fallibleArray);
SendDataWithAddress(array, *aAddr);
return NS_OK;
}
示例9: 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);
}
示例10: FireInteralError
NS_IMETHODIMP
TCPSocketParent::SendEvent(const nsAString& aType, JS::Handle<JS::Value> aDataVal,
const nsAString& aReadyState, JSContext* aCx)
{
if (!mIPCOpen) {
NS_WARNING("Dropping callback due to no IPC connection");
return NS_OK;
}
CallbackData data;
if (aDataVal.isString()) {
JSString* jsstr = aDataVal.toString();
nsAutoJSString str;
if (!str.init(aCx, jsstr)) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
data = SendableData(str);
} else if (aDataVal.isUndefined() || aDataVal.isNull()) {
data = mozilla::void_t();
} else if (aDataVal.isObject()) {
JS::Rooted<JSObject *> obj(aCx, &aDataVal.toObject());
if (JS_IsArrayBufferObject(obj)) {
FallibleTArray<uint8_t> fallibleArr;
uint32_t errLine = 0;
do {
JS::AutoCheckCannotGC nogc;
uint32_t nbytes = JS_GetArrayBufferByteLength(obj);
uint8_t* buffer = JS_GetArrayBufferData(obj, nogc);
if (!buffer) {
errLine = __LINE__;
break;
}
if (!fallibleArr.InsertElementsAt(0, buffer, nbytes, fallible)) {
errLine = __LINE__;
break;
}
} while (false);
if (errLine) {
FireInteralError(this, errLine);
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> arr;
arr.SwapElements(fallibleArr);
data = SendableData(arr);
} else {
nsAutoJSString name;
JS::Rooted<JS::Value> val(aCx);
if (!JS_GetProperty(aCx, obj, "name", &val)) {
NS_ERROR("No name property on supposed error object");
} else if (val.isString()) {
if (!name.init(aCx, val.toString())) {
NS_WARNING("couldn't initialize string");
}
}
data = TCPError(name);
}
} else {
NS_ERROR("Unexpected JS value encountered");
FireInteralError(this, __LINE__);
return NS_ERROR_FAILURE;
}
mozilla::unused <<
PTCPSocketParent::SendCallback(nsString(aType), data,
nsString(aReadyState));
return NS_OK;
}
示例11: FireInteralError
NS_IMETHODIMP
TCPSocketParent::SendCallback(const nsAString& aType, const JS::Value& aDataVal,
const nsAString& aReadyState, uint32_t aBuffered,
JSContext* aCx)
{
if (!mIPCOpen) {
NS_WARNING("Dropping callback due to no IPC connection");
return NS_OK;
}
CallbackData data;
if (aDataVal.isString()) {
JSString* jsstr = aDataVal.toString();
nsDependentJSString str;
if (!str.init(aCx, jsstr)) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
data = SendableData(str);
} else if (aDataVal.isUndefined() || aDataVal.isNull()) {
data = mozilla::void_t();
} else if (aDataVal.isObject()) {
JSObject* obj = &aDataVal.toObject();
if (JS_IsArrayBufferObject(obj)) {
uint32_t nbytes = JS_GetArrayBufferByteLength(obj);
uint8_t* buffer = JS_GetArrayBufferData(obj);
if (!buffer) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
FallibleTArray<uint8_t> fallibleArr;
if (!fallibleArr.InsertElementsAt(0, buffer, nbytes)) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> arr;
arr.SwapElements(fallibleArr);
data = SendableData(arr);
} else {
nsDependentJSString name;
JS::Rooted<JS::Value> val(aCx);
if (!JS_GetProperty(aCx, obj, "name", val.address())) {
NS_ERROR("No name property on supposed error object");
} else if (JSVAL_IS_STRING(val)) {
if (!name.init(aCx, JSVAL_TO_STRING(val))) {
NS_WARNING("couldn't initialize string");
}
}
data = TCPError(name);
}
} else {
NS_ERROR("Unexpected JS value encountered");
FireInteralError(this, __LINE__);
return NS_ERROR_FAILURE;
}
mozilla::unused <<
PTCPSocketParent::SendCallback(nsString(aType), data,
nsString(aReadyState), aBuffered);
return NS_OK;
}
示例12: FireInteralError
NS_IMETHODIMP
TCPSocketParent::SendCallback(const nsAString& aType, const JS::Value& aDataVal,
const nsAString& aReadyState, uint32_t aBuffered,
JSContext* aCx)
{
if (!mIPCOpen) {
NS_WARNING("Dropping callback due to no IPC connection");
return NS_OK;
}
CallbackData data;
if (aDataVal.isString()) {
JSString* jsstr = aDataVal.toString();
nsDependentJSString str;
if (!str.init(aCx, jsstr)) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
data = str;
} else if (aDataVal.isUndefined() || aDataVal.isNull()) {
data = mozilla::void_t();
} else if (aDataVal.isObject()) {
JSObject* obj = &aDataVal.toObject();
if (JS_IsTypedArrayObject(obj)) {
NS_ENSURE_TRUE(JS_IsUint8Array(obj), NS_ERROR_FAILURE);
uint32_t nbytes = JS_GetTypedArrayByteLength(obj);
uint8_t* buffer = JS_GetUint8ArrayData(obj);
if (!buffer) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
FallibleTArray<uint8_t> fallibleArr;
if (!fallibleArr.InsertElementsAt(0, buffer, nbytes)) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> arr;
arr.SwapElements(fallibleArr);
data = SendableData(arr);
} else {
nsDependentJSString message, filename;
uint32_t lineNumber = 0;
uint32_t columnNumber = 0;
jsval val;
if (!JS_GetProperty(aCx, obj, "message", &val)) {
NS_ERROR("No message property on supposed error object");
} else if (JSVAL_IS_STRING(val)) {
if (!message.init(aCx, JSVAL_TO_STRING(val))) {
NS_WARNING("couldn't initialize string");
}
}
if (!JS_GetProperty(aCx, obj, "fileName", &val)) {
NS_ERROR("No fileName property on supposed error object");
} else if (JSVAL_IS_STRING(val)) {
if (!filename.init(aCx, JSVAL_TO_STRING(val))) {
NS_WARNING("couldn't initialize string");
}
}
if (!JS_GetProperty(aCx, obj, "lineNumber", &val)) {
NS_ERROR("No lineNumber property on supposed error object");
} else if (JSVAL_IS_INT(val)) {
lineNumber = JSVAL_TO_INT(val);
}
if (!JS_GetProperty(aCx, obj, "columnNumber", &val)) {
NS_ERROR("No columnNumber property on supposed error object");
} else if (JSVAL_IS_INT(val)) {
columnNumber = JSVAL_TO_INT(val);
}
data = JSError(message, filename, lineNumber, columnNumber);
}
} else {
NS_ERROR("Unexpected JS value encountered");
FireInteralError(this, __LINE__);
return NS_ERROR_FAILURE;
}
mozilla::unused <<
PTCPSocketParent::SendCallback(nsString(aType), data,
nsString(aReadyState), aBuffered);
return NS_OK;
}