summaryrefslogtreecommitdiff
path: root/lib-src
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1996-07-23 14:18:34 +0000
committerRichard M. Stallman <rms@gnu.org>1996-07-23 14:18:34 +0000
commit23a7488deacd523f4f676b79a5407467f1283a8c (patch)
treeeb1a1a3b25a0cb2a58b1207f68b3077b90c6f790 /lib-src
parent236ebf3525b654326eb6afd21363fa8e3263b06e (diff)
downloademacs-23a7488deacd523f4f676b79a5407467f1283a8c.tar.gz
(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.c29
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)
{
char system_name[32];
int s, i;
- FILE *out;
+ FILE *out, *in;
struct sockaddr_un server;
char *homedir, *cwd, *str;
char string[BUFSIZ];
@@ -132,6 +132,8 @@ main (argc, argv)
perror ("connect");
exit (1);
}
+
+ /* We use the stream OUT to send our command to the server. */
if ((out = fdopen (s, "r+")) == NULL)
{
fprintf (stderr, "%s: ", argv[0]);
@@ -139,6 +141,18 @@ main (argc, argv)
exit (1);
}
+ /* We use the stream IN to read the response.
+ We used to use just one stream for both output and input
+ on the socket, but reversing direction works nonportably:
+ on some systems, the output appears as the first input;
+ on other systems it does not. */
+ if ((in = fdopen (s, "r+")) == NULL)
+ {
+ fprintf (stderr, "%s: ", argv[0]);
+ perror ("fdopen");
+ exit (1);
+ }
+
#ifdef BSD
cwd = getwd (string);
#else
@@ -170,15 +184,14 @@ main (argc, argv)
printf ("Waiting for Emacs...");
fflush (stdout);
- rewind (out); /* re-read the output */
- str = fgets (string, BUFSIZ, out);
- printf ("\n");
-
- /* Now, wait for an answer and print any messages. */
+ /* Now, wait for an answer and print any messages. On some systems,
+ the first line we read will actually be the output we just sent.
+ We can't predict whether that will happen, so if it does, we
+ detect it by recognizing `Client: ' at the beginning. */
- while (str = fgets (string, BUFSIZ, out))
+ while (str = fgets (string, BUFSIZ, in))
printf ("%s", str);
-
+
return 0;
}