@@ -11,18 +11,28 @@ communication in each direction between client and server. This documentation
1111refers to an interacting client and server as "counterparts".
1212
1313`Sender` and `Receiver` are low-level traits. Using them entails working with
14- raw pointers to shared memory segments, so applications will generally need to
15- build higher-level abstractions around them them to provide well-typed
16- interfaces, prevent data races, batch messages to reduce IPC overhead, and so
17- on.
14+ raw pointers to shared memory segments, so users will generally need to build
15+ higher-level abstractions around them them to provide well-typed interfaces,
16+ prevent data races, batch messages to reduce IPC overhead, and so on.
17+
18+ For example, to build a communications channel carrying typed messages that was
19+ generic over `Sender` implementations, you could use `Sender` to create and map
20+ a shared memory segment, and then serialize the messages into the shared memory.
21+ When it became full, or a response was needed, you would call
22+ [`Sender::send_message`] to alert your counterpart to the whole batch of
23+ messages. Your [`Receiver::receive_message`] implementation in the counterpart
24+ would then map the shared memory segment, deserialize the messages from the
25+ given range, and process them.
1826
1927## Senders
2028
2129A [`Sender`] implementation is responsible for interacting with the operating
22- system to create memory segments that are shared with the `Receiver`, and
23- sending unbuffered messages to the `Receiver`. However, a `Sender` should be
24- agnostic to the actual content of those memory segments and messages. The
25- `Sender` trait is meant to be easy to implement in terms of a wide range of
30+ system to create memory segments that are shared with its `Receiver`, and
31+ sending unbuffered messages to the `Receiver`. A `Sender` should be agnostic to
32+ the actual content of those memory segments and messages; only the `Sender`'s
33+ user knows their interpretation.
34+
35+ The `Sender` trait is meant to be easy to implement in terms of a wide range of
2636operating system mechanisms:
2737
2838- A Unix implementation might use [`mmap`] to create memory segments, and then
@@ -38,15 +48,22 @@ operating system mechanisms:
3848
3949## Receivers
4050
41- The [`Receiver`] trait is meant to be implemented by users of the transport,
42- serving as the callback invoked when messages are received. Exactly how
43- `Receiver`s get called is specific to the `Sender` implementation:
51+ An implementation of the [`Receiver`] trait serves as the callback invoked when
52+ messages are received. It is meant to be implemented by users of the transport.
53+
54+ Exactly how `Receiver`s get called when messages arrive is specific to the
55+ `Sender` implementation:
4456
4557- A `Sender` implementation might spawn a thread to read messages from a socket
46- and invoke the `Receiver` when a complete message has been received.
58+ and invoke the `Receiver` when complete messages have been received.
59+
60+ - A `Sender` implementation might register an internal listener with
61+ some sort of platform event loop, and have that listener call the
62+ `Receiver` when appropriate.
4763
48- - A `Sender` implementation might register a listener with some sort of platform
49- event loop, and have that listener call the `Receiver` when appropriate.
64+ Whatever the case, the `Sender` implementation should document this behavior.
65+ For example, users may need to know which thread the `Receiver` is invoked on to
66+ avoid deadlocks.
5067
5168The [`Sender`] and [`Receiver`] traits are meant to integrate smoothly with
5269existing interprocess communication mechanisms and event loops, like Firefox's
0 commit comments