Back to index

im-sdk  12.3.91
Xtransint.h
Go to the documentation of this file.
00001 /* $XConsortium: Xtransint.h,v 1.21 94/05/10 11:08:46 mor Exp $ */
00002 /*
00003 
00004 Copyright (c) 1993, 1994  X Consortium
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining
00007 a copy of this software and associated documentation files (the
00008 "Software"), to deal in the Software without restriction, including
00009 without limitation the rights to use, copy, modify, merge, publish,
00010 distribute, sublicense, and/or sell copies of the Software, and to
00011 permit persons to whom the Software is furnished to do so, subject to
00012 the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included
00015 in all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00019 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00020 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
00021 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00022 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00023 OTHER DEALINGS IN THE SOFTWARE.
00024 
00025 Except as contained in this notice, the name of the X Consortium shall
00026 not be used in advertising or otherwise to promote the sale, use or
00027 other dealings in this Software without prior written authorization
00028 from the X Consortium.
00029 
00030 */
00031 
00032 /* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
00033  *
00034  * All Rights Reserved
00035  *
00036  * Permission to use, copy, modify, and distribute this software and its
00037  * documentation for any purpose and without fee is hereby granted, provided
00038  * that the above copyright notice appear in all copies and that both that
00039  * copyright notice and this permission notice appear in supporting
00040  * documentation, and that the name NCR not be used in advertising
00041  * or publicity pertaining to distribution of the software without specific,
00042  * written prior permission.  NCR makes no representations about the
00043  * suitability of this software for any purpose.  It is provided "as is"
00044  * without express or implied warranty.
00045  *
00046  * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00047  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
00048  * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00049  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00050  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00051  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00052  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00053  */
00054 
00055 /*
00056  * DEBUG will enable the PRMSG() macros used in the X Transport Interface code.
00057  * Each use of the PRMSG macro has a level associated with it. DEBUG is defined
00058  * to be a level. If the invocation level is =< the value of DEBUG, then the
00059  * message will be printed out to stderr. Recommended levels are:
00060  *
00061  *     DEBUG=1       Error messages
00062  *     DEBUG=2 API Function Tracing
00063  *     DEBUG=3 All Function Tracing
00064  *     DEBUG=4 printing of intermediate values
00065  *     DEBUG=5 really detailed stuff
00066 #define DEBUG 2
00067  */
00068 
00069 #ifndef _XTRANSINT_H_
00070 #define _XTRANSINT_H_
00071 
00072 #ifdef WIN32
00073 #define _WILLWINSOCK_
00074 #endif
00075 
00076 #include "Xtrans.h"
00077 
00078 #ifdef DEBUG
00079 #include <stdio.h>
00080 #endif /* DEBUG */
00081 
00082 #include <errno.h>
00083 #ifdef X_NOT_STDC_ENV
00084 extern int  errno;          /* Internal system error number. */
00085 #endif
00086 
00087 #ifndef WIN32
00088 #include <sys/socket.h>
00089 
00090 /*
00091  * makedepend screws up on #undef OPEN_MAX, so we define a new symbol
00092  */
00093 
00094 #ifndef TRANS_OPEN_MAX
00095 
00096 #ifndef X_NOT_POSIX
00097 #ifdef _POSIX_SOURCE
00098 #include <limits.h>
00099 #else
00100 #define _POSIX_SOURCE
00101 #include <limits.h>
00102 #undef _POSIX_SOURCE
00103 #endif
00104 #endif
00105 #ifndef OPEN_MAX
00106 #ifdef SVR4
00107 #define OPEN_MAX 256
00108 #else
00109 #include <sys/param.h>
00110 #ifndef OPEN_MAX
00111 #ifdef NOFILE
00112 #define OPEN_MAX NOFILE
00113 #else
00114 #define OPEN_MAX NOFILES_MAX
00115 #endif
00116 #endif
00117 #endif
00118 #endif
00119 
00120 #if OPEN_MAX > 256
00121 #define TRANS_OPEN_MAX 256
00122 #else
00123 #define TRANS_OPEN_MAX OPEN_MAX
00124 #endif
00125 
00126 #endif /* TRANS_OPEN_MAX */
00127 
00128 
00129 #define ESET(val) errno = val
00130 #define EGET() errno
00131 
00132 #else /* WIN32 */
00133 
00134 #define ESET(val) WSASetLastError(val)
00135 #define EGET() WSAGetLastError()
00136 
00137 #endif /* WIN32 */
00138 
00139 #ifndef NULL
00140 #define NULL 0
00141 #endif
00142 
00143 #ifdef X11_t
00144 #define X_TCP_PORT   6000
00145 #endif
00146 
00147 struct _XtransConnInfo {
00148     struct _Xtransport     *transptr;
00149     int              index;
00150     char      *priv;
00151     int              flags;
00152     int              fd;
00153     char      *port;
00154     int              family;
00155     char      *addr;
00156     int              addrlen;
00157     char      *peeraddr;
00158     int              peeraddrlen;
00159 };
00160 
00161 #define XTRANS_OPEN_COTS_CLIENT       1
00162 #define XTRANS_OPEN_COTS_SERVER       2
00163 #define XTRANS_OPEN_CLTS_CLIENT       3
00164 #define XTRANS_OPEN_CLTS_SERVER       4
00165 
00166 
00167 typedef struct _Xtransport {
00168     char      *TransName;
00169     int              flags;
00170 
00171 #ifdef TRANS_CLIENT
00172 
00173     XtransConnInfo (*OpenCOTSClient)(
00174 #if NeedNestedPrototypes
00175        struct _Xtransport *,       /* transport */
00176        char *,                     /* protocol */
00177        char *,                     /* host */
00178        char *               /* port */
00179 #endif
00180     );
00181 
00182 #endif /* TRANS_CLIENT */
00183 
00184 #ifdef TRANS_SERVER
00185 
00186     XtransConnInfo (*OpenCOTSServer)(
00187 #if NeedNestedPrototypes
00188        struct _Xtransport *,       /* transport */
00189        char *,                     /* protocol */
00190        char *,                     /* host */
00191        char *               /* port */
00192 #endif
00193     );
00194 
00195 #endif /* TRANS_SERVER */
00196 
00197 #ifdef TRANS_CLIENT
00198 
00199     XtransConnInfo (*OpenCLTSClient)(
00200 #if NeedNestedPrototypes
00201        struct _Xtransport *,       /* transport */
00202        char *,                     /* protocol */
00203        char *,                     /* host */
00204        char *               /* port */
00205 #endif
00206     );
00207 
00208 #endif /* TRANS_CLIENT */
00209 
00210 #ifdef TRANS_SERVER
00211 
00212     XtransConnInfo (*OpenCLTSServer)(
00213 #if NeedNestedPrototypes
00214        struct _Xtransport *,       /* transport */
00215        char *,                     /* protocol */
00216        char *,                     /* host */
00217        char *               /* port */
00218 #endif
00219     );
00220 
00221 #endif /* TRANS_SERVER */
00222 
00223 
00224 #ifdef TRANS_REOPEN
00225 
00226     XtransConnInfo (*ReopenCOTSServer)(
00227 #if NeedNestedPrototypes
00228        struct _Xtransport *,       /* transport */
00229         int,                /* fd */
00230         char *                     /* port */
00231 #endif
00232     );
00233 
00234     XtransConnInfo (*ReopenCLTSServer)(
00235 #if NeedNestedPrototypes
00236        struct _Xtransport *,       /* transport */
00237         int,                /* fd */
00238         char *                     /* port */
00239 #endif
00240     );
00241 
00242 #endif /* TRANS_REOPEN */
00243 
00244 
00245     int       (*SetOption)(
00246 #if NeedNestedPrototypes
00247        XtransConnInfo,             /* connection */
00248        int,                 /* option */
00249        int                  /* arg */
00250 #endif
00251     );
00252 
00253 #ifdef TRANS_SERVER
00254 
00255     int       (*CreateListener)(
00256 #if NeedNestedPrototypes
00257        XtransConnInfo,             /* connection */
00258        char *               /* port */
00259 #endif
00260     );
00261 
00262     int       (*ResetListener)(
00263 #if NeedNestedPrototypes
00264        XtransConnInfo              /* connection */
00265 #endif
00266     );
00267 
00268     XtransConnInfo (*Accept)(
00269 #if NeedNestedPrototypes
00270        XtransConnInfo,             /* connection */
00271         int *               /* status */
00272 #endif
00273     );
00274 
00275 #endif /* TRANS_SERVER */
00276 
00277 #ifdef TRANS_CLIENT
00278 
00279     int       (*Connect)(
00280 #if NeedNestedPrototypes
00281        XtransConnInfo,             /* connection */
00282        char *,                     /* host */
00283        char *               /* port */
00284 #endif
00285     );
00286 
00287 #endif /* TRANS_CLIENT */
00288 
00289     int       (*BytesReadable)(
00290 #if NeedNestedPrototypes
00291        XtransConnInfo,             /* connection */
00292        BytesReadable_t *    /* pend */
00293 #endif
00294     );
00295 
00296     int       (*Read)(
00297 #if NeedNestedPrototypes
00298        XtransConnInfo,             /* connection */
00299        char *,                     /* buf */
00300        int                  /* size */
00301 #endif
00302     );
00303 
00304     int       (*Write)(
00305 #if NeedNestedPrototypes
00306        XtransConnInfo,             /* connection */
00307        char *,                     /* buf */
00308        int                  /* size */
00309 #endif
00310     );
00311 
00312     int       (*Readv)(
00313 #if NeedNestedPrototypes
00314        XtransConnInfo,             /* connection */
00315        struct iovec *,             /* buf */
00316        int                  /* size */
00317 #endif
00318     );
00319 
00320     int       (*Writev)(
00321 #if NeedNestedPrototypes
00322        XtransConnInfo,             /* connection */
00323        struct iovec *,             /* buf */
00324        int                  /* size */
00325 #endif
00326     );
00327 
00328     int       (*Disconnect)(
00329 #if NeedNestedPrototypes
00330        XtransConnInfo              /* connection */
00331 #endif
00332     );
00333 
00334     int       (*Close)(
00335 #if NeedNestedPrototypes
00336        XtransConnInfo              /* connection */
00337 #endif
00338     );
00339 
00340     int       (*CloseForCloning)(
00341 #if NeedNestedPrototypes
00342        XtransConnInfo              /* connection */
00343 #endif
00344     );
00345 
00346 } Xtransport;
00347 
00348 
00349 typedef struct _Xtransport_table {
00350     Xtransport       *transport;
00351     int              transport_id;
00352 } Xtransport_table;
00353 
00354 
00355 /*
00356  * Flags for the flags member of Xtransport.
00357  */
00358 
00359 #define TRANS_ALIAS  (1<<0) /* record is an alias, don't create server */
00360 #define TRANS_LOCAL  (1<<1) /* local transport */
00361 
00362 
00363 /*
00364  * readv() and writev() don't exist or don't work correctly on some
00365  * systems, so they may be emulated.
00366  */
00367 
00368 #if defined(CRAY) || (defined(SYSV) && defined(SYSV386)) || defined(WIN32) || defined(__sxg__) || defined(SCO)
00369 
00370 #define READV(ciptr, iov, iovcnt)  TRANS(ReadV)(ciptr, iov, iovcnt)
00371 
00372 static int TRANS(ReadV)(
00373     XtransConnInfo,  /* ciptr */
00374     struct iovec *,  /* iov */
00375     int                     /* iovcnt */
00376 );
00377 
00378 #else
00379 
00380 #define READV(ciptr, iov, iovcnt)  readv(ciptr->fd, iov, iovcnt)
00381 
00382 #endif /* CRAY || (SYSV && SYSV386) || WIN32 || __sxg__ || SCO */
00383 
00384 
00385 #if defined(CRAY) || defined(WIN32) || defined(__sxg__) || defined(SCO)
00386 
00387 #define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt)
00388 
00389 static int TRANS(WriteV)(
00390     XtransConnInfo,  /* ciptr */
00391     struct iovec *,  /* iov */
00392     int              /* iovcnt */
00393 );
00394 
00395 #else
00396 
00397 #define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt)
00398 
00399 #endif /* CRAY || WIN32 || __sxg__ || SCO */
00400 
00401 
00402 static int is_numeric (
00403     char *           /* str */
00404 );
00405 
00406 
00407 /*
00408  * Some DEBUG stuff
00409  */
00410 
00411 #if defined(DEBUG)
00412 #define PRMSG(lvl,x,a,b,c)  if (lvl <= DEBUG){ \
00413                      int saveerrno=errno; \
00414                      fprintf(stderr, x,a,b,c); fflush(stderr); \
00415                      errno=saveerrno; \
00416                      }
00417 #else
00418 #define PRMSG(lvl,x,a,b,c)
00419 #endif /* DEBUG */
00420 
00421 #endif /* _XTRANSINT_H_ */