BSD 4_3_Reno release
[unix-history] / usr / src / old / man / mpx.2
CommitLineData
1c15e888 1.\" @(#)mpx.2 4.1 (Berkeley) 5/9/85
e08c6f11
KM
2.\"
3.TH MPX 2
4.AT 3
5.SH NAME
6mpx \- create and manipulate multiplexed files
7.SH SYNOPSIS
8.nf
9.B mpx(name, access)
10.B char *name;
11.PP
12.B join(fd, xd)
13.PP
14.B chan(xd)
15.PP
16.B extract(i, xd)
17.PP
18.B attach(i, xd)
19.PP
20.B detach(i, xd)
21.PP
22.B connect(fd, cd, end)
23.PP
24.B npgrp(i, xd, pgrp)
25.PP
26.B ckill(i, xd, signal)
27.PP
28.B #include <sys/mx.h>
29.B mpxcall(cmd, vec)
30.B int *vec;
31.fi
32.SH DESCRIPTION
33.PP
34.B mpxcall(cmd, vec)
35is the system call shared by the
36library routines described below.
37.I Cmd
38selects a command using values
39defined in
40.IR <sys/mx.h> .
41.I Vec
42is the address of a
43structure containing the arguments
44for the command.
45.PP
46.B mpx(name, access)
47.PP
48.I Mpx
49creates and opens the file
50.I name
51with access permission
52.I access
53(see
54.IR creat (2))
55and returns a file descriptor available for
56reading and writing.
57A \-1 is returned if the file cannot be created,
58if
59.I name
60already exists, or
61if the file table or other operating system
62data structures are full.
63The file descriptor is required for use
64with other routines.
65.PP
66If
67.I name
68is 0,
69a file descriptor is returned as described
70but no entry is created in the file system.
71.PP
72Once created an mpx file may be opened
73(see
74.IR open (2))
75by any process.
76This provides a form of interprocess communication
77whereby a process B can `call' process A
78by opening an mpx file
79created by A.
80To B, the file is ordinary with one exception:
81the
82.I connect
83primitive could be applied to it.
84Otherwise the functions
85described below are used only in process A
86and descendants that inherit the open mpx file.
87.PP
88When a process opens an mpx file, the owner of the
89file receives a control message when the file is next read.
90The method for `answering'
91this kind of call involves
92using
93.I attach
94and
95.I detach
96as described in more detail below.
97.PP
98Once B has opened A's mpx file
99it is said to have a
100.I channel
101to A.
102A channel is a pair of data streams:
103in this case, one from B to A and the
104other from A to B.
105Several processes may open the same mpx file
106yielding multiple channels within the one mpx file.
107By accessing the appropriate channel,
108A can communicate with B and any others.
109When A reads (see
110.IR read (2))
111from the mpx file
112data written to A by the other processes appears
113in A's buffer using a record format
114described in
115.IR mpxio (5).
116When A writes (see
117.IR write (2))
118on its mpx file the data must be formatted in a similar way.
119.PP
120The following commands
121are used to manipulate mpx files and channels.
122.IP
123.IR join \-
124adds a new channel on an mpx file to an open file F.
125I/O on the new channel is I/O on F.
126.br
127.IR chan \-
128creates a new channel.
129.br
130.IR extract \-
131file descriptor maintenance.
132.br
133.IR connect \-
134similar to join except that the open file F is connected
135to an existing channel.
136.br
137.I attach
138and
139.IR detach \-
140used with call protocol.
141.br
142.IR npgrp \-
143manipulates process group numbers so that a channel
144can act as a control terminal (see
145.IR tty (4)).
146.br
147.IR ckill \-
148send signal (see
149.IR signal (2))
150to process group through channel.
151.PP
152A maximum of 15 channels may be connected to an
153mpx file.
154They are numbered 0 through 14.
155.I Join
156may be used to make one mpx file appear as a channel
157on another mpx file.
158A hierarchy or tree of mpx files may be set up in this way.
159In this case
160one of the mpx files must be the root of a tree
161where the other mpx files are interior nodes.
162The maximum depth of such a tree
163is 4.
164.PP
165An
166.I index
167is a 16-bit value
168that denotes a location
169in an mpx tree other than the root:
170the path through mpx `nodes' from the root
171to the location is expressed as a sequence of
1724-bit nibbles.
173The branch taken at the root is represented by
174the low-order 4-bits of an index.
175Each succeeding branch is specified by the next
176higher-order nibble.
177If the length of a path to be expressed
178is less than 4,
179then the illegal channel number, 15,
180must be used to terminate the sequence.
181This is not strictly necessary for the
182simple case of a tree consisting of
183only a root node: its channels
184can be expressed by the numbers
1850 through 14.
186An index
187.I i
188and file descriptor
189.I xd
190for the root of an mpx tree are
191required as arguments to most
192of the commands described below.
193Indices also serve as channel identifiers
194in the record formats given in
195.IR mpxio (5).
196Since \-1 is not a valid index,
197it can be returned as a error indication
198by subroutines that normally return
199indices.
200.PP
201The operating system informs the process managing an mpx file
202of changes in the status of channels attached to the file
203by generating messages that
204are read along with data from the channels.
205The form and content of these messages is described
206in
207.IR mpxio (5).
208.PP
209.B join(fd, xd)
210establishes a connection (channel) between an mpx file
211and another object.
212.I Fd
213is an open file descriptor for a character device
214or an mpx file and
215.I xd
216is the file descriptor of an
217mpx file.
218.I Join
219returns the index for the new channel
220if the operation succeeds and \-1
221if it does not.
222.PP
223Following join,
224.I fd
225may still be used in any system call that would
226have been meaningful before the join operation.
227Thus
228a process can read and write directly to
229.I fd
230as well as access it via
231.I xd.
232If the number of channels
233required for a tree of mpx files
234exceeds the number of open files
235permitted a process by the operating system,
236some of the file descriptors can be released using
237the standard
238.IR close (2)
239call.
240Following a close on an active file descriptor for a channel
241or internal mpx node,
242that object may still be accessed through the root of the
243tree.
244.PP
245.B chan(xd)
246allocates a channel and connects
247one end of it to the mpx file
248represented by file descriptor
249.I xd.
250.I Chan
251returns the index of the new channel or
252a \-1 indicating failure.
253The
254.I extract
255primitive can be used to get a non-multiplexed
256file descriptor for the free end of a channel
257created by
258.I chan.
259.PP
260Both
261.I chan
262and
263.I join
264operate on the mpx file specified by
265.IR xd .
266File descriptors for interior nodes of an
267mpx tree must be preserved or reconstructed with
268.I extract
269for use with
270.I join
271or
272.IR chan .
273For the remaining commands described here,
274.I xd
275denotes the file descriptor for the
276root of an mpx tree.
277.PP
278.B extract(i, xd)
279returns a file descriptor for the object with
280index
281.I i
282on the mpx tree with root file descriptor
283.I xd.
284A \-1 is returned by extract if a file descriptor is not available
285or if the arguments do not refer to an existing
286channel and mpx file.
287.PP
288.B attach(i, xd)
289.br
290.BR "detach(i, xd)" .
291If a process A has created an mpx file represented
292by file descriptor
293.I xd,
294then a process B
295can open (see
296.IR open (2))
297the mpx file.
298The purpose is to establish a channel between
299A and B through the mpx file.
300.I Attach
301and
302.I Detach
303are used by A to respond to
304such opens.
305.PP
306An open request by B fails immediately if a
307new channel cannot be allocated on the mpx file,
308if the mpx file does not exist,
309or if it does exist
310but there is no process (A)
311with a multiplexed file descriptor
312for the mpx file
313(i.e.
314.I xd
315as returned by
316.IR mpx (2)).
317Otherwise a channel
318with index number
319.I i
320is allocated.
321The next time A reads on file descriptor
322.IR xd ,
323the WATCH control message
324(see
325.IR mpxio (5))
326will be delivered on channel
327.I i.
328A responds to this message with
329.I attach
330or
331.I detach.
332The former causes the open to complete and
333return a file descriptor to B.
334The latter deallocates channel
335.I i
336and causes the open to fail.
337.PP
338One mpx file may be placed in `listener' mode.
339This is done by writing
340.I "ioctl(xd, MXLSTN, 0)"
341where
342.I xd
343is an mpx file descriptor
344and MXLSTN is defined in
345.IR /usr/include/sgtty.h .
346The semantics of listener mode are that
347all file names discovered by
348.IR open (2)
349to have
350the syntax
351.I "system!pathname"
352(see
353.IR uucp (1))
354are treated as opens on the mpx file.
355The operating system sends the listener process
356an OPEN message (see
357.IR mpxio (5))
358which includes the file name being opened.
359.I Attach
360and
361.I detach
362then apply as described above.
363.PP
364.I Detach
365has two other uses:
366it closes and releases the resources
367of any active channel it is applied to,
368and should be used to respond to
369a CLOSE message (see
370.IR mpxio (5))
371on a channel so the channel may be reused.
372.PP
373.BR "connect(fd, cd, end)" .
374.I Fd
375is a character file descriptor and
376.I cd
377is a file descriptor for a channel,
378such as might be obtained via
379.I "extract( chan(xd), xd)"
380or by
381.IR open (2)
382followed by
383.I attach.
384.I Connect
385splices the two streams together.
386If
387.I end
388is negative, only
389the output of
390.I fd
391is spliced to the input of
392.I cd.
393If
394.I end
395is positive, the output of
396.I cd
397is spliced to the input of
398.I fd.
399If
400.I end
401is zero, then both splices are made.
402.PP
403.BR "npgrp(i, xd, pgrp)" .
404If
405.I xd
406is negative
407.I npgrp
408applies to the process executing it,
409otherwise
410.I i
411and
412.I xd
413are interpreted as a channel index and
414mpx file descriptor
415and
416.I npgrp
417is applied to the process on the
418non-multiplexed end of the channel.
419If
420.I pgrp
421is zero, the process group number of the indicated process
422is set to the process number of that process,
423otherwise the value of
424.I pgrp
425is used as the process group number.
426.PP
427.I Npgrp
428normally returns the new process group number.
429If
430.I i
431and
432.I xd
433specify a nonexistent channel,
434.I npgrp
435returns \-1.
436.PP
437.B ckill(i, xd, signal)
438sends the specified signal (see
439.IR signal (2))
440through the channel specified by
441.I i
442and
443.I xd.
444If the channel is connected to anything other
445than a process,
446.I ckill
447is a null operation.
448If there is a process at the other end of the channel,
449the process group will be interrupted (see
450.IR signal (2),
451.IR kill (2)).
452.I Ckill
453normally returns
454.I signal.
455If
456.I ch
457and
458.I xd
459specify a nonexistent channel,
460.I ckill
461returns \-1.
462.SH FILES
463/usr/include/sys/mx.h
464.br
465/usr/include/sgtty.h
466.SH "SEE ALSO"
467mpxio(5)
468.SH BUGS
469.PP
470Mpx files are an experimental part of the operating
471system more subject to change and prone to bugs
472than other parts.
473.PP
474Maintenance programs, e.g.
475.IR icheck (1),
476diagnose mpx files as an illegal mode.
477.PP
478Channels may only be connected to objects in the operating
479system that are accessible through the line discipline
480mechanism.
481.PP
482Higher performance line disciplines are needed.
483.PP
484The maximum tree depth restriction is not really checked.
485.PP
486A non-destructive
487.I disconnect
488primitive (inverse of
489.IR connect )
490is not provided.
491.PP
492A non-blocking flow control strategy
493based on messages defined in
494.IR mpxio (5)
495should not be attempted by novices;
496the enabling
497.I ioctl
498command should be protected.
499.PP
500The
501.I join
502operation could be subsumed by
503.I connect.
504A mechanism is needed for moving a channel from one
505location in an mpx tree to another.