diff options
| author | Richard M. Stallman | 1996-07-23 14:18:34 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-07-23 14:18:34 +0000 |
| commit | 23a7488deacd523f4f676b79a5407467f1283a8c (patch) | |
| tree | eb1a1a3b25a0cb2a58b1207f68b3077b90c6f790 /lib-src | |
| parent | 236ebf3525b654326eb6afd21363fa8e3263b06e (diff) | |
| download | emacs-23a7488deacd523f4f676b79a5407467f1283a8c.tar.gz emacs-23a7488deacd523f4f676b79a5407467f1283a8c.zip | |
(main) [HAVE_SOCKETS]: Use two separate stdio
streams, one for sending and one for reading the reply.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsclient.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index b3dac792390..d1fb4df2ac7 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -63,7 +63,7 @@ main (argc, argv) | |||
| 63 | { | 63 | { |
| 64 | char system_name[32]; | 64 | char system_name[32]; |
| 65 | int s, i; | 65 | int s, i; |
| 66 | FILE *out; | 66 | FILE *out, *in; |
| 67 | struct sockaddr_un server; | 67 | struct sockaddr_un server; |
| 68 | char *homedir, *cwd, *str; | 68 | char *homedir, *cwd, *str; |
| 69 | char string[BUFSIZ]; | 69 | char string[BUFSIZ]; |
| @@ -132,6 +132,8 @@ main (argc, argv) | |||
| 132 | perror ("connect"); | 132 | perror ("connect"); |
| 133 | exit (1); | 133 | exit (1); |
| 134 | } | 134 | } |
| 135 | |||
| 136 | /* We use the stream OUT to send our command to the server. */ | ||
| 135 | if ((out = fdopen (s, "r+")) == NULL) | 137 | if ((out = fdopen (s, "r+")) == NULL) |
| 136 | { | 138 | { |
| 137 | fprintf (stderr, "%s: ", argv[0]); | 139 | fprintf (stderr, "%s: ", argv[0]); |
| @@ -139,6 +141,18 @@ main (argc, argv) | |||
| 139 | exit (1); | 141 | exit (1); |
| 140 | } | 142 | } |
| 141 | 143 | ||
| 144 | /* We use the stream IN to read the response. | ||
| 145 | We used to use just one stream for both output and input | ||
| 146 | on the socket, but reversing direction works nonportably: | ||
| 147 | on some systems, the output appears as the first input; | ||
| 148 | on other systems it does not. */ | ||
| 149 | if ((in = fdopen (s, "r+")) == NULL) | ||
| 150 | { | ||
| 151 | fprintf (stderr, "%s: ", argv[0]); | ||
| 152 | perror ("fdopen"); | ||
| 153 | exit (1); | ||
| 154 | } | ||
| 155 | |||
| 142 | #ifdef BSD | 156 | #ifdef BSD |
| 143 | cwd = getwd (string); | 157 | cwd = getwd (string); |
| 144 | #else | 158 | #else |
| @@ -170,15 +184,14 @@ main (argc, argv) | |||
| 170 | printf ("Waiting for Emacs..."); | 184 | printf ("Waiting for Emacs..."); |
| 171 | fflush (stdout); | 185 | fflush (stdout); |
| 172 | 186 | ||
| 173 | rewind (out); /* re-read the output */ | 187 | /* Now, wait for an answer and print any messages. On some systems, |
| 174 | str = fgets (string, BUFSIZ, out); | 188 | the first line we read will actually be the output we just sent. |
| 175 | printf ("\n"); | 189 | We can't predict whether that will happen, so if it does, we |
| 176 | 190 | detect it by recognizing `Client: ' at the beginning. */ | |
| 177 | /* Now, wait for an answer and print any messages. */ | ||
| 178 | 191 | ||
| 179 | while (str = fgets (string, BUFSIZ, out)) | 192 | while (str = fgets (string, BUFSIZ, in)) |
| 180 | printf ("%s", str); | 193 | printf ("%s", str); |
| 181 | 194 | ||
| 182 | return 0; | 195 | return 0; |
| 183 | } | 196 | } |
| 184 | 197 | ||