3 Mux, muxinit, muxrpc, muxthreads \- protocol multiplexor
14 int (*settag)(Mux *mux, void *msg, uint tag);
15 int (*gettag)(Mux *mux, void *msg);
16 int (*send)(Mux *mux, void *msg);
17 void *(*recv)(Mux *mux);
20 \&... /* private fields follow */
25 void muxinit(Mux *mux);
28 void* muxrpc(Mux *mux, void *request);
31 void muxprocs(Mux *mux);
34 is a generic protocol multiplexor.
35 A client program initializes a
37 structure with information about the protocol
38 (mainly in the form of helper functions)
41 to execute individual RPCs without worrying
42 about details of multiplexing requests
43 and demultiplexing responses.
46 assumes that the protocol messages contain a
48 (or message ID) field that exists for the sole purpose of demultiplexing messages.
50 chooses the tags and then calls a helper function
51 to put them in the outgoing messages.
53 calls another helper function to retrieve tags
54 from incoming messages.
55 It also calls helper functions to send and receive packets.
57 A client should allocate a
59 structure and then call
61 to initialize the library's private elements.
62 The client must initialize the following elements:
64 .I mintag\fR, \fPmaxtag
65 The range of valid tags;
67 is the maximum valid tag plus one, so that
69 is equal to the number of valid tags.
73 (all tags are being used for RPCs currently in progress),
76 will block until an executing call finishes.
78 .I settag\fR, \fPgettag
79 Set or get the tag value in a message.
82 Send or receive protocol messages on the connection.
84 should block until a message is available and
85 should return nil if the connection is closed.
87 will arrange that only one call to
92 An auxiliary pointer for use by the client.
94 Once a client has initialized the
96 structure, it can call
101 is the message passed to
105 The return value is the response packet,
109 nil if an error occurred.
125 in these procs instead of in the calling proc.
126 This is useful if the implementation of
129 blocks an entire proc
130 and there are other threads in the calling proc
131 that need to remain active.
134 .B /usr/local/plan9/src/lib9pclient/fs.c
135 for an example of using
142 .B /usr/local/plan9/src/libmux
148 does not know how to free protocol messages,
149 so message arriving with unexpected or invalid
154 other than zero is not well tested and probably buggy.