xtrans.xml revision af928962
1<?xml version="1.0" encoding="UTF-8" ?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3                      "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
4
5<!-- lifted from troff+ms+XMan by doclifter -->
6<book id="xtrans">
7
8<bookinfo>
9   <title>X Transport Interface</title>
10   <subtitle>X Consortium Standard</subtitle>
11   <releaseinfo>X Version 11, Release 7.X</releaseinfo>
12   <authorgroup>
13      <author>
14         <firstname>Stuart</firstname><surname>Anderson</surname>
15      </author>
16   </authorgroup>
17   <othercredit><firstname>Ralph</firstname><surname>Mor</surname></othercredit>
18   <othercredit><firstname>Alan</firstname><surname>Coopersmith</surname></othercredit>
19   <corpname>NCR Corporation</corpname>
20   <releaseinfo>Version 0.7</releaseinfo>
21   <affiliation><orgname>The Open Group</orgname></affiliation>
22   <productnumber>X Version 11, Release 7.x</productnumber>
23
24<legalnotice>
25<para>
26Copyright &copy; 1993, 1994 NCR Corporation - Dayton, Ohio, USA
27</para>
28
29<para>
30All Rights Reserved
31</para>
32
33<para>
34Permission to use, copy, modify, and distribute this software and its
35documentation for any purpose and without fee is hereby granted, provided
36that the above copyright notice appear in all copies and that both that
37copyright notice and this permission notice appear in supporting
38documentation, and that the name NCR not be used in advertising
39or publicity pertaining to distribution of the software without specific,
40written prior permission.  NCR makes no representations about the
41suitability of this software for any purpose.  It is provided "as is"
42without express or implied warranty.
43</para>
44
45<para>
46NCR DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
47INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
48NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
49CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
50OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
51NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
52CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
53</para>
54
55</legalnotice>
56
57<legalnotice>
58<para>
59Copyright &copy; 1993, 1994, 2002 The Open Group
60</para>
61
62<para>
63Permission is hereby granted, free of charge, to any person obtaining a copy
64of this software and associated documentation files (the &ldquo;Software&rdquo;), to deal
65in the Software without restriction, including without limitation the rights
66to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
67copies of the Software, and to permit persons to whom the Software is
68furnished to do so, subject to the following conditions:
69</para>
70
71<para>
72The above copyright notice and this permission notice shall be included in
73all copies or substantial portions of the Software.
74</para>
75
76<para>
77THE SOFTWARE IS PROVIDED &ldquo;AS IS&rdquo;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
78IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
79FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
80OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
81AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
82CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
83</para>
84
85<para>
86Except as contained in this notice, the name of The Open Group shall not be
87used in advertising or otherwise to promote the sale, use or other dealings
88in this Software without prior written authorization from The Open Group.
89</para>
90
91<para>
92X Window System is a trademark of The Open Group, Inc.
93</para>
94
95</legalnotice>
96
97</bookinfo>
98
99<preface><title>The X Transport Interface</title>
100<para>
101Designed by Stuart Anderson (NCR) with help from Ralph Mor (X Consortium)
102</para>
103
104<note><para>
105This documentation does not completely match the implementation in R6
106(as a result of some late changes made in the code). Specifically, support
107was added for font server cloning, and conditional compliation was introduced
108for client vs. server code.
109</para></note>
110</preface>
111
112<chapter id='purposes_and_goals'>
113<title>Purposes and Goals</title>
114
115<para>The X Transport Interface is intended to combine all system and
116transport specific code into a single place in the source tree. This API
117should be used by all libraries, clients and servers of the X Window System.
118Use of this API should allow the addition of new types of transports and
119support for new platforms without making any changes to the source except
120in the X Transport Interface code.</para>
121<para>This interface should solve the problem of multiple
122<code>#ifdef TRANSPORT</code> and <code>#ifdef PLATFORM</code>
123statements scattered throughout the source tree.</para>
124<para>This interface should provide enough functionality to support all
125types of protocols, including connection oriented protocols such as X11 and
126FS, and connection-less oriented protocols such as XDMCP.</para>
127
128</chapter>
129
130<chapter id='overview_of_the_interface'>
131<title>Overview of the Interface</title>
132
133<para>
134The interface provides an API for use by applications. The functions in
135this API perform work that is common to all transports and systems, such
136as parsing an address into a host and port number. The functions in this
137API call transport specific functions that are contained in a table whose
138contents are defined at compile time. This table contains an entry for each
139type of transport. Each entry is a record containing mostly pointers to
140function that implements the interface for the given transport.
141</para>
142<para>
143This API does not provide an abstraction for <function>select()</function>
144or <function>poll()</function>.
145These functions are themselves transport independent, so an additional
146interface is not needed for these functions. It is also unclear how such
147an interface would affect performance.
148</para>
149</chapter>
150
151<chapter id='definition_of_address_specification_format'>
152<title>Definition of Address Specification Format</title>
153
154<para>
155Addresses are specified in the following syntax,
156
157<synopsis>
158<replaceable>protocol</replaceable>/<replaceable>host</replaceable>:<replaceable>port</replaceable>
159</synopsis>
160
161where <replaceable>protocol</replaceable> specifies a protocol family
162or an alias for a protocol family. A definition of common protocol
163families is given in a later section.
164</para>
165<para>
166The <replaceable>host</replaceable> part specifies the name of a host or other
167transport dependent entity that could be interpreted as a Network Service Access Point
168(NSAP).
169</para>
170<para>
171The <replaceable>port</replaceable> part specifies the name of a Transport Service
172Access Point (TSAP). The format of the TSAP is defined by the underlying transport
173implementation, but it is represented using a string format when it is
174part of an address.
175</para>
176</chapter>
177
178<chapter id='internal_data_structures'>
179<title>Internal Data Structures</title>
180<para>
181There are two major data structures associated with the transport
182independent portion of this interface.  Additional data structures
183may be used internally by each transport.
184</para>
185<sect1 id="xtransport">
186<title>Xtransport</title>
187<para>
188Each transport supported has an entry in the transport table. The transport
189table is an array of Xtransport records. Each record contains all the entry
190points for a single transport. This record is defined as:
191</para>
192
193<synopsis>
194typedef struct _Xtransport {
195
196    char *TransName;
197    int  flags;
198
199    XtransConnInfo (*OpenCOTSClient)(
200    struct _Xtransport *,     /* transport */
201    char     *,     /* protocol */
202    char     *,     /* host */
203    char     *      /* port */
204    );
205
206    XtransConnInfo (*OpenCOTSServer)(
207    struct _Xtransport *,     /* transport */
208    char *,     /* protocol */
209    char *,     /* host */
210    char *      /* port */
211    );
212
213    XtransConnInfo (*OpenCLTSClient)(
214    struct _Xtransport *,     /* transport */
215    char *,               /* protocol */
216    char *,               /* host */
217    char *               /* port */
218    );
219
220    XtransConnInfo (*OpenCLTSServer)(
221     struct _Xtransport *,   /* transport */
222     char *,     /* protocol */
223     char *,     /* host */
224     char *     /* port */
225    );
226
227    int     (*SetOption)(
228     XtransConnInfo,          /* connection */
229     int,               /* option */
230     int               /* arg */
231    );
232
233    int     (*CreateListener)(
234     XtransConnInfo,          /* connection */
235     char *,               /* port */
236     int               /* flags */
237    );
238
239    int     (*ResetListener)(
240     XtransConnInfo          /* connection */
241    );
242
243    XtransConnInfo (*Accept)(
244     XtransConnInfo          /* connection */
245    );
246
247    int     (*Connect)(
248     XtransConnInfo,          /* connection */
249     char *,               /* host */
250     char *               /* port */
251    );
252
253    int     (*BytesReadable)(
254     XtransConnInfo,          /* connection */
255     BytesReadable_t *     /* pend */
256    );
257
258    int     (*Read)(
259     XtransConnInfo,          /* connection */
260     char *,               /* buf */
261     int               /* size */
262    );
263
264    int     (*Write)(
265     XtransConnInfo,          /* connection */
266     char *,               /* buf */
267     int               /* size */
268    );
269
270    int     (*Readv)(
271     XtransConnInfo,          /* connection */
272     struct iovec *,          /* buf */
273     int               /* size */
274    );
275
276    int     (*Writev)(
277     XtransConnInfo,          /* connection */
278     struct iovec *,          /* buf */
279     int               /* size */
280    );
281
282    int     (*Disconnect)(
283     XtransConnInfo          /* connection */
284    );
285
286    int     (*Close)(
287     XtransConnInfo          /* connection */
288    );
289
290} Xtransport;
291</synopsis>
292
293<para>
294The <structfield>flags</structfield> field can contain an OR of
295the following masks:
296<variablelist>
297  <varlistentry>
298    <term><symbol>TRANS_ALIAS</symbol></term>
299    <listitem><para>
300indicates that this record is providing an alias, and should
301not be used to create a listener.
302      </para></listitem>
303  </varlistentry>
304  <varlistentry>
305    <term><symbol>TRANS_LOCAL</symbol></term>
306    <listitem><para>
307indicates that this is a <symbol>LOCALCONN</symbol> transport.
308    </para></listitem>
309  </varlistentry>
310  <varlistentry>
311    <term><symbol>TRANS_ABSTRACT</symbol></term>
312    <listitem><para>
313indicates that a local connection transport uses the abstract socket namespace.
314    </para></listitem>
315  </varlistentry>
316</variablelist>
317</para>
318
319<para>
320Some additional flags may be set in the <structfield>flags</structfield>
321field by the library while it is running:
322<variablelist>
323  <varlistentry>
324    <term><symbol>TRANS_DISABLED</symbol></term>
325    <listitem><para>
326indicates that this transport has been disabled.
327    </para></listitem>
328  </varlistentry>
329  <varlistentry>
330    <term><symbol>TRANS_NOLISTEN</symbol></term>
331    <listitem><para>
332indicates that servers should not open new listeners using this transport.
333    </para></listitem>
334  </varlistentry>
335  <varlistentry>
336    <term><symbol>TRANS_NOUNLINK</symbol></term>
337    <listitem><para>
338set by a transport backend to indicate that the endpoints for its connection
339should not be unlinked.
340    </para></listitem>
341  </varlistentry>
342</variablelist>
343</para>
344</sect1>
345
346<sect1 id="xtransconninfo">
347<title>XtransConnInfo</title>
348<para>
349Each connection will have an opaque <structname>XtransConnInfo</structname>
350transport connection
351object allocated for it. This record contains information specific to the
352connection. The record is defined as:
353
354<synopsis>
355typedef struct _XtransConnInfo *XtransConnInfo;
356
357struct _XtransConnInfo {
358    struct _Xtransport     *transptr;
359    char     *priv;
360    int          flags;
361    int          fd;
362    int          family;
363    char     *addr;
364    int          addrlen;
365    char     *peeraddr;
366    int          peeraddrlen;
367};
368</synopsis>
369</para>
370</sect1>
371</chapter>
372
373<chapter id='exposed_transport_independent_api'>
374<title>Exposed Transport Independent API</title>
375
376<para>
377This API is included in each library and server that uses it. The API may
378be used by the library, but it is not added to the public API for that
379library. This interface is simply an implementation facilitator. This API
380contains a low level set of core primitives, and a few utility functions
381that are built on top of the primitives.  The utility functions exist to
382provide a more familiar interface that can be used to port existing code.
383</para>
384<para>
385A macro is defined in Xtrans.h for TRANS(func) that creates a unique function
386name depending on where the code is compiled. For example, when built for
387Xlib, TRANS(OpenCOTSClient) becomes <function>_X11TransOpenCOTSClient</function>.
388</para>
389<para>
390All failures are considered fatal, and the connection should be closed
391and re-established if desired. In most cases, however, the value of
392errno will be available for debugging purposes.
393</para>
394<sect1 id="core_interface_api">
395<title>Core Interface API</title>
396<itemizedlist mark='bullet'>
397  <listitem>
398    <para>
399XtransConnInfo TRANS(OpenCOTSClient)(char *address)
400    </para>
401    <para>
402This function creates a Connection-Oriented Transport that is
403suitable for use by a client. The parameter <parameter>address</parameter>
404contains the full address of the server to which this endpoint will be connected.  This
405functions returns an opaque transport connection object on success, or
406NULL on failure.
407    </para>
408  </listitem>
409  <listitem>
410    <para>
411XtransConnInfo TRANS(OpenCOTSServer)(char *address)
412    </para>
413    <para>
414This function creates a Connection-Oriented Transport that is suitable
415for use by a server. The parameter <parameter>address</parameter> contains the
416full address to which this server will be bound. This functions returns an opaque
417transport connection object on success, or NULL on failure.
418    </para>
419  </listitem>
420  <listitem>
421    <para>
422XtransConnInfo TRANS(OpenCLTSClient)(char *address)
423    </para>
424    <para>
425This function creates a Connection-Less Transport that is suitable for
426use by a client. The parameter <parameter>address</parameter> contains the
427full address of the server to which this endpoint will be connected. This functions
428returns an opaque transport connection object on success, or NULL on failure.
429    </para>
430  </listitem>
431  <listitem>
432    <para>
433XtransConnInfo TRANS(OpenCLTSServer)(char *address)
434    </para>
435    <para>
436This function creates a Connection-Less Transport that is suitable for
437use by a server. The parameter <parameter>address</parameter> contains the
438full address to which this server will be bound. This functions returns an opaque
439transport connection object on success, or NULL on failure.
440    </para>
441  </listitem>
442  <listitem>
443    <para>
444int TRANS(SetOption)(XtransConnInfo connection, int option, int arg)
445    </para>
446    <para>
447This function sets transport options, similar to the way
448<function>setsockopt()</function> and <function>ioctl()</function> work.
449The parameter <parameter>connection</parameter> is an endpoint
450that was obtained from _XTransOpen*() functions. The parameter
451<parameter>option</parameter> contains the option that will be set. The actual
452values for option are defined in a later section. The parameter
453<parameter>arg</parameter> can be used to pass in an additional value that may
454be required by some options. This function return 0 on
455success and -1 on failure.
456    </para>
457    <note><para>
458Based on current usage, the complimentary function
459<function>TRANS(GetOption)</function> is not necessary.
460    </para></note>
461  </listitem>
462  <listitem>
463    <para>
464int TRANS(CreateListener)(XtransConnInfo connection, char *port, int flags)
465    </para>
466    <para>
467This function sets up the server endpoint for listening. The parameter
468<parameter>connection</parameter> is an endpoint that was obtained from
469<function>TRANS(OpenCOTSServer)()</function> or
470<function>TRANS(OpenCLTSServer)()</function>. The parameter
471<parameter>port</parameter> specifies the
472port to which this endpoint should be bound for listening. If port is NULL,
473then the transport may attempt to allocate any available TSAP for this
474connection. If the transport cannot support this, then this function will
475return a failure. The <parameter>flags</parameter> parameter can be set
476to <symbol>ADDR_IN_USE_ALLOWED</symbol> to allow the call to the underlying
477binding function to fail with a <errorname>EADDRINUSE</errorname> error
478without causing the <function>TRANS(CreateListener)</function>
479function itself to fail. This function return 0 on success and -1 on failure.
480    </para>
481  </listitem>
482  <listitem>
483    <para>
484int TRANS(ResetListener)(XtransConnInfo connection)
485    </para>
486    <para>
487When a server is restarted, certain listen ports may need to be reset.
488For example, unix domain needs to check that the file used for
489communication has not been deleted. If it has, it must be recreated.
490The parameter <parameter>connection</parameter> is an opened and bound
491endpoint that was obtained from <function>TRANS(OpenCOTSServer)()</function>
492and passed to <function>TRANS(CreateListener)()</function>.
493This function will return one of the following values:
494<symbol>TRANS_RESET_NOOP</symbol>,
495<symbol>TRANS_RESET_NEW_FD</symbol>, or
496<symbol>TRANS_RESET_FAILURE</symbol>.
497    </para>
498  </listitem>
499  <listitem>
500    <para>
501XtransConnInfo TRANS(Accept)(XtransConnInfo connection)
502    </para>
503    <para>
504Once a connection indication is received, this function can be called to
505accept the connection. The parameter <parameter>connection</parameter> is
506an opened and bound endpoint that was obtained from
507<function>TRANS(OpenCOTSServer)()</function> and passed to
508<function>TRANS(CreateListener)()</function>. This function will return a
509new opaque transport connection object upon success, NULL otherwise.
510    </para>
511  </listitem>
512  <listitem>
513    <para>
514int TRANS(Connect)(XtransConnInfo connection, char *address)
515    </para>
516    <para>
517This function creates a connection to a server. The parameter
518<parameter>connection</parameter> is an endpoint that was obtained
519from <function>TRANS(OpenCOTSClient)()</function>. The parameter
520<parameter>address</parameter> specifies the TSAP to which this endpoint
521should connect. If the
522protocol is included in the address, it will be ignored. This function
523return 0 on success and -1 on failure.
524    </para>
525  </listitem>
526  <listitem>
527    <para>
528int TRANS(BytesReadable)(XtransConnInfo connection, BytesReadable_t *pend);
529    </para>
530    <para>
531This function provides the same functionality as the BytesReadable macro.
532    </para>
533  </listitem>
534  <listitem>
535    <para>
536int TRANS(Read)(XtransConnInfo connection, char *buf, int size)
537    </para>
538    <para>
539This function will return the number of bytes requested on a COTS
540connection, and will return the minimum of the number bytes requested or
541the size of the incoming packet on a CLTS connection.
542    </para>
543  </listitem>
544  <listitem>
545    <para>
546int TRANS(Write)(XtransConnInfo connection, char *buf, int size)
547    </para>
548    <para>
549This function will write the requested number of bytes on a COTS
550connection, and will send a packet of the requested size on a CLTS connection.
551    </para>
552  </listitem>
553  <listitem>
554    <para>
555int TRANS(Readv)(XtransConnInfo connection, struct iovec *buf, int size)
556    </para>
557    <para>
558Similar to <function>TRANS(Read)()</function>.
559    </para>
560  </listitem>
561  <listitem>
562    <para>
563  int TRANS(Writev)(XtransConnInfo connection, struct iovec *buf, int size)
564    </para>
565    <para>
566Similar to <function>TRANS(Write)()</function>.
567    </para>
568  </listitem>
569  <listitem>
570    <para>
571int TRANS(Disconnect)(XtransConnInfo connection)
572    </para>
573    <para>
574This function is used when an orderly disconnect is desired. This function
575breaks the connection on the transport. It is similar to the socket function
576<function>shutdown()</function>.
577    </para>
578  </listitem>
579  <listitem>
580    <para>
581int TRANS(Close)(XtransConnInfo connection)
582    </para>
583    <para>
584This function closes the transport, unbinds it, and frees all resources that
585was associated with the transport. If a <function>TRANS(Disconnect)</function>
586call was not made on the connection, a disorderly disconnect may occur.
587    </para>
588  </listitem>
589  <listitem>
590    <para>
591int TRANS(IsLocal)(XtransConnInfo connection)
592    </para>
593    <para>
594Returns TRUE if it is a local transport.
595    </para>
596  </listitem>
597  <listitem>
598    <para>
599int TRANS(GetMyAddr)(XtransConnInfo connection, int *familyp, int *addrlenp,
600Xtransaddr **addrp)
601    </para>
602    <para>
603This function is similar to
604<function>getsockname()</function>.
605This function will allocate space for the address, so it must be freed by
606the caller. Not all transports will have a valid address until a connection
607is established.  This function should not be used until the connection is
608established with
609<function>Connect()</function> or
610<function>Accept()</function>.
611    </para>
612  </listitem>
613  <listitem>
614    <para>
615int TRANS(GetPeerAddr)(XtransConnInfo connection, int *familyp, int *addrlenp,
616Xtransaddr **addrp)
617    </para>
618    <para>
619This function is similar to
620<function>getpeername()</function>.
621This function will allocate space for the address, so it must be freed by
622the caller. Not all transports will have a valid address until a connection
623is established.  This function should not be used until the connection is
624established with
625<function>Connect()</function> or
626<function>Accept()</function>.
627    </para>
628  </listitem>
629  <listitem>
630    <para>
631int TRANS(GetConnectionNumber)(XtransConnInfo connection)
632    </para>
633    <para>
634Returns the file descriptor associated with this transport.
635    </para>
636  </listitem>
637  <listitem>
638    <para>
639int TRANS(MakeAllCOTSServerListeners)(char *port, int *partial_ret,
640int *count_ret, XtransConnInfo **connections_ret)
641    </para>
642    <para>
643This function should be used by most servers. It will try to establish
644a COTS server endpoint for each transport listed in the transport table.
645<parameter>partial_ret</parameter> will be set to <symbol>True</symbol> if
646only a partial network could be created. <parameter>count_ret</parameter> is
647the number of transports returned, and <parameter>connections_ret</parameter>
648is the list of transports.
649    </para>
650  </listitem>
651  <listitem>
652    <para>
653int TRANS(MakeAllCLTSServerListeners)( char *port, int *partial_ret,
654int *count_ret, XtransConnInfo **connections_ret)
655    </para>
656    <para>
657This function should be used by most servers. It will try to establish a
658CLTS server endpoint for each transport listed in the transport table.
659<parameter>partial_ret</parameter> will be set to <symbol>True</symbol> if
660only a partial network could be created. <parameter>count_ret</parameter> is
661the number of transports returned, and <parameter>connections_ret</parameter>
662is the list of transports.
663    </para>
664  </listitem>
665</itemizedlist>
666</sect1>
667
668<sect1 id="utility_api">
669<title>Utility API</title>
670<para>
671This section describes a few useful functions that have been implemented on
672top of the Core Interface API.  These functions are being provided as a
673convenience.
674</para>
675<itemizedlist mark='bullet'>
676  <listitem>
677    <para>
678int TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr *addrp)
679    </para>
680    <para>
681This function converts a sockaddr based address to an X authorization based
682address (ie AF_INET, AF_UNIX to the X protocol definition (ie FamilyInternet,
683FamilyLocal)).
684    </para>
685  </listitem>
686</itemizedlist>
687</sect1>
688</chapter>
689
690<chapter id="transport_option_definition">
691<title>Transport Option Definition</title>
692<para>
693The following options are defined for the
694<function>TRANS(SetOption)()</function>
695 function. If an OS or transport does not support any of these options,
696then it will silently ignore the option.
697</para>
698
699<itemizedlist mark='bullet'>
700  <listitem>
701    <para>
702<symbol>TRANS_NONBLOCKING</symbol>
703    </para>
704    <para>
705This option controls the blocking mode of the connection. If the argument
706is set to 1, then the connection will be set to blocking. If the argument
707is set to 0, then the connection will be set to non- blocking.
708    </para>
709  </listitem>
710  <listitem>
711    <para>
712<symbol>TRANS_CLOSEONEXEC</symbol>
713    </para>
714    <para>
715This option determines what will happen to the connection when an exec is
716encountered. If the argument is set to 1, then the connection will be
717closed when an exec occurs. If the argument is set to 0, then the
718connection will not be closed when an exec occurs.
719    </para>
720  </listitem>
721</itemizedlist>
722</chapter>
723
724<chapter id="hidden_transport_dependent_api">
725<title>Hidden Transport Dependent API</title>
726<para>
727The hidden transport dependent functions are placed in the Xtransport record.
728These function are similar to the Exposed Transport Independent API, but
729some of the parameters and return values are slightly different.  Stuff like
730the <code>#ifdef SUNSYSV</code> should be handled inside these functions.
731</para>
732
733<itemizedlist mark='bullet'>
734  <listitem>
735    <para>
736XtransConnInfo *OpenCOTSClient (
737struct _Xtransport *thistrans, char *protocol, char *host, char *port)
738    </para>
739    <para>
740This function creates a Connection-Oriented Transport. The parameter
741<parameter>thistrans</parameter>
742points to an Xtransport entry in the transport table. The parameters
743<parameter>protocol</parameter>,
744<parameter>host</parameter>,  and
745<parameter>port</parameter>, point to strings containing the corresponding
746parts of the address that was passed into <function>TRANS(OpenCOTSClient)()</function>.
747This function must allocate and initialize the contents of the XtransConnInfo
748structure that is returned by this function. This function will open the
749transport, and bind it into the transport namespace if applicable. The local
750address portion of the XtransConnInfo structure will also be filled in by
751this function.
752    </para>
753  </listitem>
754  <listitem>
755    <para>
756XtransConnInfo *OpenCOTSServer (
757struct _Xtransport *thistrans, char *protocol, char *host, char *port)
758    </para>
759    <para>
760This function creates a Connection-Oriented Transport. The parameter
761<parameter>thistrans</parameter>
762points to an Xtransport entry in the transport table. The
763parameters
764<parameter>protocol</parameter>,
765<parameter>host</parameter>, and
766<parameter>port</parameter> point to strings containing the
767corresponding parts of the address that was passed into
768<function>TRANS(OpenCOTSClient)()</function>.
769This function must allocate and initialize the contents of the
770XtransConnInfo structure that is returned by this function. This function
771will open the transport.
772    </para>
773  </listitem>
774  <listitem>
775    <para>
776XtransConnInfo *OpenCLTSClient (
777struct _Xtransport *thistrans, char *protocol, char *host, char *port)
778    </para>
779    <para>
780This function creates a Connection-Less Transport. The parameter
781<parameter>thistrans</parameter>
782points to an Xtransport entry in the transport table. The parameters
783<parameter>protocol</parameter>,
784<parameter>host</parameter>, and
785<parameter>port</parameter> point to strings containing the
786corresponding parts of the address that was passed into
787<function>TRANS(OpenCOTSClient)()</function>.
788This function must allocate and initialize the contents of the XtransConnInfo
789structure that is returned by this function. This function will open the
790transport, and bind it into the transport namespace if applicable. The
791local address portion of the XtransConnInfo structure will also be filled
792in by this function.
793    </para>
794  </listitem>
795  <listitem>
796    <para>
797XtransConnInfo *OpenCLTSServer (
798struct _Xtransport *thistrans, char *protocol, char *host, char *port)
799    </para>
800    <para>
801This function creates a Connection-Less Transport. The parameter
802<parameter>thistrans</parameter>
803points to an Xtransport entry in the transport table. The  parameters
804<parameter>protocol</parameter>,
805<parameter>host</parameter>, and
806<parameter>port</parameter> point to strings containing the
807corresponding parts of the address that was passed into
808<function>TRANS(OpenCOTSClient)()</function>.
809This function must allocate and initialize the contents of the
810XtransConnInfo structure that is returned by this function. This
811function will open the transport.
812    </para>
813  </listitem>
814  <listitem>
815    <para>
816int SetOption (struct _Xtransport *thistrans, int option, int arg)
817    </para>
818    <para>
819This function provides a transport dependent way of implementing the
820options defined by the X Transport Interface. In the current prototype,
821this function is not being used, because all of the options defined so far
822are transport independent. This function will have to be used if a radically
823different transport type is added, or a transport dependent option is defined.
824    </para>
825  </listitem>
826  <listitem>
827    <para>
828int CreateListener (struct _Xtransport *thistrans, char *port, int flags )
829    </para>
830    <para>
831This function takes a transport endpoint opened for a server, and sets it
832up to listen for incoming connection requests. The parameter
833<parameter>port</parameter>
834contains the port portion of the address that was passed to the Open function.
835The parameter <parameter>flags</parameter> should be set to
836<symbol>ADDR_IN_USE_ALLOWED</symbol> if the underlying transport endpoint
837may be already bound and this should not be considered
838as an error. Otherwise flags should be set to 0. This is used by IPv6 code,
839where the same socket can be bound to both an IPv6 address and then to a
840IPv4 address.  This function will bind the transport into the transport
841name space if applicable, and fill in the local address portion of the
842XtransConnInfo structure. The transport endpoint will then be set to
843listen for incoming connection requests.
844    </para>
845  </listitem>
846  <listitem>
847    <para>
848int ResetListener (struct _Xtransport *thistrans)
849    </para>
850    <para>
851This function resets the transport for listening.
852    </para>
853  </listitem>
854  <listitem>
855    <para>
856 XtransConnInfo Accept(struct _Xtransport *thistrans)
857    </para>
858    <para>
859This function creates a new transport endpoint as a result of an
860incoming connection request. The parameter
861<parameter>thistrans</parameter> is the endpoint
862that was opened for listening by the server. The new endpoint is
863opened and bound into the transport’s namespace. A XtransConnInfo
864structure describing the new endpoint is returned from this function
865    </para>
866  </listitem>
867  <listitem>
868    <para>
869int Connect(struct _Xtransport *thistrans, char *host, char *port )
870    </para>
871    <para>
872This function establishes a connection to a server. The parameters
873<parameter>host</parameter>  and
874<parameter>port</parameter>
875describe the server to which the connection should be
876established. The connection will be established so that
877<function>Read()</function> and
878<function>Write()</function> call can be made.
879    </para>
880  </listitem>
881  <listitem>
882    <para>
883int BytesReadable(struct _Xtransport *thistrans, BytesReadable_t *pend )
884    </para>
885    <para>
886This function replaces the
887<function>BytesReadable()</function>
888macro. This allows each transport to have it’s own mechanism for determining
889how much data is ready to be read.
890    </para>
891  </listitem>
892  <listitem>
893    <para>
894int Read(struct _Xtransport *thistrans, char *buf, int size )
895    </para>
896    <para>
897This function reads size bytes into buf from the connection.
898    </para>
899  </listitem>
900  <listitem>
901    <para>
902int Write(struct _Xtransport *thistrans, char *buf, int size )
903    </para>
904    <para>
905This function writes size bytes from buf to the connection.
906    </para>
907  </listitem>
908  <listitem>
909    <para>
910int Readv(struct _Xtransport *thistrans, struct iovec *buf, int size )
911    </para>
912    <para>
913This function performs a <function>readv()</function> on the connection.
914    </para>
915  </listitem>
916  <listitem>
917    <para>
918int Writev(struct _Xtransport *thistrans, struct iovec *buf, int size )
919    </para>
920    <para>
921This function performs a <function>writev()</function> on the connection.
922    </para>
923  </listitem>
924  <listitem>
925    <para>
926int Disconnect(struct _Xtransport *thistrans)
927    </para>
928    <para>
929This function initiates an orderly shutdown of a connection. If a
930transport does not distinguish between orderly and disorderly
931disconnects, then a call to this function will have no affect.
932    </para>
933  </listitem>
934  <listitem>
935    <para>
936int Close(struct _Xtransport *thistrans)
937    </para>
938    <para>
939This function will break the connection, and close the endpoint.
940    </para>
941  </listitem>
942</itemizedlist>
943</chapter>
944<chapter id="configuration">
945<title>Configuration</title>
946
947<para>
948The implementation of each transport can be platform specific. It is expected
949that existing connection types such as <symbol>TCPCONN</symbol>,
950<symbol>UNIXCONN</symbol>, <symbol>LOCALCONN</symbol>, and
951<symbol>STREAMSCONN</symbol> will be replaced with flags for each
952possible transport type.
953</para>
954<para>
955In X11R6, the below flags to enable transport types were set in
956<symbol>ConnectionFlags</symbol> in the <filename>vendor.cf</filename> or
957<filename>site.def</filename> config files.
958</para>
959<para>
960In X11R7 modular releases, these flags are set when running
961<filename>configure</filename> scripts which include the
962<function>XTRANS_CONNECTION_FLAGS</function> macro from
963<filename>xtrans.m4</filename>.
964</para>
965<informaltable pgwide='0' frame='none'>
966  <tgroup cols='4' align='left'>
967    <colspec colname='define' align='center'/>
968    <colspec colname='enable'/>
969    <colspec colname='desc'/>
970    <thead>
971      <row>
972	<entry><code>#define</code></entry>
973	<entry>configure flag</entry>
974	<entry>Description</entry>
975      </row>
976    </thead>
977    <tbody>
978      <row>
979	<entry><symbol>TCPCONN</symbol></entry>
980	<entry><option>--enable-tcp-transport</option></entry>
981	<entry>
982	Enables the INET (IPv4) Domain Socket based transport
983	</entry>
984      </row>
985      <row>
986	<entry><symbol>IPv6</symbol></entry>
987	<entry><option>--enable-ipv6</option></entry>
988	<entry>
989	Extends <symbol>TCPCONN</symbol> to enable IPv6 Socket based transport
990	</entry>
991      </row>
992      <row>
993	<entry><symbol>UNIXCONN</symbol></entry>
994	<entry><option>--enable-unix-transport</option></entry>
995	<entry>
996	Enables the UNIX Domain Socket based transport
997	</entry>
998      </row>
999      <row>
1000	<entry><symbol>STREAMSCONN</symbol></entry>
1001	<entry><emphasis>Not available in X11R7</emphasis></entry>
1002	<entry>
1003	Enables the TLI based transports
1004	</entry>
1005      </row>
1006      <row>
1007	<entry><symbol>LOCALCONN</symbol></entry>
1008	<entry><option>--enable-local-transport</option></entry>
1009	<entry>
1010	Enables the SYSV Local connection transports
1011	</entry>
1012      </row>
1013      <row>
1014	<entry><symbol>DNETCONN</symbol></entry>
1015	<entry><emphasis>Not available in X11R7</emphasis></entry>
1016	<entry>
1017	Enables the DECnet transports
1018	</entry>
1019      </row>
1020    </tbody>
1021  </tgroup>
1022</informaltable>
1023
1024
1025</chapter>
1026
1027<chapter id="transport_specific_definitions">
1028<title>Transport Specific Definitions</title>
1029
1030<informaltable pgwide='0' frame='none'>
1031  <tgroup cols='4' align='center'>
1032    <colspec colname='c1'/>
1033    <colspec colname='c2'/>
1034    <colspec colname='c3'/>
1035    <colspec colname='c4'/>
1036    <thead>
1037      <row>
1038        <entry morerows="1" align='center'>Protocol Family</entry>
1039        <entry namest="c2" nameend="c4"  align='center'>Address Component</entry>
1040      </row>
1041      <row>
1042        <entry align='center'>protocol</entry>
1043        <entry align='center'>host</entry>
1044        <entry align='center'>port</entry>
1045      </row>
1046    </thead>
1047    <tbody>
1048      <row>
1049        <entry align='center'>Internet</entry>
1050        <entry align='center'>inet inet6 tcp udp</entry>
1051        <entry align='center'>name of an internet addressable host</entry>
1052        <entry align='center'>string containing the name of a service or a valid port number.  Example: "xserver0", "7100"</entry>
1053      </row>
1054      <row>
1055        <entry align='center'>DECnet</entry>
1056        <entry align='center'>decnet</entry>
1057        <entry align='center'>name of a DECnet addressable host</entry>
1058        <entry align='center'>string containing the complete name of the object.  Example: "X$X0"</entry>
1059      </row>
1060      <row>
1061        <entry align='center'>NETware</entry>
1062        <entry align='center'>ipx</entry>
1063        <entry align='center'>name of a NETware addressable host</entry>
1064        <entry align='center'>Not sure of the specifics yet.</entry>
1065      </row>
1066      <row>
1067        <entry align='center'>OSI</entry>
1068        <entry align='center'>osi</entry>
1069        <entry align='center'>name of an OSI adressable host.</entry>
1070        <entry align='center'>Not sure of the specifics yet.</entry>
1071      </row>
1072      <row>
1073        <entry align='center'>Local</entry>
1074        <entry align='center'>local pts named sco isc</entry>
1075        <entry align='center'>(ignored)</entry>
1076        <entry align='center'>String containing the port name, ie "xserver0", "fontserver0".</entry>
1077      </row>
1078    </tbody>
1079  </tgroup>
1080</informaltable>
1081
1082</chapter>
1083
1084<chapter id="implementation_notes">
1085<title>Implementation Notes</title>
1086<para>
1087This section refers to the prototype implementation that is being developed
1088concurrently with this document. This prototype has been able to flush out many
1089details and problems as the specification was being developed.
1090</para>
1091<para>
1092In X11R6, all of the source code for this interface was located in
1093<filename>xc/lib/xtrans</filename>.
1094</para>
1095<para>
1096In X11R7, all of the source code for this interface is delivered via
1097the <systemitem>lib/libxtrans</systemitem> modular package from X.Org,
1098and is installed under
1099<filename><replaceable>${prefix}</replaceable>/X11/Xtrans</filename>
1100so that other modules may find it when they build.
1101</para>
1102<para>
1103All functions names in the source are of the format
1104<function>TRANS(func)()</function>. The
1105<function>TRANS()</function>
1106macro is defined as
1107<programlisting language="C">
1108#if (__STDC__ &amp;&amp; !defined(UNIXCPP)) || defined(ANSICPP)
1109#define TRANS(func) _PROTOCOLTrans##func
1110#else
1111#define TRANS(func) _PROTOCOLTrans/**/func
1112#endif
1113</programlisting>
1114</para>
1115
1116<para>
1117<symbol>PROTOCOL</symbol> will be uniquely defined in each directory
1118where this code is compiled.
1119<symbol>PROTOCOL</symbol> will be defined to be the name of the protocol
1120that is implemented by the library or server, such as X11, FS, and ICE.
1121</para>
1122
1123<para>
1124All libraries and servers that use the X Transport Interface should have a new
1125file called <filename><replaceable>TRANSPORT</replaceable>trans.c</filename>.
1126This file will include the transports based on the configuration flags
1127provided by the <filename>configure</filename> script. Below is an
1128example <filename>xfstrans.c</filename> for the font server.
1129</para>
1130
1131<programlisting language="C">
1132#include "config.h"
1133
1134#define FONT_t 1
1135#define TRANS_REOPEN 1
1136#define TRANS_SERVER 1
1137
1138#include &lt;X11/Xtrans/transport.c&gt;
1139</programlisting>
1140<para>
1141The source files for this interface are listed below.
1142</para>
1143
1144<variablelist>
1145  <varlistentry>
1146    <term><filename>Xtrans.h</filename></term>
1147    <listitem><para>
1148Function prototypes and defines for the Transport Independent API.
1149    </para></listitem>
1150  </varlistentry>
1151  <varlistentry>
1152    <term><filename>Xtransint.h</filename></term>
1153    <listitem><para>
1154Used by the interface implementation only.
1155Contains the internal data structures.
1156    </para></listitem>
1157  </varlistentry>
1158  <varlistentry>
1159    <term><filename>Xtranssock.c</filename></term>
1160    <listitem><para>
1161Socket implementation of the Transport Dependent API.
1162    </para></listitem>
1163  </varlistentry>
1164  <varlistentry>
1165    <term><filename>Xtranstli.c</filename></term>
1166    <listitem><para>
1167TLI implementation of the Transport Dependent API.
1168    </para></listitem>
1169  </varlistentry>
1170  <varlistentry>
1171    <term><filename>Xtransdnet.c</filename></term>
1172    <listitem><para>
1173DECnet implementation of the Transport Dependent API.
1174    </para></listitem>
1175  </varlistentry>
1176  <varlistentry>
1177    <term><filename>Xtranslocal.c</filename></term>
1178    <listitem><para>
1179Implementation of the Transport Dependent API for SYSV Local connections.
1180    </para></listitem>
1181  </varlistentry>
1182  <varlistentry>
1183    <term><filename>Xtrans.c</filename></term>
1184    <listitem><para>
1185Exposed Transport Independent API Functions.
1186    </para></listitem>
1187  </varlistentry>
1188  <varlistentry>
1189    <term><filename>Xtransutil.c</filename></term>
1190    <listitem><para>
1191Collection of Utility functions that use the X Transport Interface.
1192    </para></listitem>
1193  </varlistentry>
1194</variablelist>
1195
1196
1197<para>
1198The file <filename>Xtransint.h</filename> contains much of the transport
1199related code that was previously in <filename>Xlibint.h</filename> and
1200<filename>Xlibnet.h</filename>.
1201This will make the definitions available for all transport users. This
1202should also obsolete the equivalent code in other libraries.
1203</para>
1204
1205</chapter>
1206</book>
1207