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