o Fix http module on windows to close sockets properly.
o Make autogen.sh script run correctly on systems where /bin/sh isn't bash. (Patch from Trond Norbye, rewritten by Hagne Mahre and then Hannah Schroeter.)
o Skip calling gettime() in timeout_process if we are not in fact waiting for any events. (Patch from Trond Norbye)
+ o Make test subdirectory compile under mingw.
+
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#ifdef WIN32
+#include <windows.h>
+#else
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/resource.h>
+#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <event.h>
+#include <evutil.h>
static int count, writes, fired;
int
main (int argc, char **argv)
{
+#ifndef WIN32
struct rlimit rl;
+#endif
int i, c;
struct timeval *tv;
int *cp;
}
}
+#ifndef WIN32
rl.rlim_cur = rl.rlim_max = num_pipes * 2 + 50;
if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
perror("setrlimit");
exit(1);
}
+#endif
events = calloc(num_pipes, sizeof(struct event));
pipes = calloc(num_pipes * 2, sizeof(int));
#ifdef USE_PIPES
if (pipe(cp) == -1) {
#else
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
+ if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
#endif
perror("pipe");
exit(1);
#include <sys/socket.h>
#include <sys/signal.h>
#include <unistd.h>
-#endif
#include <netdb.h>
+#endif
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <errno.h>
#include "event.h"
+#include "evutil.h"
#include "event-internal.h"
#include "log.h"
#define TEST1 "this is a test"
#define SECONDS 1
+#ifndef SHUT_WR
+#define SHUT_WR 1
+#endif
+
void
simple_read_cb(int fd, short event, void *arg)
{
fprintf(stdout, "%s", name);
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
+ if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
fprintf(stderr, "%s: socketpair\n", __func__);
exit(1);
}
#ifdef HAVE_NETINET_IN6_H
#include <netinet/in6.h>
#endif
+#ifdef HAVE_NETDB_H
#include <netdb.h>
+#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
evdns_close_server_port(port);
evdns_shutdown(0); /* remove ourself as nameserver. */
#ifdef WIN32
- CloseHandle(sock);
+ closesocket(sock);
#else
close(sock);
#endif
#include <sys/socket.h>
#include <sys/signal.h>
#include <unistd.h>
-#endif
#include <netdb.h>
+#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
return (myhttp);
}
+#ifndef NI_MAXSERV
+#define NI_MAXSERV 1024
+#endif
+
int
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;
char strport[NI_MAXSERV];
+#endif
+ struct sockaddr *sa;
+ int slen;
int fd;
+#ifdef WIN32
+ if (!(he = gethostbyname(address))) {
+ event_warn("gethostbyname");
+ }
+ memcpy(&sin.sin_addr, &he->h_addr, sizeof(struct in_addr));
+ 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;
event_warn("getaddrinfo");
return (-1);
}
+ sa = aitop->ai_addr;
+ slen = aitop->ai_addrlen;
+#endif
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1)
event_err(1, "socket failed");
- if (connect(fd, aitop->ai_addr, aitop->ai_addrlen) == -1)
+ if (connect(fd, sa, slen) == -1)
event_err(1, "connect failed");
+#ifndef WIN32
freeaddrinfo(aitop);
+#endif
return (fd);
}
#include <sys/socket.h>
#include <sys/signal.h>
#include <unistd.h>
-#endif
#include <netdb.h>
+#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#endif
+#ifdef WIN32
+#include <winsock2.h>
+#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
+#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <event.h>
+#include <evutil.h>
int test_okay = 1;
int called = 0;
called++;
}
+#ifndef SHUT_WR
+#define SHUT_WR 1
+#endif
+
int
main (int argc, char **argv)
{
char *test = "test string";
int pair[2];
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
+ if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
return (1);
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
+#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
struct event *ev[NEVENT];
+int
+rand_int(int n)
+{
+#ifdef WIN32
+ return (int)(rand() * n);
+#else
+ return (int)(random() % n);
+#endif
+}
+
void
time_cb(int fd, short event, void *arg)
{
if (called < 10*NEVENT) {
for (i = 0; i < 10; i++) {
- j = random() % NEVENT;
+ j = rand_int(NEVENT);
tv.tv_sec = 0;
- tv.tv_usec = random() % 50000L;
+ tv.tv_usec = rand_int(50000);
if (tv.tv_usec % 2)
evtimer_add(ev[j], &tv);
else
/* Initalize one event */
evtimer_set(ev[i], time_cb, ev[i]);
tv.tv_sec = 0;
- tv.tv_usec = random() % 50000L;
+ tv.tv_usec = rand_int(50000);
evtimer_add(ev[i], &tv);
}
#endif
+#ifdef WIN32
+#include <winsock2.h>
+#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
+#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <event.h>
+#include <evutil.h>
int pair[2];
int test_okay = 1;
{
struct event ev;
+#ifndef WIN32
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
return (1);
+#endif
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
+ if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
return (1);
/* Initalize the event library */