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; }
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. m_socket->write(reinterpret_cast<char*>(&bufferSize), sizeof(bufferSize)); qint64 bytesWritten = m_socket->write(reinterpret_cast<char*>(arguments->buffer()), arguments->bufferSize()); ASSERT_UNUSED(bytesWritten, bytesWritten == arguments->bufferSize()); return true; }
bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEncoder> arguments) { if (m_socket < 0) return false; // We put the message ID last. arguments->encodeUInt32(messageID.toInt()); size_t bufferSize = arguments->bufferSize(); // Send the message size first. if (!writeBytesToSocket(m_socket, reinterpret_cast<uint8_t*>(&bufferSize), sizeof(size_t))) return false; if (!writeBytesToSocket(m_socket, arguments->buffer(), arguments->bufferSize())) return false; return true; }
bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEncoder> arguments) { ASSERT(!m_pendingWriteArguments); // Just bail if the handle has been closed. if (m_connectionPipe == INVALID_HANDLE_VALUE) return false; // We put the message ID last. arguments->encodeUInt32(messageID.toInt()); // Write the outgoing message. if (::WriteFile(m_connectionPipe, arguments->buffer(), arguments->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 arguments so that they won't be destroyed // before the write completes. m_pendingWriteArguments = arguments; // We can only send one asynchronous message at a time (see comment in platformCanSendOutgoingMessages). return false; }