]> git.eshelyaron.com Git - emacs.git/commitdiff
(sock_err_message): New function.
authorJason Rumney <jasonr@gnu.org>
Thu, 25 Oct 2007 23:56:53 +0000 (23:56 +0000)
committerJason Rumney <jasonr@gnu.org>
Thu, 25 Oct 2007 23:56:53 +0000 (23:56 +0000)
(set_tcp_socket): Use it.

lib-src/ChangeLog
lib-src/emacsclient.c

index a09ba2c078c872e9c9421b444c8a9c1ec053c95b..c9599fee81df959f4c2c0e2e942d4f9be388b054 100644 (file)
@@ -1,3 +1,8 @@
+2007-10-25  Jason Rumney  <jasonr@gnu.org>
+
+       * emacsclient.c (sock_err_message): New function.
+       (set_tcp_socket): Use it.
+
 2007-09-27  Jason Rumney  <jasonr@gnu.org>
 
        * makefile.w32-in (emacsclient, emacsclientw): Link to COMCTL32.
index c7f0bcf561326af9cebb7ca8ca2855b34931a11d..adc580e47686bfd8c17cbeb6465e23c74c2b6315 100644 (file)
@@ -395,6 +395,29 @@ extern int errno;
 char send_buffer[SEND_BUFFER_SIZE + 1];
 int sblen = 0; /* Fill pointer for the send buffer.  */
 
+/* On Windows, the socket library was historically separate from the standard
+   C library, so errors are handled differently.  */
+void
+sock_err_message (function_name)
+     char *function_name;
+{
+#ifdef WINDOWSNT
+  char* msg = NULL;
+
+  FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+                 | FORMAT_MESSAGE_ALLOCATE_BUFFER
+                 | FORMAT_MESSAGE_ARGUMENT_ARRAY,
+                 NULL, WSAGetLastError (), 0, (LPTSTR)&msg, 0, NULL);
+
+  message (TRUE, "%s: %s: %s\n", progname, function_name, msg);
+
+  LocalFree (msg);
+#else
+  message (TRUE, "%s: %s: %s\n", progname, function_name, strerror (errno));
+#endif
+}
+
+
 /* Let's send the data to Emacs when either
    - the data ends in "\n", or
    - the buffer is full (but this shouldn't happen)
@@ -646,7 +669,7 @@ set_tcp_socket ()
    */
   if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
     {
-      message (TRUE, "%s: socket: %s\n", progname, strerror (errno));
+      sock_err_message ("socket");
       return INVALID_SOCKET;
     }
 
@@ -655,7 +678,7 @@ set_tcp_socket ()
    */
   if (connect (s, (struct sockaddr *) &server, sizeof server) < 0)
     {
-      message (TRUE, "%s: connect: %s\n", progname, strerror (errno));
+      sock_err_message ("connect");
       return INVALID_SOCKET;
     }