Apple Darwin User Manual Page 49

  • Download
  • Add to my manuals
  • Print
  • Page
    / 68
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 48
}
Note: If you use a function like this one, you should always specify an absolute path to your helper
application.
Message Queues
Message queues provide a way for one process to communicate with another process in a flexible fashion over
a stream-based transport without requiring that the two processes behave in a lockstep fashion at all times.
You can build message queues on top of either bidirectional communication channels, such as sockets, or on
top of pairs of unidirectional communication channels, such as pipes or standard input and output.
A message queue at its simplest consists of a linked list of message structures. Each message structure contains
an outgoing message and a location in which the response will be stored. Depending on how you write your
code, it may contain a callback, to be executed upon completion, or a single handler that calls the right function
based on the original message type.
On each end, you should have a thread to handle messages from the socket. You can use your run loop thread
as a handler thread if you are writing a traditional application, or you can use a separate message thread if you
prefer to use lower-level socket APIs.
The code for managing a message queue is relatively straightforward, locking issues notwithstanding. A
complete code example is provided in the companion files associated with this document. The companion
files archive can be downloaded from the sidebar when viewing this document as HTML at the ADC Reference
Library (developer.apple.com).
Memory Mapping for Bulk Data Transport
For moving large quantities of data between two applications, unless you are communicating over a network,
you should generally avoid most traditional message-passing algorithms because of the inherent CPU overhead
and latency involved. Instead, you should consider a shared memory design using mmap.
The following example shows how to create a shared memory region between a process and its child:
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/dirent.h>
#include <fcntl.h>
#include <stdlib.h>
Cross-Architecture Plug-in Support
Using Interprocess Communication
2012-12-13 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.
49
Page view 48
1 2 ... 44 45 46 47 48 49 50 51 52 53 54 ... 67 68

Comments to this Manuals

No comments