2002-09-15 18:55:21 +00:00
|
|
|
/*
|
2012-02-10 17:29:53 -05:00
|
|
|
* Copyright (c) 2002-2007 Niels Provos <provos@citi.umich.edu>
|
|
|
|
* Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2002-09-15 18:55:21 +00:00
|
|
|
*/
|
2010-07-07 16:45:03 -04:00
|
|
|
#include "event2/event-config.h"
|
2002-09-15 18:55:21 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-05-25 19:50:56 -04:00
|
|
|
#ifndef _WIN32
|
2002-09-15 18:55:21 +00:00
|
|
|
#include <unistd.h>
|
2009-11-05 20:37:19 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
2002-09-15 18:55:21 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2010-12-02 14:13:33 -05:00
|
|
|
#include "event2/event.h"
|
|
|
|
#include "event2/event_compat.h"
|
|
|
|
#include "event2/event_struct.h"
|
2014-09-18 12:02:13 -04:00
|
|
|
#include "util-internal.h"
|
2002-09-15 18:55:21 +00:00
|
|
|
|
|
|
|
int called = 0;
|
|
|
|
|
|
|
|
#define NEVENT 20000
|
|
|
|
|
|
|
|
struct event *ev[NEVENT];
|
|
|
|
|
2014-09-18 12:02:13 -04:00
|
|
|
struct evutil_weakrand_state weakrand_state;
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static int
|
2007-09-20 19:08:20 +00:00
|
|
|
rand_int(int n)
|
|
|
|
{
|
2014-09-18 12:12:36 -04:00
|
|
|
return evutil_weakrand_(&weakrand_state) % n;
|
2007-09-20 19:08:20 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2010-03-05 12:47:46 -05:00
|
|
|
time_cb(evutil_socket_t fd, short event, void *arg)
|
2002-09-15 18:55:21 +00:00
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
called++;
|
|
|
|
|
|
|
|
if (called < 10*NEVENT) {
|
|
|
|
for (i = 0; i < 10; i++) {
|
2007-09-20 19:08:20 +00:00
|
|
|
j = rand_int(NEVENT);
|
2002-09-15 18:55:21 +00:00
|
|
|
tv.tv_sec = 0;
|
2007-09-20 19:08:20 +00:00
|
|
|
tv.tv_usec = rand_int(50000);
|
2014-12-15 12:50:11 -05:00
|
|
|
if (tv.tv_usec % 2 || called < NEVENT)
|
2002-09-15 18:55:21 +00:00
|
|
|
evtimer_add(ev[j], &tv);
|
|
|
|
else
|
|
|
|
evtimer_del(ev[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-02-19 03:39:50 -05:00
|
|
|
main(int argc, char **argv)
|
2002-09-15 18:55:21 +00:00
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
int i;
|
2011-05-25 19:50:56 -04:00
|
|
|
#ifdef _WIN32
|
2010-05-08 18:00:26 -04:00
|
|
|
WORD wVersionRequested;
|
|
|
|
WSADATA wsaData;
|
|
|
|
|
|
|
|
wVersionRequested = MAKEWORD(2, 2);
|
|
|
|
|
2012-11-01 17:38:34 -04:00
|
|
|
(void) WSAStartup(wVersionRequested, &wsaData);
|
2010-05-08 18:00:26 -04:00
|
|
|
#endif
|
2002-09-15 18:55:21 +00:00
|
|
|
|
2014-09-18 12:02:13 -04:00
|
|
|
evutil_weakrand_seed_(&weakrand_state, 0);
|
|
|
|
|
2002-09-15 18:55:21 +00:00
|
|
|
/* Initalize the event library */
|
|
|
|
event_init();
|
|
|
|
|
|
|
|
for (i = 0; i < NEVENT; i++) {
|
|
|
|
ev[i] = malloc(sizeof(struct event));
|
|
|
|
|
|
|
|
/* Initalize one event */
|
|
|
|
evtimer_set(ev[i], time_cb, ev[i]);
|
|
|
|
tv.tv_sec = 0;
|
2007-09-20 19:08:20 +00:00
|
|
|
tv.tv_usec = rand_int(50000);
|
2002-09-15 18:55:21 +00:00
|
|
|
evtimer_add(ev[i], &tv);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_dispatch();
|
|
|
|
|
2014-12-15 12:50:11 -05:00
|
|
|
|
|
|
|
printf("%d, %d\n", called, NEVENT);
|
2002-09-15 18:55:21 +00:00
|
|
|
return (called < NEVENT);
|
|
|
|
}
|
|
|
|
|