sclose() function-like macro definition used to close a socket,


			
			
				pull/1/head
			
			
		
Yang Tse 16 years ago
parent 0757cbf7f4
commit f34c2a879b
  1. 4
      ares__close_sockets.c
  2. 7
      ares_private.h
  3. 14
      ares_process.c
  4. 2
      config.dos
  5. 13
      setup_once.h

@ -54,14 +54,14 @@ void ares__close_sockets(ares_channel channel, struct server_state *server)
if (server->tcp_socket != ARES_SOCKET_BAD) if (server->tcp_socket != ARES_SOCKET_BAD)
{ {
SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0); SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0);
closesocket(server->tcp_socket); sclose(server->tcp_socket);
server->tcp_socket = ARES_SOCKET_BAD; server->tcp_socket = ARES_SOCKET_BAD;
server->tcp_connection_generation = ++channel->tcp_connection_generation; server->tcp_connection_generation = ++channel->tcp_connection_generation;
} }
if (server->udp_socket != ARES_SOCKET_BAD) if (server->udp_socket != ARES_SOCKET_BAD)
{ {
SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0); SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0);
closesocket(server->udp_socket); sclose(server->udp_socket);
server->udp_socket = ARES_SOCKET_BAD; server->udp_socket = ARES_SOCKET_BAD;
} }
} }

@ -4,7 +4,7 @@
/* $Id$ */ /* $Id$ */
/* Copyright 1998 by the Massachusetts Institute of Technology. /* Copyright 1998 by the Massachusetts Institute of Technology.
* Copyright (C) 2004-2008 by Daniel Stenberg * Copyright (C) 2004-2009 by Daniel Stenberg
* *
* Permission to use, copy, modify, and distribute this * Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without * software and its documentation for any purpose and without
@ -32,16 +32,11 @@
#if !defined(WIN32) || defined(WATT32) #if !defined(WIN32) || defined(WATT32)
#include <netinet/in.h> #include <netinet/in.h>
/* We define closesocket() here so that we can use this function all over
the source code for closing sockets. */
#define closesocket(x) close(x)
#endif #endif
#ifdef WATT32 #ifdef WATT32
#include <tcp.h> #include <tcp.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#undef closesocket
#define closesocket(s) close_s(s)
#define writev(s,v,c) writev_s(s,v,c) #define writev(s,v,c) writev_s(s,v,c)
#define HAVE_WRITEV 1 #define HAVE_WRITEV 1
#endif #endif

@ -896,7 +896,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
/* Configure it. */ /* Configure it. */
if (configure_socket(s, channel) < 0) if (configure_socket(s, channel) < 0)
{ {
closesocket(s); sclose(s);
return -1; return -1;
} }
@ -911,7 +911,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
(void *)&opt, sizeof(opt)) == -1) (void *)&opt, sizeof(opt)) == -1)
{ {
closesocket(s); sclose(s);
return -1; return -1;
} }
#endif #endif
@ -927,7 +927,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
if (err != EINPROGRESS && err != EWOULDBLOCK) if (err != EINPROGRESS && err != EWOULDBLOCK)
{ {
closesocket(s); sclose(s);
return -1; return -1;
} }
} }
@ -938,7 +938,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
channel->sock_create_cb_data); channel->sock_create_cb_data);
if (err < 0) if (err < 0)
{ {
closesocket(s); sclose(s);
return err; return err;
} }
} }
@ -963,7 +963,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
/* Set the socket non-blocking. */ /* Set the socket non-blocking. */
if (configure_socket(s, channel) < 0) if (configure_socket(s, channel) < 0)
{ {
closesocket(s); sclose(s);
return -1; return -1;
} }
@ -978,7 +978,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
if (err != EINPROGRESS && err != EWOULDBLOCK) if (err != EINPROGRESS && err != EWOULDBLOCK)
{ {
closesocket(s); sclose(s);
return -1; return -1;
} }
} }
@ -989,7 +989,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
channel->sock_create_cb_data); channel->sock_create_cb_data);
if (err < 0) if (err < 0)
{ {
closesocket(s); sclose(s);
return err; return err;
} }
} }

@ -154,6 +154,7 @@
#define HAVE_AF_INET6 1 #define HAVE_AF_INET6 1
#define HAVE_ARPA_INET_H 1 #define HAVE_ARPA_INET_H 1
#define HAVE_ARPA_NAMESER_H 1 #define HAVE_ARPA_NAMESER_H 1
#define HAVE_CLOSESOCKET_CAMEL 1
#define HAVE_GETHOSTNAME 1 #define HAVE_GETHOSTNAME 1
#define HAVE_NETDB_H 1 #define HAVE_NETDB_H 1
#define HAVE_NETINET_IN_H 1 #define HAVE_NETINET_IN_H 1
@ -167,6 +168,7 @@
#define HAVE_SYS_UIO_H 1 #define HAVE_SYS_UIO_H 1
#define NS_INADDRSZ 4 #define NS_INADDRSZ 4
#define HAVE_STRUCT_SOCKADDR_IN6 1 #define HAVE_STRUCT_SOCKADDR_IN6 1
#define CloseSocket(s) close_s((s))
#endif #endif
#undef word #undef word

@ -222,6 +222,19 @@ struct timeval {
#endif /* if 0 */ #endif /* if 0 */
/*
* Function-like macro definition used to close a socket.
*/
#if defined(HAVE_CLOSESOCKET)
# define sclose(x) closesocket((x))
#elif defined(HAVE_CLOSESOCKET_CAMEL)
# define sclose(x) CloseSocket((x))
#else
# define sclose(x) close((x))
#endif
/* /*
* Uppercase macro versions of ANSI/ISO is*() functions/macros which * Uppercase macro versions of ANSI/ISO is*() functions/macros which
* avoid negative number inputs with argument byte codes > 127. * avoid negative number inputs with argument byte codes > 127.

Loading…
Cancel
Save