Deleted Added
full compact
winsock_event.c (256281) winsock_event.c (269257)
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
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 LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
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>
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>
44#include "util/winsock_event.h"
45#include "util/fptr_wlist.h"
46
47int mini_ev_cmp(const void* a, const void* b)
48{
49 const struct event *e = (const struct event*)a;
50 const struct event *f = (const struct event*)b;
51 if(e->ev_timeout.tv_sec < f->ev_timeout.tv_sec)

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

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

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

103{
104 int i;
105 for(i=0; i<WSK_MAX_ITEMS; i++) {
106 if(waitfor[i] == x)
107 waitfor[i] = 0;
108 }
109}
110
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
111void *event_init(uint32_t* time_secs, struct timeval* time_tv)
115void *event_init(time_t* time_secs, struct timeval* time_tv)
112{
113 struct event_base* base = (struct event_base*)malloc(
114 sizeof(struct event_base));
115 if(!base)
116 return NULL;
117 memset(base, 0, sizeof(*base));
118 base->time_secs = time_secs;
119 base->time_tv = time_tv;

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

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

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

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

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

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

--- 109 unchanged lines hidden ---
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 ---