Skip to content

Commit 9ccbdb3

Browse files
committed
doc fixes
1 parent 7a6e071 commit 9ccbdb3

1 file changed

Lines changed: 30 additions & 14 deletions

File tree

  • wgpu-remote/src/transport

wgpu-remote/src/transport/mod.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,27 @@ communication in each direction between client and server. This documentation
1111
refers 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, you could build a communications channel carrying typed messages by
19+
using `Sender` to create and map a shared memory segment and serializing the
20+
messages into the shared memory. When it is full, you would call
21+
[`Sender::send_message`] to alert your counterpart to the whole batch of
22+
messages. Your [`Receiver::receive_message`] implementation in the counterpart
23+
would then map the shared memory segment, and deserialize the messages from the
24+
given range.
1825
1926
## Senders
2027
2128
A [`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
29+
system to create memory segments that are shared with its `Receiver`, and
30+
sending unbuffered messages to the `Receiver`. A `Sender` should be agnostic to
31+
the actual content of those memory segments and messages; only the `Sender`'s
32+
user knows their interpretation.
33+
34+
The `Sender` trait is meant to be easy to implement in terms of a wide range of
2635
operating system mechanisms:
2736
2837
- A Unix implementation might use [`mmap`] to create memory segments, and then
@@ -38,15 +47,22 @@ operating system mechanisms:
3847
3948
## Receivers
4049
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:
50+
An implementation of the [`Receiver`] trait serves as the callback invoked when
51+
messages are received. It is meant to be implemented by users of the transport.
52+
53+
Exactly how `Receiver`s get called when messages arrive is specific to the
54+
`Sender` implementation:
4455
4556
- 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.
57+
and invoke the `Receiver` when complete messages have been received.
58+
59+
- A `Sender` implementation might register an internal listener with
60+
some sort of platform event loop, and have that listener call the
61+
`Receiver` when appropriate.
4762
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.
63+
Whatever the case, the `Sender` implementation should document this behavior.
64+
For example, users may need to know which thread the `Receiver` is invoked on to
65+
avoid deadlocks.
5066
5167
The [`Sender`] and [`Receiver`] traits are meant to integrate smoothly with
5268
existing interprocess communication mechanisms and event loops, like Firefox's

0 commit comments

Comments
 (0)