Deleted Added
sdiff udiff text old ( 256281 ) new ( 269257 )
full compact
1/*
2 * util/winsock_event.c - implementation of the unbound winsock event handler.
3 *
4 * Copyright (c) 2008, NLnet Labs. All rights reserved.
5 *
6 * This software is open source.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 7 unchanged lines hidden (view full) ---

16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35/**
36 * \file
37 * Implementation of the unbound WinSock2 API event notification handler
38 * for the Windows port.
39 */
40
41#include "config.h"
42#ifdef USE_WINSOCK
43#include <signal.h>
44#ifdef HAVE_TIME_H
45#include <time.h>
46#endif
47#include <sys/time.h>
48#include "util/winsock_event.h"
49#include "util/fptr_wlist.h"
50
51int mini_ev_cmp(const void* a, const void* b)
52{
53 const struct event *e = (const struct event*)a;
54 const struct event *f = (const struct event*)b;
55 if(e->ev_timeout.tv_sec < f->ev_timeout.tv_sec)

--- 14 unchanged lines hidden (view full) ---

70/** set time */
71static int
72settime(struct event_base* base)
73{
74 if(gettimeofday(base->time_tv, NULL) < 0) {
75 return -1;
76 }
77#ifndef S_SPLINT_S
78 *base->time_secs = (time_t)base->time_tv->tv_sec;
79#endif
80 return 0;
81}
82
83#ifdef UNBOUND_DEBUG
84/**
85 * Find a fd in the list of items.
86 * Note that not all items have a fd associated (those are -1).

--- 20 unchanged lines hidden (view full) ---

107{
108 int i;
109 for(i=0; i<WSK_MAX_ITEMS; i++) {
110 if(waitfor[i] == x)
111 waitfor[i] = 0;
112 }
113}
114
115void *event_init(time_t* time_secs, struct timeval* time_tv)
116{
117 struct event_base* base = (struct event_base*)malloc(
118 sizeof(struct event_base));
119 if(!base)
120 return NULL;
121 memset(base, 0, sizeof(*base));
122 base->time_secs = time_secs;
123 base->time_tv = time_tv;

--- 56 unchanged lines hidden (view full) ---

180 if(now->tv_usec > p->ev_timeout.tv_usec) {
181 wait->tv_sec--;
182 wait->tv_usec = 1000000 - (now->tv_usec -
183 p->ev_timeout.tv_usec);
184 } else {
185 wait->tv_usec = p->ev_timeout.tv_usec
186 - now->tv_usec;
187 }
188 verbose(VERB_CLIENT, "winsock_event wait=" ARG_LL "d.%6.6d",
189 (long long)wait->tv_sec, (int)wait->tv_usec);
190 return;
191 }
192#endif
193 /* event times out, remove it */
194 (void)rbtree_delete(base->times, p);
195 p->ev_events &= ~EV_TIMEOUT;
196 fptr_ok(fptr_whitelist_event(p->ev_callback));
197 (*p->ev_callback)(p->ev_fd, EV_TIMEOUT, p->ev_arg);

--- 289 unchanged lines hidden (view full) ---

487 ev->old_events = 0;
488 ev->stick_events = 0;
489 ev->added = 0;
490 return 0;
491}
492
493int event_add(struct event *ev, struct timeval *tv)
494{
495 verbose(VERB_ALGO, "event_add %p added=%d fd=%d tv=" ARG_LL "d %s%s%s",
496 ev, ev->added, ev->ev_fd,
497 (tv?(long long)tv->tv_sec*1000+(long long)tv->tv_usec/1000:-1),
498 (ev->ev_events&EV_READ)?" EV_READ":"",
499 (ev->ev_events&EV_WRITE)?" EV_WRITE":"",
500 (ev->ev_events&EV_TIMEOUT)?" EV_TIMEOUT":"");
501 if(ev->added)
502 event_del(ev);
503 log_assert(ev->ev_fd==-1 || find_fd(ev->ev_base, ev->ev_fd) == -1);
504 ev->is_tcp = 0;
505 ev->is_signal = 0;

--- 62 unchanged lines hidden (view full) ---

568 (void)rbtree_insert(ev->ev_base->times, &ev->node);
569 }
570 ev->added = 1;
571 return 0;
572}
573
574int event_del(struct event *ev)
575{
576 verbose(VERB_ALGO, "event_del %p added=%d fd=%d tv=" ARG_LL "d %s%s%s",
577 ev, ev->added, ev->ev_fd,
578 (ev->ev_events&EV_TIMEOUT)?(long long)ev->ev_timeout.tv_sec*1000+
579 (long long)ev->ev_timeout.tv_usec/1000:-1,
580 (ev->ev_events&EV_READ)?" EV_READ":"",
581 (ev->ev_events&EV_WRITE)?" EV_WRITE":"",
582 (ev->ev_events&EV_TIMEOUT)?" EV_TIMEOUT":"");
583 if(!ev->added)
584 return 0;
585 log_assert(ev->added);
586 if((ev->ev_events&EV_TIMEOUT))
587 (void)rbtree_delete(ev->ev_base->times, &ev->node);

--- 109 unchanged lines hidden ---