1 /* $XConsortium: Xtransint.h /main/25 1995/12/05 16:51:28 mor $ */
2 /* $XFree86: xc/lib/xtrans/Xtransint.h,v 3.18.2.2 1997/07/19 04:59:16 dawes Exp $ */
5 Copyright (c) 1993, 1994 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
33 /* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
37 * Permission to use, copy, modify, and distribute this software and its
38 * documentation for any purpose and without fee is hereby granted, provided
39 * that the above copyright notice appear in all copies and that both that
40 * copyright notice and this permission notice appear in supporting
41 * documentation, and that the name NCR not be used in advertising
42 * or publicity pertaining to distribution of the software without specific,
43 * written prior permission. NCR makes no representations about the
44 * suitability of this software for any purpose. It is provided "as is"
45 * without express or implied warranty.
47 * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
48 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
49 * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
50 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
51 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
52 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
53 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
60 * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport
61 * Interface code. Each use of the PRMSG macro has a level associated with
62 * it. XTRANSDEBUG is defined to be a level. If the invocation level is =<
63 * the value of XTRANSDEBUG, then the message will be printed out to stderr.
64 * Recommended levels are:
66 * XTRANSDEBUG=1 Error messages
67 * XTRANSDEBUG=2 API Function Tracing
68 * XTRANSDEBUG=3 All Function Tracing
69 * XTRANSDEBUG=4 printing of intermediate values
70 * XTRANSDEBUG=5 really detailed stuff
73 * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each
78 # define XTRANSDEBUG 1
91 #endif /* XTRANSDEBUG */
95 extern int errno; /* Internal system error number. */
101 #include <sys/socket.h>
107 #include <sys/ioctl.h>
111 * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c,
112 * to avoid a race condition. JKJ (6/5/97)
114 #if (defined(_POSIX_SOURCE) && !defined(AIXV3)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(SCO)
118 #include <sys/utsname.h>
122 * makedepend screws up on #undef OPEN_MAX, so we define a new symbol
125 #ifndef TRANS_OPEN_MAX
131 #define _POSIX_SOURCE
140 #include <sys/param.h>
146 #define OPEN_MAX NOFILE
149 #define OPEN_MAX NOFILES_MAX
160 #define TRANS_OPEN_MAX 256
162 #define TRANS_OPEN_MAX OPEN_MAX
165 #endif /* TRANS_OPEN_MAX */
170 #define ESET(val) errno = val
176 #define ESET(val) WSASetLastError(val)
177 #define EGET() WSAGetLastError()
186 #define X_TCP_PORT 6000
189 struct _XtransConnInfo {
190 struct _Xtransport *transptr;
203 #define XTRANS_OPEN_COTS_CLIENT 1
204 #define XTRANS_OPEN_COTS_SERVER 2
205 #define XTRANS_OPEN_CLTS_CLIENT 3
206 #define XTRANS_OPEN_CLTS_SERVER 4
209 typedef struct _Xtransport {
215 XtransConnInfo (*OpenCOTSClient)(
216 #if NeedNestedPrototypes
217 struct _Xtransport *, /* transport */
218 char *, /* protocol */
224 #endif /* TRANS_CLIENT */
228 XtransConnInfo (*OpenCOTSServer)(
229 #if NeedNestedPrototypes
230 struct _Xtransport *, /* transport */
231 char *, /* protocol */
237 #endif /* TRANS_SERVER */
241 XtransConnInfo (*OpenCLTSClient)(
242 #if NeedNestedPrototypes
243 struct _Xtransport *, /* transport */
244 char *, /* protocol */
250 #endif /* TRANS_CLIENT */
254 XtransConnInfo (*OpenCLTSServer)(
255 #if NeedNestedPrototypes
256 struct _Xtransport *, /* transport */
257 char *, /* protocol */
263 #endif /* TRANS_SERVER */
268 XtransConnInfo (*ReopenCOTSServer)(
269 #if NeedNestedPrototypes
270 struct _Xtransport *, /* transport */
276 XtransConnInfo (*ReopenCLTSServer)(
277 #if NeedNestedPrototypes
278 struct _Xtransport *, /* transport */
284 #endif /* TRANS_REOPEN */
288 #if NeedNestedPrototypes
289 XtransConnInfo, /* connection */
297 int (*CreateListener)(
298 #if NeedNestedPrototypes
299 XtransConnInfo, /* connection */
304 int (*ResetListener)(
305 #if NeedNestedPrototypes
306 XtransConnInfo /* connection */
310 XtransConnInfo (*Accept)(
311 #if NeedNestedPrototypes
312 XtransConnInfo, /* connection */
317 #endif /* TRANS_SERVER */
322 #if NeedNestedPrototypes
323 XtransConnInfo, /* connection */
329 #endif /* TRANS_CLIENT */
331 int (*BytesReadable)(
332 #if NeedNestedPrototypes
333 XtransConnInfo, /* connection */
334 BytesReadable_t * /* pend */
339 #if NeedNestedPrototypes
340 XtransConnInfo, /* connection */
347 #if NeedNestedPrototypes
348 XtransConnInfo, /* connection */
355 #if NeedNestedPrototypes
356 XtransConnInfo, /* connection */
357 struct iovec *, /* buf */
363 #if NeedNestedPrototypes
364 XtransConnInfo, /* connection */
365 struct iovec *, /* buf */
371 #if NeedNestedPrototypes
372 XtransConnInfo /* connection */
377 #if NeedNestedPrototypes
378 XtransConnInfo /* connection */
382 int (*CloseForCloning)(
383 #if NeedNestedPrototypes
384 XtransConnInfo /* connection */
391 typedef struct _Xtransport_table {
392 Xtransport *transport;
398 * Flags for the flags member of Xtransport.
401 #define TRANS_ALIAS (1<<0) /* record is an alias, don't create server */
402 #define TRANS_LOCAL (1<<1) /* local transport */
403 #define TRANS_DISABLED (1<<2) /* Don't open this one */
404 #define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */
408 * readv() and writev() don't exist or don't work correctly on some
409 * systems, so they may be emulated.
412 #if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__EMX__)
414 #define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt)
416 static int TRANS(ReadV)(
417 #if NeedFunctionPrototypes
418 XtransConnInfo, /* ciptr */
419 struct iovec *, /* iov */
426 #define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt)
428 #endif /* CRAY || (SYSV && i386) || WIN32 || __sxg__ || */
431 #if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__EMX__)
433 #define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt)
435 static int TRANS(WriteV)(
436 #if NeedFunctionPrototypes
437 XtransConnInfo, /* ciptr */
438 struct iovec *, /* iov */
445 #define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt)
447 #endif /* CRAY || WIN32 || __sxg__ */
450 static int is_numeric (
451 #if NeedFunctionPrototypes
458 * Some XTRANSDEBUG stuff
461 #if defined(XTRANSDEBUG)
462 /* add hack to the format string to avoid warnings about extra arguments
465 #ifdef XTRANSDEBUGTIMESTAMP
466 #if defined(XSERV_t) && defined(TRANS_SERVER)
467 /* Use ErrorF() for the X server */
468 #define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
469 int hack= 0, saveerrno=errno; \
471 gettimeofday(&tp,0); \
472 ErrorF(__xtransname); \
473 ErrorF(x+hack,a,b,c); \
474 ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
478 #define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
479 int hack= 0, saveerrno=errno; \
481 gettimeofday(&tp,0); \
482 fprintf(stderr, __xtransname); fflush(stderr); \
483 fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
484 fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
488 #endif /* XSERV_t && TRANS_SERVER */
489 #else /* XTRANSDEBUGTIMESTAMP */
490 #if defined(XSERV_t) && defined(TRANS_SERVER)
491 /* Use ErrorF() for the X server */
492 #define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
493 int hack= 0, saveerrno=errno; \
494 ErrorF(__xtransname); \
495 ErrorF(x+hack,a,b,c); \
499 #define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
500 int hack= 0, saveerrno=errno; \
501 fprintf(stderr, __xtransname); fflush(stderr); \
502 fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
505 #endif /* XSERV_t && TRANS_SERVER */
506 #endif /* XTRANSDEBUGTIMESTAMP */
508 #define PRMSG(lvl,x,a,b,c) ((void)0)
509 #endif /* XTRANSDEBUG */
511 #endif /* _XTRANSINT_H_ */