824N/A * (c) Copyright 1990-1994 Adobe Systems Incorporated. 824N/A * Permission to use, copy, modify, distribute, and sublicense this software 824N/A * and its documentation for any purpose and without fee is hereby granted, 824N/A * provided that the above copyright notices appear in all copies and that 824N/A * both those copyright notices and this permission notice appear in 824N/A * supporting documentation and that the name of Adobe Systems Incorporated 824N/A * not be used in advertising or publicity pertaining to distribution of the 824N/A * software without specific, written prior permission. No trademark license 824N/A * to use the Adobe trademarks is hereby granted. If the Adobe trademark 824N/A * "Display PostScript"(tm) is used to describe this software, its 824N/A * functionality or for any other purpose, such use shall be limited to a 824N/A * statement that this software works in conjunction with the Display 824N/A * PostScript system. Proper trademark attribution to reflect Adobe's 824N/A * ownership of the trademark shall be given whenever any such reference to 824N/A * the Display PostScript system is made. 824N/A * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR 824N/A * ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 824N/A * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 824N/A * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 824N/A * NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE 824N/A * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL 824N/A * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT, 824N/A * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN 824N/A * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT 824N/A * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE. 824N/A * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems 824N/A * Incorporated which may be registered in certain jurisdictions 824N/A * Portions Copyright 1989 Massachusetts Institute of Technology 824N/A * Permission to use, copy, modify, distribute, and sell this software and its 824N/A * documentation for any purpose is hereby granted without fee, provided that 824N/A * the above copyright notice appear in all copies and that both that 824N/A * copyright notice and this permission notice appear in supporting 824N/A * documentation, and that the name of M.I.T. not be used in advertising or 824N/A * publicity pertaining to distribution of the software without specific, 824N/A * written prior permission. M.I.T. makes no representations about the 824N/A * suitability of this software for any purpose. It is provided "as is" 824N/A * without express or implied warranty. 824N/A * Author: Adobe Systems Incorporated and MIT X Consortium 824N/A the definition of NOFILE */ 824N/A/* This global controls the size of the output socket buffer. Zero 824N/A means to use the system default size. */ 824N/A * Attempts to connect to agent, given name. Returns file descriptor 824N/A * (network socket) or -1 if connection fails. Names may be of the 824N/A * [hostname] : [:] agentnumber 824N/A * The second colon indicates a DECnet style name. No hostname is interpretted 824N/A * as the most efficient local connection to a server on the same machine. 824N/A int fd = -
1;
/* file descriptor to return */ 824N/A * Step 1, find the hostname. This is delimited by the required 824N/A if (!*p)
return -
1;
/* must have a colon */ 824N/A * Step 2, see if this is a DECnet address by looking for the optional 824N/A if (p[
1] ==
':') {
/* then DECnet format */ 824N/A * see if we're allowed to have a DECnet address 824N/A * Step 3, find the port number. This field is required. 824N/A * Zero is acceptable as a port number, meaning use the default. 824N/A (*p !=
'\0' && *p !=
'.') ||
/* invalid non-digit terminator */ 824N/A * At this point, we know the following information: 824N/A * phostname hostname string or NULL 824N/A * iagent agent port number 824N/A * We can now decide which transport to use based on the ConnectionFlags 824N/A * build parameter the hostname string. If phostname is NULL or equals 824N/A * the string "local", then choose the best transport. If phostname 824N/A * is "unix", then choose BSD UNIX domain sockets (if configured). 824N/A * First, choose default transports: DECnet else (TCP or STREAMS) 824N/A * Now that the defaults have been established, see if we have any 824N/A * special names that we have to override: 824N/A * :N => if UNIXCONN then unix-domain-socket 824N/A * ::N => if UNIXCONN then unix-domain-socket 824N/A * unix:N => if UNIXCONN then unix-domain-socket 824N/A * Note that if UNIXCONN isn't defined, then we can use the default 824N/A * transport connection function set above. 824N/A * Get the auth info for local hosts so that it doesn't have to be 824N/A * repeated everywhere; the particular values in these fields are 824N/A * not part of the protocol. 824N/A /* Ultrix has a nasty bug in getservbyname(); if the name passed to 824N/A it is not in the services list it seg faults! *sigh* So, we 824N/A don't ever look in the services info for ultrix... */ 824N/A if (
iagent == 0) {
/* find service default, if one's defined */ 824N/A DPSWarnProc(
NULL,
"Services database specifies a protocol other than tcp. Using default port.\n");
824N/A }
else /* extract the port number */ 824N/A * Make the connection, also need to get the auth address info for 824N/A * non-local connections. Do retries in case server host has hit its 824N/A * backlog (which, unfortunately, isn't distinguishable from there not 824N/A * being a server listening at all, which is why we have to not retry 824N/A * Set the connection non-blocking since we use select() to block; also 824N/A * set close-on-exec so that programs that fork() doesn't get confused. 824N/A * Build the expanded display name: 824N/A * [host] : [:] agent \0 824N/A * error return; make sure everything is cleaned up. 824N/A/***************************************************************************** 824N/A * Make Connection Routines * 824N/A *****************************************************************************/ 824N/A#
ifdef apollo /* nest if(n)defs because makedepend is broken */ 824N/A#
endif /* NEED_BSDISH */ 824N/A * build the target object name. 824N/A * Attempt to open the DECnet connection, return -1 if fails; ought to 824N/A * do some retries here.... 824N/A int fd;
/* socket file descriptor */ 824N/A * Open the network connection. 824N/A * Don't need to get auth info since we're local 824N/A char *
cp;
/* character pointer iterator */ 824N/A int fd;
/* file descriptor to return */ 824N/A * if numeric host name then try to parse it as such; do the number 824N/A * first because some systems return garbage instead of INVALID_INETADDR 824N/A /* Not an Internet host! */ 824N/A /* Set up the socket data. */ 824N/A /* Only Cray UNICOS3 and UNICOS4 will define this */ 824N/A#
endif /* CRAY and OLDTCP */ 824N/A /* Only Cray UNICOS3 and UNICOS4 will define this */ 824N/A#
endif /* CRAY and OLDTCP */ 824N/A * Open the network connection. 824N/A * turn off TCP coalescence 824N/A * connect to the socket; if there is no X server or if the backlog has 824N/A * been reached, then ECONNREFUSED will be returned. 824N/A * Success! So, save the auth information 824N/A#
else /* else not CRAY */ 824N/A * We are special casing the BSD hack localhost address 824N/A * 127.0.0.1, since this address shouldn't be copied to 824N/A * other machines. So, we simply omit generating the auth info 824N/A * since we set it to the local machine before calling this routine! 824N/A/***************************************************************************** 824N/A * Connection Utility Routines * 824N/A *****************************************************************************/ 824N/A * Disconnect from server. 824N/A * This is an OS dependent routine which: 824N/A * 1) returns as soon as the connection can be written on.... 824N/A * 2) if the connection can be read, must enqueue events and handle errors, 824N/A * until the connection is writable. 824N/A /* find out how much data can be read */ 824N/A /* must read at least one xEvent; if none is pending, then 824N/A we'll just block waiting for it */ 824N/A /* but we won't read more than the max buffer size */ 824N/A /* round down to an integral number of XReps */ 824N/A /* no space between comma and type or else macro will die */ 824N/A else /* it's an event packet; die */ 824N/Astatic int padlength[
4] = {0,
3,
2,
1};
/* make sure auth is multiple of 4 */ 824N/A * write authorization protocol name and data