+\f
+#if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS)
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n",
+ argv[0]);
+ fprintf (stderr, "on systems with Berkeley sockets.\n");
+
+ fail (argc, argv);
+}
+
+#else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
+
+#ifdef WINDOWSNT
+# include <winsock2.h>
+#else
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <sys/un.h>
+# include <sys/stat.h>
+# include <errno.h>
+#endif
+
+#define AUTH_KEY_LENGTH 64
+#define SEND_BUFFER_SIZE 4096
+
+extern char *strerror ();
+extern int errno;
+
+/* Buffer to accumulate data to send in TCP connections. */
+char send_buffer[SEND_BUFFER_SIZE + 1];
+int sblen = 0; /* Fill pointer for the send buffer. */
+
+/* Let's send the data to Emacs when either
+ - the data ends in "\n", or
+ - the buffer is full (but this shouldn't happen)
+ Otherwise, we just accumulate it. */
+void
+send_to_emacs (s, data)
+ HSOCKET s;
+ char *data;
+{
+ while (data)
+ {
+ int dlen = strlen (data);
+ if (dlen + sblen >= SEND_BUFFER_SIZE)
+ {
+ int part = SEND_BUFFER_SIZE - sblen;
+ strncpy (&send_buffer[sblen], data, part);
+ data += part;
+ sblen = SEND_BUFFER_SIZE;
+ }
+ else if (dlen)
+ {
+ strcpy (&send_buffer[sblen], data);
+ data = NULL;
+ sblen += dlen;
+ }
+ else
+ break;
+
+ if (sblen == SEND_BUFFER_SIZE
+ || (sblen > 0 && send_buffer[sblen-1] == '\n'))
+ {
+ int sent = send (s, send_buffer, sblen, 0);
+ if (sent != sblen)
+ strcpy (send_buffer, &send_buffer[sent]);
+ sblen -= sent;
+ }
+ }
+}
+
+/* In NAME, insert a & before each &, each space, each newline, and
+ any initial -. Change spaces to underscores, too, so that the
+ return value never contains a space. */
+void
+quote_file_name (s, name)
+ HSOCKET s;