📄 xconndis.c
字号:
#endif#ifdef ISOCONN if (isoconn) { if ((fd = iso_conn(displaybuf)) < 0) return(-1); else fd2family[fd] = ISODE_IO; } else#endif {#ifdef UNIXCONN if ((displaybuf[0] == '\0') || (strcmp("unix", displaybuf) == 0)) { /* Connect locally using Unix domain. */ unaddr.sun_family = AF_UNIX; (void) strcpy(unaddr.sun_path, X_UNIX_PATH); strcat(unaddr.sun_path, display_ptr); addr = (struct sockaddr *) &unaddr; addrlen = strlen(unaddr.sun_path) + 2; /* * Open the network connection. */ if ((fd = socket((int) addr->sa_family, SOCK_STREAM, 0)) < 0) return(-1); /* errno set by system call. */ } else#endif { /* Get the statistics on the specified host. */ hostinetaddr = inet_addr (displaybuf); if (hostinetaddr == -1) { if ((host_ptr = gethostbyname(displaybuf)) == NULL) { /* No such host! */ errno = EINVAL; return(-1); } /* Check the address type for an internet host. */ if (host_ptr->h_addrtype != AF_INET) { /* Not an Internet host! */ errno = EPROTOTYPE; return(-1); } /* Set up the socket data. */ inaddr.sin_family = host_ptr->h_addrtype;#if defined(CRAY) && defined(OLDTCP) /* Only Cray UNICOS3 and UNICOS4 will define this */ { long t; bcopy((char *)host_ptr->h_addr, (char *)&t, sizeof(inaddr.sin_addr)); inaddr.sin_addr = t; }#else bcopy((char *)host_ptr->h_addr, (char *)&inaddr.sin_addr, sizeof(inaddr.sin_addr));#endif /* CRAY and OLDTCP */ } else {#if defined(CRAY) && defined(OLDTCP) /* Only Cray UNICOS3 and UNICOS4 will define this */ inaddr.sin_addr = hostinetaddr;#else inaddr.sin_addr.s_addr = hostinetaddr;#endif /* CRAY and OLDTCP */ inaddr.sin_family = AF_INET; } addr = (struct sockaddr *) &inaddr; addrlen = sizeof (struct sockaddr_in); inaddr.sin_port = display_num; inaddr.sin_port += X_TCP_PORT; inaddr.sin_port = htons(inaddr.sin_port); /* * Open the network connection. */ if ((fd = socket((int) addr->sa_family, SOCK_STREAM, 0)) < 0) return(-1); /* errno set by system call. */#ifdef ISOCONN fd2family[fd] = UNIX_IO;#endif /* ISOCONN */ /* make sure to turn off TCP coalescence */#ifdef TCP_NODELAY { int mi = 1; setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &mi, sizeof (int)); }#endif } if (connect(fd, addr, addrlen) == -1) { (void) close (fd); return(-1); /* errno set by system call. */ } }#ifdef ISOCONN if (!isoconn) {#endif /* ISOCONN *//* * Not required for ISO T-Service */ /* * set it non-blocking. This is so we can read data when blocked * for writing in the library. */#ifdef FIOSNBIO { int arg = 1; ioctl(fd, FIOSNBIO, &arg); }#else (void) fcntl(fd, F_SETFL, FNDELAY);#endif /* FIOSNBIO */#ifdef ISOCONN }#endif /* ISOCONN */ /* * Return the id if the connection succeeded. Rebuild the expanded * spec and return it in the result parameter. */ display_ptr = displaybuf-1; while (*(++display_ptr) != '\0') ; *(display_ptr++) = ':';#ifdef DNETCONN if (dnet) *(display_ptr++) = ':';#endif#ifdef ISOCONN if (isoconn) { *(display_ptr++) = isochar; }#endif numbuf_ptr = numberbuf; while (*numbuf_ptr != '\0') *(display_ptr++) = *(numbuf_ptr++); if (prop_name[0] != '\0') { char *cp; *(display_ptr++) = '.'; for (cp = prop_name; *cp; cp++) *(display_ptr++) = *cp; } *display_ptr = '\0'; (void) strcpy(expanded_name, displaybuf); return(fd);}/* * Disconnect from server. */int _XDisconnectDisplay (server) int server;{#ifdef ISOCONN (void)CloseToServer(server);#else /* ISOCONN */ (void) close(server);#endif /* ISOCONN */}#undef NULL#define NULL ((char *) 0)/* * This is an OS dependent routine which: * 1) returns as soon as the connection can be written on.... * 2) if the connection can be read, must enqueue events and handle errors, * until the connection is writable. */_XWaitForWritable(dpy) Display *dpy;{ unsigned long r_mask[MSKCNT]; unsigned long w_mask[MSKCNT]; int nfound; CLEARBITS(r_mask); CLEARBITS(w_mask); while (1) { BITSET(r_mask, dpy->fd); BITSET(w_mask, dpy->fd); do {#ifdef ISOCONN/* * Note, we shouldnt get any connections to us as we're a client, * But the elements of style say we should check... * and of course, a TDR */ int vecp; char *vec[4]; struct TSAPdisconnect tds; struct TSAPdisconnect *td = &tds; nfound = TNetAccept(&vecp, vec, dpy->fd + 1, r_mask, w_mask, NULL, NOTOK, td);#ifdef ISODEBUG if (nfound < 0) { int sverrno = errno; fprintf(stderr, "TNetAcc err %d %s\n", errno, TErrString(td->td_reason)); errno = sverrno; }#endif /* ISODEBUG */#ifdef ISODEBUG if (vecp > 0) { fprintf(stderr, "Weirdness, connect to a client?\n"); }#endif#else /* ISOCONN */ nfound = select (dpy->fd + 1, r_mask, w_mask, NULL, NULL);#endif /* ISOCONN */ if (nfound < 0 && errno != EINTR) (*_XIOErrorFunction)(dpy); } while (nfound <= 0); if (ANYSET(r_mask)) { char buf[BUFSIZE]; long pend_not_register; register long pend; register xEvent *ev; /* find out how much data can be read */ if (BytesReadable(dpy->fd, (char *) &pend_not_register) < 0) (*_XIOErrorFunction)(dpy); pend = pend_not_register; /* must read at least one xEvent; if none is pending, then we'll just block waiting for it */ if (pend < SIZEOF(xEvent)) pend = SIZEOF(xEvent); /* but we won't read more than the max buffer size */ if (pend > BUFSIZE) pend = BUFSIZE; /* round down to an integral number of XReps */ pend = (pend / SIZEOF(xEvent)) * SIZEOF(xEvent); _XRead (dpy, buf, pend); /* no space between comma and type or else macro will die */ STARTITERATE (ev,xEvent, buf, (pend > 0), (pend -= SIZEOF(xEvent))) { if (ev->u.u.type == X_Error) _XError (dpy, (xError *) ev); else /* it's an event packet; enqueue it */ _XEnq (dpy, ev); } ENDITERATE } if (ANYSET(w_mask)) return; }}_XWaitForReadable(dpy) Display *dpy;{ unsigned long r_mask[MSKCNT]; int result; CLEARBITS(r_mask); do {#ifdef ISOCONN/* * Note, we shouldnt get any connections to us as we're a client, * But the elements of style say we should check... * and of course, a TDR */ int vecp; char *vec[4]; struct TSAPdisconnect tds; struct TSAPdisconnect *td = &tds; BITSET(r_mask, dpy->fd); result = TNetAccept(&vecp, vec, dpy->fd + 1, r_mask, NULL, NULL, NOTOK, td);#else /* ISOCONN */ BITSET(r_mask, dpy->fd); result = select(dpy->fd + 1, r_mask, NULL, NULL, NULL);#endif /* ISOCONN */ if (result == -1 && errno != EINTR) (*_XIOErrorFunction)(dpy); } while (result <= 0);}static int padlength[4] = {0, 3, 2, 1};_XSendClientPrefix (dpy, client) Display *dpy; xConnClientPrefix *client;{ /* * Authorization string stuff.... Must always transmit multiple of 4 * bytes. */ char *auth_proto = ""; int auth_length; char *auth_string = ""; int auth_strlen; char pad[3]; char buffer[BUFSIZ], *bptr; int bytes=0; auth_length = strlen(auth_proto); auth_strlen = strlen(auth_string); client->nbytesAuthProto = auth_length; client->nbytesAuthString = auth_strlen; bytes = (SIZEOF(xConnClientPrefix) + auth_length + padlength[auth_length & 3] + auth_strlen + padlength[auth_strlen & 3]); bcopy(client, buffer, SIZEOF(xConnClientPrefix)); bptr = buffer + SIZEOF(xConnClientPrefix); if (auth_length) { bcopy(auth_proto, bptr, auth_length); bptr += auth_length; if (padlength[auth_length & 3]) { bcopy(pad, bptr, padlength[auth_length & 3]); bptr += padlength[auth_length & 3]; } } if (auth_strlen) { bcopy(auth_string, bptr, auth_strlen); bptr += auth_strlen; if (padlength[auth_strlen & 3]) { bcopy(pad, bptr, padlength[auth_strlen & 3]); bptr += padlength[auth_strlen & 3]; } } (void) WriteToServer(dpy->fd, buffer, bytes); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -