/[cmucl]/src/lisp/socket.c
ViewVC logotype

Contents of /src/lisp/socket.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Tue Aug 21 18:58:21 2007 UTC (6 years, 8 months ago) by fgilham
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +1 -1 lines
File MIME type: text/plain
FILE REMOVED
Delete unnecessary socket.c file.
1 /*
2
3 $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/Attic/socket.c,v 1.7 2007/08/21 18:58:21 fgilham dead $
4
5 This code was written as part of the CMU Common Lisp project at
6 Carnegie Mellon University, and has been placed in the public domain.
7
8 */
9
10 /* Copyright Massachusetts Institute of Technology 1988 */
11 /*
12 * THIS IS AN OS DEPENDENT FILE! It should work on 4.2BSD derived
13 * systems. VMS and System V should plan to have their own version.
14 *
15 * This code was cribbed from lib/X/XConnDis.c.
16 * Compile using
17 * % cc -c socket.c -DUNIXCONN
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <X11/Xos.h>
23 #include <X11/Xproto.h>
24 #include <errno.h>
25 #include <netinet/in.h>
26 #include <sys/ioctl.h>
27 #include <netdb.h>
28 #include <sys/socket.h>
29 #include <arpa/inet.h>
30 #ifndef hpux
31 #include <netinet/tcp.h>
32 #endif
33
34 #include "os.h"
35
36 #ifdef UNIXCONN
37 #include <sys/un.h>
38 #ifndef X_UNIX_PATH
39 #ifdef hpux
40 #define X_UNIX_PATH "/usr/spool/sockets/X11/"
41 #define OLD_UNIX_PATH "/tmp/.X11-unix/X"
42 #else /* hpux */
43 #define X_UNIX_PATH "/tmp/.X11-unix/X"
44 #endif /* hpux */
45 #endif /* X_UNIX_PATH */
46 #endif /* UNIXCONN */
47
48 /*
49 * Attempts to connect to server, given host and display. Returns file
50 * descriptor (network socket) or 0 if connection fails.
51 */
52
53 int
54 connect_to_server(char *host, int display)
55 {
56 struct sockaddr_in inaddr; /* INET socket address. */
57 struct sockaddr *addr; /* address to connect to */
58 struct hostent *host_ptr;
59 int addrlen; /* length of address */
60
61 #ifdef UNIXCONN
62 struct sockaddr_un unaddr; /* UNIX socket address. */
63 #endif
64 int fd; /* Network socket */
65
66 {
67 #ifdef UNIXCONN
68 if ((host[0] == '\0') || (strcmp("unix", host) == 0)) {
69 /* Connect locally using Unix domain. */
70 unaddr.sun_family = AF_UNIX;
71 (void) strcpy(unaddr.sun_path, X_UNIX_PATH);
72 sprintf(&unaddr.sun_path[strlen(unaddr.sun_path)], "%d", display);
73 addr = (struct sockaddr *) &unaddr;
74 addrlen = strlen(unaddr.sun_path) + 2;
75 /*
76 * Open the network connection.
77 */
78 if ((fd = socket((int) addr->sa_family, SOCK_STREAM, 0)) < 0) {
79 #ifdef hpux /* this is disgusting */ /* cribbed from X11R4 xlib source */
80 if (errno == ENOENT) { /* No such file or directory */
81 sprintf(unaddr.sun_path, "%s%d", OLD_UNIX_PATH, display);
82 addrlen = strlen(unaddr.sun_path) + 2;
83 if ((fd = socket((int) addr->sa_family, SOCK_STREAM, 0)) <
84 0) return (-1); /* errno set by most recent system call. */
85 } else
86 #endif /* hpux */
87 return (-1); /* errno set by system call. */
88 }
89 } else
90 #endif /* UNIXCONN */
91 {
92 /* Get the statistics on the specified host. */
93 if ((inaddr.sin_addr.s_addr = inet_addr(host)) == -1) {
94 if ((host_ptr = gethostbyname(host)) == NULL) {
95 /* No such host! */
96 errno = EINVAL;
97 return (-1);
98 }
99 /* Check the address type for an internet host. */
100 if (host_ptr->h_addrtype != AF_INET) {
101 /* Not an Internet host! */
102 errno = EPROTOTYPE;
103 return (-1);
104 }
105 /* Set up the socket data. */
106 inaddr.sin_family = host_ptr->h_addrtype;
107 memcpy((char *) &inaddr.sin_addr,
108 (char *) host_ptr->h_addr, sizeof(inaddr.sin_addr));
109 } else {
110 inaddr.sin_family = AF_INET;
111 }
112 addr = (struct sockaddr *) &inaddr;
113 addrlen = sizeof(struct sockaddr_in);
114
115 inaddr.sin_port = display + X_TCP_PORT;
116 inaddr.sin_port = htons(inaddr.sin_port);
117 /*
118 * Open the network connection.
119 */
120 if ((fd = socket((int) addr->sa_family, SOCK_STREAM, 0)) < 0) {
121 return (-1); /* errno set by system call. */
122 }
123 /* make sure to turn off TCP coalescence */
124 #ifdef TCP_NODELAY
125 {
126 int mi = 1;
127 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &mi, sizeof(int));
128 }
129 #endif
130 }
131
132 /*
133 * Changed 9/89 to retry connection if system call was interrupted. This
134 * is necessary for multiprocessing implementations that use timers,
135 * since the timer results in a SIGALRM. -- jdi
136 */
137 while (connect(fd, addr, addrlen) == -1) {
138 if (errno != EINTR) {
139 (void) close(fd);
140 return (-1); /* errno set by system call. */
141 }
142 }
143 }
144 /*
145 * Return the id if the connection succeeded.
146 */
147 return (fd);
148 }

  ViewVC Help
Powered by ViewVC 1.1.5