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; }