Skip to content
Snippets Groups Projects
Commit c85bf83e authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

- Fixed a few variable return types for some system calls. Made configure

  check for ssize_t to make it possible to use that when receiving the send()
  error code. This is necessary to prevent compiler warnings on some systems.

- Made configure create config.h, and all source files now include setup.h that
  might include the proper config.h (or a handicrafted alternative).

- Switched to 'ares_socket_t' type for sockets in ares, since Windows don't
  use 'int' for that.

- automake-ified and libool-ified c-ares. Now it builds libcares as a shared
  lib on most platforms if wanted. (This bloated the size of the release
  archive with another 200K!)

- Makefile.am now uses Makefile.inc for the c sources, h headers and man
  pages, to make it easier for other makefiles to use the exact same set of
  files.

- Adjusted 'maketgz' to use the new automake magic when building distribution
  archives.
parent 060b6ce1
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <sys/types.h>
#ifdef WIN32
......
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <sys/types.h>
#ifdef WIN32
......
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <sys/types.h>
#ifdef WIN32
......
......@@ -82,8 +82,8 @@ struct send_request {
struct server_state {
struct in_addr addr;
int udp_socket;
int tcp_socket;
ares_socket_t udp_socket;
ares_socket_t tcp_socket;
/* Mini-buffer for reading the length word */
unsigned char tcp_lenbuf[2];
......
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <sys/types.h>
#ifdef WIN32
......@@ -80,13 +81,15 @@ static void write_tcp_data(ares_channel channel, fd_set *write_fds, time_t now)
struct server_state *server;
struct send_request *sendreq;
struct iovec *vec;
int i, n, count;
int i;
ssize_t count;
size_t n;
for (i = 0; i < channel->nservers; i++)
{
/* Make sure server has data to send and is selected in write_fds. */
server = &channel->servers[i];
if (!server->qhead || server->tcp_socket == -1
if (!server->qhead || server->tcp_socket == ARES_SOCKET_BAD
|| !FD_ISSET(server->tcp_socket, write_fds))
continue;
......@@ -185,7 +188,8 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now)
{
/* Make sure the server has a socket and is selected in read_fds. */
server = &channel->servers[i];
if (server->tcp_socket == -1 || !FD_ISSET(server->tcp_socket, read_fds))
if (server->tcp_socket == ARES_SOCKET_BAD ||
!FD_ISSET(server->tcp_socket, read_fds))
continue;
if (server->tcp_lenbuf_pos != 2)
......@@ -257,7 +261,8 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
/* Make sure the server has a socket and is selected in read_fds. */
server = &channel->servers[i];
if (server->udp_socket == -1 || !FD_ISSET(server->udp_socket, read_fds))
if (server->udp_socket == ARES_SOCKET_BAD ||
!FD_ISSET(server->udp_socket, read_fds))
continue;
count = recv(server->udp_socket, buf, sizeof(buf), 0);
......@@ -407,7 +412,7 @@ void ares__send_query(ares_channel channel, struct query *query, time_t now)
/* Make sure the TCP socket for this server is set up and queue
* a send request.
*/
if (server->tcp_socket == -1)
if (server->tcp_socket == ARES_SOCKET_BAD)
{
if (open_tcp_socket(channel, server) == -1)
{
......@@ -431,7 +436,7 @@ void ares__send_query(ares_channel channel, struct query *query, time_t now)
}
else
{
if (server->udp_socket == -1)
if (server->udp_socket == ARES_SOCKET_BAD)
{
if (open_udp_socket(channel, server) == -1)
{
......@@ -454,12 +459,13 @@ void ares__send_query(ares_channel channel, struct query *query, time_t now)
static int open_tcp_socket(ares_channel channel, struct server_state *server)
{
int s, flags;
ares_socket_t s;
int flags;
struct sockaddr_in sockin;
/* Acquire a socket. */
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1)
if (s == ARES_SOCKET_BAD)
return -1;
/* Set the socket non-blocking. */
......@@ -472,13 +478,13 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
if (flags == -1)
{
close(s);
closesocket(s);
return -1;
}
flags |= O_NONBLOCK;
if (fcntl(s, F_SETFL, flags) == -1)
{
close(s);
closesocket(s);
return -1;
}
#endif
......@@ -503,12 +509,12 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
static int open_udp_socket(ares_channel channel, struct server_state *server)
{
int s;
ares_socket_t s;
struct sockaddr_in sockin;
/* Acquire a socket. */
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == -1)
if (s == ARES_SOCKET_BAD)
return -1;
/* Connect to the server. */
......
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <sys/types.h>
#ifdef WIN32
......
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <sys/types.h>
#ifdef WIN32
......
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <assert.h>
#include "ares.h"
......
......@@ -13,6 +13,7 @@
* without express or implied warranty.
*/
#include "setup.h"
#include <sys/types.h>
#ifdef WIN32
......
/* $Id$ */
#include "setup.h"
#include "ares_version.h"
const char *ares_version(int *version)
......
#!/bin/sh
libtoolize --copy --automake --force
aclocal
autoheader
autoconf
automake --add-missing
This diff is collapsed.
This diff is collapsed.
dnl Process this file with autoconf to produce a configure script.
AC_INIT(ares_init.c)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE
AM_INIT_AUTOMAKE(c-ares, CVS)
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_CANONICAL_HOST
AM_PROG_LIBTOOL
case $host_os in
solaris*)
AC_DEFINE(ETC_INET)
AC_DEFINE(ETC_INET, 1, [if a /etc/inet dir is being used])
;;
esac
# check for ssize_t
AC_CHECK_TYPE(ssize_t, ,
AC_DEFINE(ssize_t, int, [the signed version of size_t]))
AC_SEARCH_LIBS(gethostbyname, nsl)
AC_SEARCH_LIBS(socket, socket)
......
......@@ -2,8 +2,6 @@
$version = $ARGV[0];
$name="c-ares";
if($version eq "") {
print "Enter version number!\n";
exit;
......@@ -15,86 +13,25 @@ if(!-f "ares.h") {
}
if(!-f "configure") {
`autoconf`;
}
@files=`find . -name FILES`;
my @entries;
sub dirpart {
my ($file)=@_;
my @p=split("/", $file);
$p[$#p]=""; # blank the last one
my $dir=join("/", @p);
$dir =~ s/^\.\///; # cut off ./ beginnings
$dir =~ s/\/$//; # off / trailers
if(!$dir) {
$dir = ".";
}
return $dir;
}
sub add {
my ($file)=@_;
my $dir=dirpart($file);
open(FILE, "<$file");
while(<FILE>) {
if($_ =~ /^ *\#/) {
next;
}
chomp;
push @entries, "$dir/$_";
}
close(FILE);
}
for(@files) {
chomp;
add($_);
print "running buildconf\n";
`./buildconf`;
}
print "adding $version in the configure.ac file\n";
`sed -e 's/AM_INIT_AUTOMAKE(c-ares, CVS)/AM_INIT_AUTOMAKE(c-ares, $version)/' < configure.ac > configure.ac-rel`;
sub mkalldir {
my ($dir) = @_;
# now make a new configure script with this
print "makes a new configure script\n";
`autoconf configure.ac-rel`;
my @parts = split("/", $dir);
# now run this new configure to get a fine makefile
print "running configure\n";
`./configure`;
#print "IN: $dir\n";
my $sub="";
for(@parts) {
#print "PART: $_\n";
$sub .= "$_";
if($_ eq "") {
next;
}
mkdir($sub, 0777);
#print "make $sub\n";
$sub .= "/";
}
}
for(@entries) {
my $dir = dirpart("$name-$version/$_");
# print "Create $dir\n";
mkalldir($dir);
# print "Copy $_ to $dir\n";
`cp -p $_ $dir`;
}
# now make the actual tarball
print "running make dist\n";
`make dist`;
# make a tarball
`tar -cf $name-$version.tar $name-$version`;
# gzip the tarball
`gzip -9 $name-$version.tar`;
# remove the dir
`rm -rf $name-$version`;
print "removing temporary configure.ac file\n";
`rm configure.ac-rel`;
print "NOTE: now cvs tag this release!\n";
#ifndef ARES_SETUP_H
#define ARES_SETUP_H
/* Copyright (C) 2004 by Daniel Stenberg et al
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. M.I.T. makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
/* simple work-around for now, for systems without configure support */
#define ssize_t int
#endif
/* Recent autoconf versions define these symbols in config.h. We don't want
them (since they collide with the libcurl ones when we build
--enable-debug) so we undef them again here. */
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#undef PACKAGE_BUGREPORT
#undef PACKAGE_NAME
#undef VERSION
#undef PACKAGE
/* now typedef our socket type */
#ifdef WIN32
typedef SOCKET ares_socket_t;
#define ARES_SOCKET_BAD INVALID_SOCKET
#else
typedef int ares_socket_t;
#define ARES_SOCKET_BAD -1
#endif
#endif /* ARES_SETUP_H */
#include "setup.h"
#ifdef WIN32 /* only do the following on windows */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
......@@ -26,8 +29,8 @@ ares_strcasecmp(const char *a, const char *b)
}
#endif
int
ares_gettimeofday(struct timeval *tv, struct timezone *tz)
int
ares_gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
LARGE_INTEGER li;
......@@ -46,18 +49,7 @@ ares_gettimeofday(struct timeval *tv, struct timezone *tz)
tv->tv_usec = (long)(t % 1000000);
}
#if 0
if (tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
#endif
return 0;
}
#endif /* WIN32 builds only */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment