IPC
From Nocturnal.insomniacgames.com
Download
http://nocturnal.insomniacgames.com/releases/IPC
IPC
IPC is a message based, asynchronous, and non-blocking interprocess communication API. Its designed to be portable to multiple platforms (Insomniac uses it on both Windows and PS3). It currently works over bsd-style sockets and named pipes (currently Windows Named Pipes, and its counterpart SN Pipes).
A connection is established by creating a connection object (for the appropriate transport desired).
IPC::TCPConnection g_TCPConn; void Connect(u16 port) { // start connection thread to wait for endpoint g_TCPConn.Initialize(false, "127.0.0.1", port); } void Disconnect() { // will cease all threads (and interrupt all IO in progress) g_TCPConn.Cleanup(); }
The connection object can allocate messages objects (currently only using the C++ heap). You copy your payload data into the message and send it through the connection. The message then sits on thread-safe write queue until the write thread sends it over the transport. All real communication IO happens in threads. The other endpoint has a read queue that your message (with payload) is pushed onto from a read thread.
bool Send(u32 type, u8* data, u32 size) { IPC::Message* msg = g_TCPConn.CreateMessage(type, size); if (msg) { // copy the payload into the message's memory memcpy(msg->GetData(), data, size); // drop the message onto the outgoing linked list for dispatch in another thread, // this is NON-BLOCKING. the connection owns the allocated memory in the message, // just fire and forget g_TCPConn.Send(type, data, size); } return msg != NULL; } IPC::Message* Receive(bool wait) { // read a message off the incoming queue, if this returns non-null // WE OWN THE MESSAGE AND NEED TO DELETE IT. optionally block the // calling thread to wait for a message return g_TCPConn.Receive(wait); }
