本文整理汇总了C++中Attachment::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Attachment::size方法的具体用法?C++ Attachment::size怎么用?C++ Attachment::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachment
的用法示例。
在下文中一共展示了Attachment::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uri
bool Attachment::operator==( const Attachment &a2 ) const
{
return uri() == a2.uri() &&
d->mLabel == a2.label() &&
d->mLocal == a2.isLocal() &&
d->mBinary == a2.isBinary() &&
d->mShowInline == a2.showInline() &&
size() == a2.size() &&
decodedData() == a2.decodedData();
}
示例2: sendOutgoingMessage
bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEncoder> arguments)
{
Vector<Attachment> attachments = arguments->releaseAttachments();
size_t numberOfPortDescriptors = 0;
size_t numberOfOOLMemoryDescriptors = 0;
for (size_t i = 0; i < attachments.size(); ++i) {
Attachment::Type type = attachments[i].type();
if (type == Attachment::MachPortType)
numberOfPortDescriptors++;
else if (type == Attachment::MachOOLMemoryType)
numberOfOOLMemoryDescriptors++;
}
size_t messageSize = machMessageSize(arguments->bufferSize(), numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
char buffer[inlineMessageMaxSize];
bool messageBodyIsOOL = false;
if (messageSize > sizeof(buffer)) {
messageBodyIsOOL = true;
attachments.append(Attachment(arguments->buffer(), arguments->bufferSize(), MACH_MSG_VIRTUAL_COPY, false));
numberOfOOLMemoryDescriptors++;
messageSize = machMessageSize(0, numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
}
bool isComplex = (numberOfPortDescriptors + numberOfOOLMemoryDescriptors > 0);
mach_msg_header_t* header = reinterpret_cast<mach_msg_header_t*>(&buffer);
header->msgh_bits = isComplex ? MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND | MACH_MSGH_BITS_COMPLEX, 0) : MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
header->msgh_size = messageSize;
header->msgh_remote_port = m_sendPort;
header->msgh_local_port = MACH_PORT_NULL;
header->msgh_id = messageID.toInt();
if (messageBodyIsOOL)
header->msgh_id |= MessageBodyIsOOL;
uint8_t* messageData;
if (isComplex) {
mach_msg_body_t* body = reinterpret_cast<mach_msg_body_t*>(header + 1);
body->msgh_descriptor_count = numberOfPortDescriptors + numberOfOOLMemoryDescriptors;
uint8_t* descriptorData = reinterpret_cast<uint8_t*>(body + 1);
for (size_t i = 0; i < attachments.size(); ++i) {
Attachment attachment = attachments[i];
mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);
switch (attachment.type()) {
case Attachment::MachPortType:
descriptor->port.name = attachment.port();
descriptor->port.disposition = attachment.disposition();
descriptor->port.type = MACH_MSG_PORT_DESCRIPTOR;
descriptorData += sizeof(mach_msg_port_descriptor_t);
break;
case Attachment::MachOOLMemoryType:
descriptor->out_of_line.address = attachment.address();
descriptor->out_of_line.size = attachment.size();
descriptor->out_of_line.copy = attachment.copyOptions();
descriptor->out_of_line.deallocate = attachment.deallocate();
descriptor->out_of_line.type = MACH_MSG_OOL_DESCRIPTOR;
descriptorData += sizeof(mach_msg_ool_descriptor_t);
break;
default:
ASSERT_NOT_REACHED();
}
}
messageData = descriptorData;
} else
messageData = (uint8_t*)(header + 1);
// Copy the data if it is not being sent out-of-line.
if (!messageBodyIsOOL)
memcpy(messageData, arguments->buffer(), arguments->bufferSize());
ASSERT(m_sendPort);
// Send the message.
kern_return_t kr = mach_msg(header, MACH_SEND_MSG, messageSize, 0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
if (kr != KERN_SUCCESS) {
// FIXME: What should we do here?
}
return true;
}