3 Mux, muxinit, muxrpc, muxthreads \- protocol multiplexor
15 int (*settag)(Mux *mux, void *msg, uint tag);
16 int (*gettag)(Mux *mux, void *msg);
17 int (*send)(Mux *mux, void *msg);
18 void *(*recv)(Mux *mux);
19 void *(*nbrecv)(Mux *mux);
22 \&... /* private fields follow */
27 void muxinit(Mux *mux);
30 void* muxrpc(Mux *mux, void *request);
33 void muxprocs(Mux *mux);
36 Muxrpc* muxrpcstart(Mux *mux, void *request);
39 void* muxrpccanfinish(Muxrpc *rpc);
42 is a generic protocol multiplexor.
43 A client program initializes a
45 structure with information about the protocol
46 (mainly in the form of helper functions)
49 to execute individual RPCs without worrying
50 about details of multiplexing requests
51 and demultiplexing responses.
54 assumes that the protocol messages contain a
56 (or message ID) field that exists for the sole purpose of demultiplexing messages.
58 chooses the tags and then calls a helper function
59 to put them in the outgoing messages.
61 calls another helper function to retrieve tags
62 from incoming messages.
63 It also calls helper functions to send and receive packets.
65 A client should allocate a
67 structure and then call
69 to initialize the library's private elements.
70 The client must initialize the following elements:
72 .I mintag\fR, \fPmaxtag
73 The range of valid tags;
75 is the maximum valid tag plus one, so that
77 is equal to the number of valid tags.
81 (all tags are being used for RPCs currently in progress),
84 will block until an executing call finishes.
86 .I settag\fR, \fPgettag
87 Set or get the tag value in a message.
89 .I send\fR, \fPrecv\fR, \fPnbrecv
90 Send or receive protocol messages on the connection.
92 should block until a message is available and
93 should return nil if the connection is closed.
95 should not block; it returns nil if there is no
96 message available to be read.
98 will arrange that only one call to
105 An auxiliary pointer for use by the client.
107 Once a client has initialized the
109 structure, it can call
114 is the message passed to
118 The return value is the response packet,
122 nil if an error occurred.
138 in these procs instead of in the calling proc.
139 This is useful if the implementation of
142 blocks an entire proc
143 and there are other threads in the calling proc
144 that need to remain active.
147 also provides a non-blocking interface, useful for programs forced
152 runs the first half of
154 it assigns a tag and sends the request,
155 but does not wait for the reply.
156 Instead it returns a pointer to a
158 structure that represents the in-progress call.
160 checks whether the given call
162 If no mux procs have been started,
166 to poll for newly arrived responses.
169 .B \*9/src/lib9pclient/fs.c
170 for an example of using
183 does not know how to free protocol messages,
184 so message arriving with unexpected or invalid