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