mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Merge remote branch 'origin/patches-2.0'
This commit is contained in:
commit
22845886c6
@ -454,7 +454,7 @@ AC_CHECK_SIZEOF(short)
|
||||
AC_CHECK_SIZEOF(size_t)
|
||||
AC_CHECK_SIZEOF(void *)
|
||||
|
||||
AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t, struct addrinfo], , ,
|
||||
AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t, struct addrinfo, struct sockaddr_storage], , ,
|
||||
[#define _GNU_SOURCE
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
|
40
evutil.c
40
evutil.c
@ -350,6 +350,8 @@ evutil_strtoll(const char *s, char **endptr, int base)
|
||||
r = (ev_int64_t) _atoi64(s);
|
||||
while (isspace(*s))
|
||||
++s;
|
||||
if (*s == '-')
|
||||
++s;
|
||||
while (isdigit(*s))
|
||||
++s;
|
||||
if (endptr)
|
||||
@ -357,6 +359,36 @@ evutil_strtoll(const char *s, char **endptr, int base)
|
||||
return r;
|
||||
#elif defined(WIN32)
|
||||
return (ev_int64_t) _strtoi64(s, endptr, base);
|
||||
#elif defined(_EVENT_SIZEOF_LONG_LONG) && _EVENT_SIZEOF_LONG_LONG == 8
|
||||
long long r;
|
||||
int n;
|
||||
if (base != 10 && base != 16)
|
||||
return 0;
|
||||
if (base == 10) {
|
||||
n = sscanf(s, "%lld", &r);
|
||||
} else {
|
||||
unsigned long long ru=0;
|
||||
n = sscanf(s, "%llx", &ru);
|
||||
if (ru > EV_INT64_MAX)
|
||||
return 0;
|
||||
r = (long long) ru;
|
||||
}
|
||||
if (n != 1)
|
||||
return 0;
|
||||
while (EVUTIL_ISSPACE(*s))
|
||||
++s;
|
||||
if (*s == '-')
|
||||
++s;
|
||||
if (base == 10) {
|
||||
while (EVUTIL_ISDIGIT(*s))
|
||||
++s;
|
||||
} else {
|
||||
while (EVUTIL_ISXDIGIT(*s))
|
||||
++s;
|
||||
}
|
||||
if (endptr)
|
||||
*endptr = (char*) s;
|
||||
return r;
|
||||
#else
|
||||
#error "I don't know how to parse 64-bit integers."
|
||||
#endif
|
||||
@ -735,6 +767,10 @@ evutil_getaddrinfo_infer_protocols(struct evutil_addrinfo *hints)
|
||||
}
|
||||
}
|
||||
|
||||
#if AF_UNSPEC != PF_UNSPEC
|
||||
#error "I cannot build on a system where AF_UNSPEC != PF_UNSPEC"
|
||||
#endif
|
||||
|
||||
/** Implements the part of looking up hosts by name that's common to both
|
||||
* the blocking and nonblocking resolver:
|
||||
* - Adjust 'hints' to have a reasonable socktype and protocol.
|
||||
@ -785,7 +821,7 @@ evutil_getaddrinfo_common(const char *nodename, const char *servname,
|
||||
memset(&sin6, 0, sizeof(sin6));
|
||||
sin6.sin6_family = AF_INET6;
|
||||
sin6.sin6_port = htons(port);
|
||||
if (hints->ai_flags & AI_PASSIVE) {
|
||||
if (hints->ai_flags & EVUTIL_AI_PASSIVE) {
|
||||
/* Bind to :: */
|
||||
} else {
|
||||
/* connect to ::1 */
|
||||
@ -802,7 +838,7 @@ evutil_getaddrinfo_common(const char *nodename, const char *servname,
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(port);
|
||||
if (hints->ai_flags & AI_PASSIVE) {
|
||||
if (hints->ai_flags & EVUTIL_AI_PASSIVE) {
|
||||
/* Bind to 0.0.0.0 */
|
||||
} else {
|
||||
/* connect to 127.0.0.1 */
|
||||
|
@ -61,12 +61,21 @@ typedef int sa_family_t;
|
||||
|
||||
#ifndef _EVENT_HAVE_STRUCT_SOCKADDR_IN6
|
||||
struct sockaddr_in6 {
|
||||
/* This will fail if we find a struct sockaddr that doesn't have
|
||||
* sa_family as the first element. */
|
||||
sa_family_t sin6_family;
|
||||
ev_uint16_t sin6_port;
|
||||
struct in6_addr sin6_addr;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef AF_INET6
|
||||
#define AF_INET6 3333
|
||||
#endif
|
||||
#ifndef PF_INET6
|
||||
#define PF_INET6 AF_INET6
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include "event2/http.h"
|
||||
#include "event2/buffer.h"
|
||||
#include "event2/bufferevent.h"
|
||||
#include "event2/util.h"
|
||||
#include "log-internal.h"
|
||||
#include "util-internal.h"
|
||||
#include "http-internal.h"
|
||||
@ -128,38 +129,23 @@ static evutil_socket_t
|
||||
http_connect(const char *address, u_short port)
|
||||
{
|
||||
/* Stupid code for connecting */
|
||||
#ifdef WIN32
|
||||
struct hostent *he;
|
||||
struct sockaddr_in sin;
|
||||
#else
|
||||
struct addrinfo ai, *aitop;
|
||||
struct evutil_addrinfo ai, *aitop;
|
||||
char strport[NI_MAXSERV];
|
||||
#endif
|
||||
|
||||
struct sockaddr *sa;
|
||||
int slen;
|
||||
evutil_socket_t fd;
|
||||
|
||||
#ifdef WIN32
|
||||
if (!(he = gethostbyname(address))) {
|
||||
event_warn("gethostbyname");
|
||||
}
|
||||
memcpy(&sin.sin_addr, he->h_addr_list[0], he->h_length);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(port);
|
||||
slen = sizeof(struct sockaddr_in);
|
||||
sa = (struct sockaddr*)&sin;
|
||||
#else
|
||||
memset(&ai, 0, sizeof(ai));
|
||||
ai.ai_family = AF_INET;
|
||||
ai.ai_socktype = SOCK_STREAM;
|
||||
evutil_snprintf(strport, sizeof(strport), "%d", port);
|
||||
if (getaddrinfo(address, strport, &ai, &aitop) != 0) {
|
||||
if (evutil_getaddrinfo(address, strport, &ai, &aitop) != 0) {
|
||||
event_warn("getaddrinfo");
|
||||
return (-1);
|
||||
}
|
||||
sa = aitop->ai_addr;
|
||||
slen = aitop->ai_addrlen;
|
||||
#endif
|
||||
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd == -1)
|
||||
@ -178,9 +164,7 @@ http_connect(const char *address, u_short port)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
freeaddrinfo(aitop);
|
||||
#endif
|
||||
evutil_freeaddrinfo(aitop);
|
||||
|
||||
return (fd);
|
||||
}
|
||||
|
@ -40,6 +40,8 @@
|
||||
#endif
|
||||
#include "event2/util.h"
|
||||
|
||||
#include "ipv6-internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -207,6 +209,21 @@ long _evutil_weakrand(void);
|
||||
#define EVUTIL_FAILURE_CHECK(cond) EVUTIL_UNLIKELY(cond)
|
||||
#endif
|
||||
|
||||
#ifndef _EVENT_HAVE_STRUCT_SOCKADDR_STORAGE
|
||||
/* Replacement for sockaddr storage that we can use internally on platforms
|
||||
* that lack it. It is not space-efficient, but neither is sockaddr_storage.
|
||||
*/
|
||||
struct sockaddr_storage {
|
||||
union {
|
||||
struct sockaddr ss_sa;
|
||||
struct sockaddr_in ss_sin;
|
||||
struct sockaddr_in6 ss_sin6;
|
||||
char ss_padding[128];
|
||||
} ss_union;
|
||||
};
|
||||
#define ss_family ss_union.ss_sa.sa_family
|
||||
#endif
|
||||
|
||||
/* Internal addrinfo error code. This one is returned from only from
|
||||
* evutil_getaddrinfo_common, when we are sure that we'll have to hit a DNS
|
||||
* server. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user