comparison lib-src/emacsclient.c @ 79226:8919d6b286e1

(sock_err_message): New function. (set_tcp_socket): Use it.
author Jason Rumney <jasonr@gnu.org>
date Thu, 25 Oct 2007 23:56:34 +0000
parents 5025525d6c9d
children 7970215aa6e5
comparison
equal deleted inserted replaced
79225:bd489b08bec6 79226:8919d6b286e1
392 extern int errno; 392 extern int errno;
393 393
394 /* Buffer to accumulate data to send in TCP connections. */ 394 /* Buffer to accumulate data to send in TCP connections. */
395 char send_buffer[SEND_BUFFER_SIZE + 1]; 395 char send_buffer[SEND_BUFFER_SIZE + 1];
396 int sblen = 0; /* Fill pointer for the send buffer. */ 396 int sblen = 0; /* Fill pointer for the send buffer. */
397
398 /* On Windows, the socket library was historically separate from the standard
399 C library, so errors are handled differently. */
400 void
401 sock_err_message (function_name)
402 char *function_name;
403 {
404 #ifdef WINDOWSNT
405 char* msg = NULL;
406
407 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
408 | FORMAT_MESSAGE_ALLOCATE_BUFFER
409 | FORMAT_MESSAGE_ARGUMENT_ARRAY,
410 NULL, WSAGetLastError (), 0, (LPTSTR)&msg, 0, NULL);
411
412 message (TRUE, "%s: %s: %s\n", progname, function_name, msg);
413
414 LocalFree (msg);
415 #else
416 message (TRUE, "%s: %s: %s\n", progname, function_name, strerror (errno));
417 #endif
418 }
419
397 420
398 /* Let's send the data to Emacs when either 421 /* Let's send the data to Emacs when either
399 - the data ends in "\n", or 422 - the data ends in "\n", or
400 - the buffer is full (but this shouldn't happen) 423 - the buffer is full (but this shouldn't happen)
401 Otherwise, we just accumulate it. */ 424 Otherwise, we just accumulate it. */
644 /* 667 /*
645 * Open up an AF_INET socket 668 * Open up an AF_INET socket
646 */ 669 */
647 if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) 670 if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
648 { 671 {
649 message (TRUE, "%s: socket: %s\n", progname, strerror (errno)); 672 sock_err_message ("socket");
650 return INVALID_SOCKET; 673 return INVALID_SOCKET;
651 } 674 }
652 675
653 /* 676 /*
654 * Set up the socket 677 * Set up the socket
655 */ 678 */
656 if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) 679 if (connect (s, (struct sockaddr *) &server, sizeof server) < 0)
657 { 680 {
658 message (TRUE, "%s: connect: %s\n", progname, strerror (errno)); 681 sock_err_message ("connect");
659 return INVALID_SOCKET; 682 return INVALID_SOCKET;
660 } 683 }
661 684
662 setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg); 685 setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg);
663 686