本文整理汇总了C++中PassOwnPtr::buffer方法的典型用法代码示例。如果您正苦于以下问题:C++ PassOwnPtr::buffer方法的具体用法?C++ PassOwnPtr::buffer怎么用?C++ PassOwnPtr::buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PassOwnPtr
的用法示例。
在下文中一共展示了PassOwnPtr::buffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendOutgoingMessage
bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEncoder> arguments)
{
ASSERT(m_socket);
// We put the message ID last.
arguments->encodeUInt32(messageID.toInt());
size_t bufferSize = arguments->bufferSize();
// Write message size first
// FIXME: Should just do a single write.
qint64 bytesWrittenForSize = m_socket->write(reinterpret_cast<char*>(&bufferSize), sizeof(bufferSize));
if (bytesWrittenForSize != sizeof(bufferSize)) {
connectionDidClose();
return false;
}
qint64 bytesWrittenForBuffer = m_socket->write(reinterpret_cast<char*>(arguments->buffer()), arguments->bufferSize());
if (bytesWrittenForBuffer != arguments->bufferSize()) {
connectionDidClose();
return false;
}
m_socket->flush();
return true;
}
示例2: sendOutgoingMessage
bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<MessageEncoder> encoder)
{
ASSERT(!m_pendingWriteEncoder);
// Just bail if the handle has been closed.
if (m_connectionPipe == INVALID_HANDLE_VALUE)
return false;
// We put the message ID last.
encoder->encode(static_cast<uint32_t>(messageID.toInt()));
// Write the outgoing message.
if (::WriteFile(m_connectionPipe, encoder->buffer(), encoder->bufferSize(), 0, &m_writeState)) {
// We successfully sent this message.
return true;
}
DWORD error = ::GetLastError();
if (error == ERROR_NO_DATA) {
// The pipe is being closed.
connectionDidClose();
return false;
}
if (error != ERROR_IO_PENDING) {
ASSERT_NOT_REACHED();
return false;
}
// The message will be sent soon. Hold onto the encoder so that it won't be destroyed
// before the write completes.
m_pendingWriteEncoder = encoder;
// We can only send one asynchronous message at a time (see comment in platformCanSendOutgoingMessages).
return false;
}