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