comparison lib-src/emacsclient.c @ 73617:7af864af10b6

[WINDOWSNT]: Define HAVE_INET_SOCKETS. [!WINDOWSNT]: Include <netinet/in.h> if available. [HAVE_SOCKETS]: Also require HAVE_INET_SOCKETS. (IOCTL, IOCTL_BOOL_ARG): Remove. (set_tcp_socket): Don't set the socket in blocking mode. Remove c_arg.
author Juanma Barranquero <lekktu@gmail.com>
date Thu, 02 Nov 2006 09:54:09 +0000
parents e243e9889b8b
children 4b7e3d203c5c
comparison
equal deleted inserted replaced
73616:a81e38c24e22 73617:7af864af10b6
30 30
31 # include <malloc.h> 31 # include <malloc.h>
32 # include <stdlib.h> 32 # include <stdlib.h>
33 33
34 # define HAVE_SOCKETS 34 # define HAVE_SOCKETS
35 # define HAVE_INET_SOCKETS
35 # define NO_SOCKETS_IN_FILE_SYSTEM 36 # define NO_SOCKETS_IN_FILE_SYSTEM
36 37
37 # define HSOCKET SOCKET 38 # define HSOCKET SOCKET
38 # define CLOSE_SOCKET closesocket 39 # define CLOSE_SOCKET closesocket
39 # define IOCTL ioctlsocket
40 # define INITIALIZE() (initialize_sockets ()) 40 # define INITIALIZE() (initialize_sockets ())
41 typedef unsigned long IOCTL_BOOL_ARG;
42 41
43 #else /* !WINDOWSNT */ 42 #else /* !WINDOWSNT */
44 43
45 #ifdef HAVE_FCNTL_H 44 # ifdef HAVE_INET_SOCKETS
46 # include <fcntl.h> 45 # include <netinet/in.h>
47 #endif 46 # endif
48 # include <netinet/in.h>
49 # include <sys/ioctl.h>
50 47
51 # define INVALID_SOCKET -1 48 # define INVALID_SOCKET -1
52 # define HSOCKET int 49 # define HSOCKET int
53 # define CLOSE_SOCKET close 50 # define CLOSE_SOCKET close
54 # define IOCTL ioctl
55 # define INITIALIZE() 51 # define INITIALIZE()
56 typedef int IOCTL_BOOL_ARG;
57 52
58 #endif /* !WINDOWSNT */ 53 #endif /* !WINDOWSNT */
59 54
60 #undef signal 55 #undef signal
61 56
269 } 264 }
270 exit (EXIT_FAILURE); 265 exit (EXIT_FAILURE);
271 } 266 }
272 267
273 268
274 #if !defined (HAVE_SOCKETS) 269 #if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS)
275 270
276 int 271 int
277 main (argc, argv) 272 main (argc, argv)
278 int argc; 273 int argc;
279 char **argv; 274 char **argv;
283 fprintf (stderr, "on systems with Berkeley sockets.\n"); 278 fprintf (stderr, "on systems with Berkeley sockets.\n");
284 279
285 fail (argc, argv); 280 fail (argc, argv);
286 } 281 }
287 282
288 #else /* HAVE_SOCKETS */ 283 #else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
289 284
290 #ifdef WINDOWSNT 285 #ifdef WINDOWSNT
291 # include <winsock2.h> 286 # include <winsock2.h>
292 #else 287 #else
293 # include <sys/types.h> 288 # include <sys/types.h>
467 HSOCKET 462 HSOCKET
468 set_tcp_socket () 463 set_tcp_socket ()
469 { 464 {
470 HSOCKET s; 465 HSOCKET s;
471 struct sockaddr_in server; 466 struct sockaddr_in server;
472 IOCTL_BOOL_ARG c_arg = 0;
473 struct linger l_arg = {1, 1}; 467 struct linger l_arg = {1, 1};
474 char auth_string[AUTH_KEY_LENGTH + 1]; 468 char auth_string[AUTH_KEY_LENGTH + 1];
475 469
476 INITIALIZE (); 470 INITIALIZE ();
477 471
496 fprintf (stderr, "%s: ", progname); 490 fprintf (stderr, "%s: ", progname);
497 perror ("connect"); 491 perror ("connect");
498 return INVALID_SOCKET; 492 return INVALID_SOCKET;
499 } 493 }
500 494
501 #ifdef O_NONBLOCK
502 IOCTL (s, O_NONBLOCK, &c_arg);
503 #else
504 #ifdef O_NDELAY
505 IOCTL (s, O_NDELAY, &c_arg);
506 #else
507 IOCTL (s, FIONBIO, &c_arg);
508 #endif
509 #endif
510 setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg); 495 setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg);
511 496
512 /* 497 /*
513 * Send the authentication 498 * Send the authentication
514 */ 499 */
816 801
817 CLOSE_SOCKET (s); 802 CLOSE_SOCKET (s);
818 return EXIT_SUCCESS; 803 return EXIT_SUCCESS;
819 } 804 }
820 805
821 #endif /* HAVE_SOCKETS */ 806 #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
822 807
823 #ifndef HAVE_STRERROR 808 #ifndef HAVE_STRERROR
824 char * 809 char *
825 strerror (errnum) 810 strerror (errnum)
826 int errnum; 811 int errnum;