Mercurial > emacs
comparison lib-src/emacsserver.c @ 8811:7cd89ebbe641
(FD_*) [HAVE_SOCKETS & !HAVE_SYSVIPC]: If not already defined, use simple
32-bit versions of these macros.
(main) [HAVE_SOCKETS & !HAVE_SYSVIPC]: Use these macros.
| author | Karl Heuer <kwzh@gnu.org> |
|---|---|
| date | Sat, 17 Sep 1994 00:02:50 +0000 |
| parents | ffbf38ae06d1 |
| children | 5d8165cdb0d8 |
comparison
equal
deleted
inserted
replaced
| 8810:6ca3e0d3b7ca | 8811:7cd89ebbe641 |
|---|---|
| 55 #include <sys/un.h> | 55 #include <sys/un.h> |
| 56 #include <stdio.h> | 56 #include <stdio.h> |
| 57 #include <errno.h> | 57 #include <errno.h> |
| 58 | 58 |
| 59 extern int errno; | 59 extern int errno; |
| 60 | |
| 61 /* Copied from src/process.c */ | |
| 62 #ifdef FD_SET | |
| 63 /* We could get this from param.h, but better not to depend on finding that. | |
| 64 And better not to risk that it might define other symbols used in this | |
| 65 file. */ | |
| 66 #ifdef FD_SETSIZE | |
| 67 #define MAXDESC FD_SETSIZE | |
| 68 #else | |
| 69 #define MAXDESC 64 | |
| 70 #endif | |
| 71 #define SELECT_TYPE fd_set | |
| 72 #else /* no FD_SET */ | |
| 73 #define MAXDESC 32 | |
| 74 #define SELECT_TYPE int | |
| 75 | |
| 76 /* Define the macros to access a single-int bitmap of descriptors. */ | |
| 77 #define FD_SET(n, p) (*(p) |= (1 << (n))) | |
| 78 #define FD_CLR(n, p) (*(p) &= ~(1 << (n))) | |
| 79 #define FD_ISSET(n, p) (*(p) & (1 << (n))) | |
| 80 #define FD_ZERO(p) (*(p) = 0) | |
| 81 #endif /* no FD_SET */ | |
| 60 | 82 |
| 61 main () | 83 main () |
| 62 { | 84 { |
| 63 char system_name[32]; | 85 char system_name[32]; |
| 64 int s, infd, fromlen; | 86 int s, infd, fromlen; |
| 127 | 149 |
| 128 /* Disable sigpipes in case luser kills client... */ | 150 /* Disable sigpipes in case luser kills client... */ |
| 129 signal (SIGPIPE, SIG_IGN); | 151 signal (SIGPIPE, SIG_IGN); |
| 130 for (;;) | 152 for (;;) |
| 131 { | 153 { |
| 132 int rmask = (1 << s) + 1; | 154 SELECT_TYPE rmask; |
| 133 if (select (s + 1, (fd_set *)&rmask, 0, 0, 0) < 0) | 155 FD_ZERO (rmask); |
| 156 FD_SET (rmask, 0); | |
| 157 FD_SET (rmask, s); | |
| 158 if (select (s + 1, &rmask, 0, 0, 0) < 0) | |
| 134 perror ("select"); | 159 perror ("select"); |
| 135 if (rmask & (1 << s)) /* client sends list of filenames */ | 160 if (FD_ISSET (rmask, s)) /* client sends list of filenames */ |
| 136 { | 161 { |
| 137 fromlen = sizeof (fromunix); | 162 fromlen = sizeof (fromunix); |
| 138 fromunix.sun_family = AF_UNIX; | 163 fromunix.sun_family = AF_UNIX; |
| 139 infd = accept (s, (struct sockaddr *) &fromunix, | 164 infd = accept (s, (struct sockaddr *) &fromunix, &fromlen); |
| 140 (size_t *) &fromlen); | |
| 141 if (infd < 0) | 165 if (infd < 0) |
| 142 { | 166 { |
| 143 if (errno == EMFILE || errno == ENFILE) | 167 if (errno == EMFILE || errno == ENFILE) |
| 144 printf ("Too many clients.\n"); | 168 printf ("Too many clients.\n"); |
| 145 else | 169 else |
| 184 } | 208 } |
| 185 fflush (stdout); | 209 fflush (stdout); |
| 186 fflush (infile); | 210 fflush (infile); |
| 187 continue; | 211 continue; |
| 188 } | 212 } |
| 189 else if (rmask & 1) /* emacs sends codeword, fd, and string message */ | 213 else if (FD_ISSET (rmask, 0)) /* emacs sends codeword, fd, and string message */ |
| 190 { | 214 { |
| 191 /* Read command codeword and fd */ | 215 /* Read command codeword and fd */ |
| 192 clearerr (stdin); | 216 clearerr (stdin); |
| 193 scanf ("%s %d%*c", code, &infd); | 217 scanf ("%s %d%*c", code, &infd); |
| 194 if (ferror (stdin) || feof (stdin)) | 218 if (ferror (stdin) || feof (stdin)) |
