void Connection::writeEventHandler() { if (m_connectionPipe == INVALID_HANDLE_VALUE) return; DWORD numberOfBytesWritten = 0; if (!::GetOverlappedResult(m_connectionPipe, &m_writeState, &numberOfBytesWritten, FALSE)) { DWORD error = ::GetLastError(); if (error == ERROR_IO_INCOMPLETE) { // FIXME: We should figure out why we're getting this error. return; } if (error == ERROR_BROKEN_PIPE) { connectionDidClose(); return; } ASSERT_NOT_REACHED(); } // The pending write has finished, so we are now done with its encoder. Clearing this member // will allow us to send messages again. m_pendingWriteEncoder = nullptr; // Now that the pending write has finished, we can try to send a new message. sendOutgoingMessages(); }
void Connection::receiveSourceEventHandler() { ReceiveBuffer buffer; mach_msg_header_t* header = readFromMachPort(m_receivePort, buffer); if (!header) return; MessageID messageID = MessageID::fromInt(header->msgh_id); OwnPtr<ArgumentDecoder> arguments = createArgumentDecoder(header); ASSERT(arguments); if (messageID == MessageID(CoreIPCMessage::InitializeConnection)) { ASSERT(m_isServer); ASSERT(!m_isConnected); ASSERT(!m_sendPort); MachPort port; if (!arguments->decode(port)) { // FIXME: Disconnect. return; } m_sendPort = port.port(); // Set the dead name source if needed. if (m_sendPort) initializeDeadNameSource(); m_isConnected = true; // Send any pending outgoing messages. sendOutgoingMessages(); return; } if (messageID == MessageID(CoreIPCMessage::SetExceptionPort)) { MachPort exceptionPort; if (!arguments->decode(exceptionPort)) return; setMachExceptionPort(exceptionPort.port()); return; } processIncomingMessage(messageID, arguments.release()); }
void Connection::receiveSourceEventHandler() { char buffer[inlineMessageMaxSize]; mach_msg_header_t* header = reinterpret_cast<mach_msg_header_t*>(&buffer); kern_return_t kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT, 0, sizeof(buffer), m_receivePort, 0, MACH_PORT_NULL); if (kr == MACH_RCV_TIMED_OUT) return; if (kr != MACH_MSG_SUCCESS) { ASSERT_NOT_REACHED(); // FIXME: Handle MACH_RCV_MSG_TOO_LARGE. return; } MessageID messageID = MessageID::fromInt(header->msgh_id); std::auto_ptr<ArgumentDecoder> arguments = createArgumentDecoder(header); ASSERT(arguments.get()); if (messageID == MessageID(CoreIPCMessage::InitializeConnection)) { ASSERT(m_isServer); ASSERT(!m_isConnected); ASSERT(!m_sendPort); MachPort port; if (!arguments->decode(port)) { // FIXME: Disconnect. return; } m_sendPort = port.port(); // Set the dead name source if needed. if (m_sendPort) initializeDeadNameSource(); m_isConnected = true; // Send any pending outgoing messages. sendOutgoingMessages(); return; } processIncomingMessage(messageID, arguments); }