~hartmans/ubuntu/trusty/krb5/gss-infinite-loop

« back to all changes in this revision

Viewing changes to src/util/k5ev/verto-k5ev.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-11-10 02:20:12 UTC
  • mfrom: (53.1.3 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131110022012-b8ojkqhcxos55kln
Tags: 1.11.3+dfsg-3ubuntu2
Add alternate dependency on libverto-libevent1 as that's the package
ABI name in ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2011 Red Hat, Inc.
3
 
 *
4
 
 * Permission is hereby granted, free of charge, to any person
5
 
 * obtaining a copy of this software and associated documentation files
6
 
 * (the "Software"), to deal in the Software without restriction,
7
 
 * including without limitation the rights to use, copy, modify, merge,
8
 
 * publish, distribute, sublicense, and/or sell copies of the Software,
9
 
 * and to permit persons to whom the Software is furnished to do so,
10
 
 * subject to the following conditions:
11
 
 *
12
 
 * The above copyright notice and this permission notice shall be
13
 
 * included in all copies or substantial portions of the Software.
14
 
 *
15
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
 
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
 
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
 
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 
 * SOFTWARE.
23
 
 */
24
 
 
25
 
/*
26
 
 * An edited version of verto-libev.c, using an embedded libev with renamed
27
 
 * symbols.  The corresponding version of verto-libev.c is stored in this
28
 
 * directory for reference, although it is not built here.
29
 
 */
30
 
 
31
 
#include <stdlib.h>
32
 
#include <string.h>
33
 
#include <errno.h>
34
 
 
35
 
#include "verto-k5ev.h"
36
 
#include <verto-module.h>
37
 
#include "rename.h"
38
 
#include "autoconf.h"
39
 
#define EV_STANDALONE 1
40
 
/* Avoids using clock_gettime; we probably shouldn't have to do this. */
41
 
#define EV_USE_REALTIME 0
42
 
#define EV_FEATURES 0x5f        /* Everything but back ends */
43
 
#ifdef HAVE_POLL_H
44
 
#define EV_USE_POLL 1
45
 
#endif
46
 
/* ev.c explicitly disables poll() on Mac or FreeBSD; fall back to select(). */
47
 
#define EV_USE_SELECT 1
48
 
#include "ev.c"
49
 
 
50
 
static verto_mod_ctx *
51
 
k5ev_ctx_new(void)
52
 
{
53
 
    return ev_loop_new(EVFLAG_AUTO);
54
 
}
55
 
 
56
 
static verto_mod_ctx *
57
 
k5ev_ctx_default(void)
58
 
{
59
 
    return ev_default_loop(EVFLAG_AUTO);
60
 
}
61
 
 
62
 
static void
63
 
k5ev_ctx_free(verto_mod_ctx *ctx)
64
 
{
65
 
    if (ctx != EV_DEFAULT)
66
 
        ev_loop_destroy(ctx);
67
 
}
68
 
 
69
 
static void
70
 
k5ev_ctx_run(verto_mod_ctx *ctx)
71
 
{
72
 
    ev_run(ctx, 0);
73
 
}
74
 
 
75
 
static void
76
 
k5ev_ctx_run_once(verto_mod_ctx *ctx)
77
 
{
78
 
    ev_run(ctx, EVRUN_ONCE);
79
 
}
80
 
 
81
 
static void
82
 
k5ev_ctx_break(verto_mod_ctx *ctx)
83
 
{
84
 
    ev_break(ctx, EVBREAK_ONE);
85
 
}
86
 
 
87
 
static void
88
 
k5ev_ctx_reinitialize(verto_mod_ctx *ctx)
89
 
{
90
 
    ev_loop_fork(ctx);
91
 
}
92
 
 
93
 
static void
94
 
libev_callback(EV_P_ ev_watcher *w, int revents)
95
 
{
96
 
    if (verto_get_type(w->data) == VERTO_EV_TYPE_CHILD)
97
 
        verto_set_proc_status(w->data, ((ev_child*) w)->rstatus);
98
 
 
99
 
    verto_fire(w->data);
100
 
}
101
 
 
102
 
#define setuptype(type, ...) \
103
 
    w.type = malloc(sizeof(ev_ ## type)); \
104
 
    if (w.type) { \
105
 
        ev_ ## type ## _init(w.type, (EV_CB(type, (*))) __VA_ARGS__); \
106
 
        ev_ ## type ## _start(ctx, w.type); \
107
 
    } \
108
 
    break
109
 
 
110
 
static verto_mod_ev *
111
 
k5ev_ctx_add(verto_mod_ctx *ctx, const verto_ev *ev, verto_ev_flag *flags)
112
 
{
113
 
    union {
114
 
       ev_watcher *watcher;
115
 
       ev_io *io;
116
 
       ev_timer *timer;
117
 
       ev_idle *idle;
118
 
       ev_signal *signal;
119
 
       ev_child *child;
120
 
    } w;
121
 
    ev_tstamp interval;
122
 
    int events = EV_NONE;
123
 
 
124
 
    w.watcher = NULL;
125
 
    *flags |= VERTO_EV_FLAG_PERSIST;
126
 
    switch (verto_get_type(ev)) {
127
 
        case VERTO_EV_TYPE_IO:
128
 
            if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
129
 
                events |= EV_READ;
130
 
            if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
131
 
                events |= EV_WRITE;
132
 
            setuptype(io, libev_callback, verto_get_fd(ev), events);
133
 
        case VERTO_EV_TYPE_TIMEOUT:
134
 
            interval = ((ev_tstamp) verto_get_interval(ev)) / 1000.0;
135
 
            setuptype(timer, libev_callback, interval, interval);
136
 
        case VERTO_EV_TYPE_IDLE:
137
 
            setuptype(idle, libev_callback);
138
 
        case VERTO_EV_TYPE_SIGNAL:
139
 
            setuptype(signal, libev_callback, verto_get_signal(ev));
140
 
        case VERTO_EV_TYPE_CHILD:
141
 
            *flags &= ~VERTO_EV_FLAG_PERSIST; /* Child events don't persist */
142
 
            setuptype(child, libev_callback, verto_get_proc(ev), 0);
143
 
        default:
144
 
            break; /* Not supported */
145
 
    }
146
 
 
147
 
    if (w.watcher)
148
 
        w.watcher->data = (void*) ev;
149
 
    return w.watcher;
150
 
}
151
 
 
152
 
static void
153
 
k5ev_ctx_del(verto_mod_ctx *ctx, const verto_ev *ev, verto_mod_ev *evpriv)
154
 
{
155
 
    switch (verto_get_type(ev)) {
156
 
        case VERTO_EV_TYPE_IO:
157
 
            ev_io_stop(ctx, (ev_io*) evpriv);
158
 
            break;
159
 
        case VERTO_EV_TYPE_TIMEOUT:
160
 
            ev_timer_stop(ctx, (ev_timer*) evpriv);
161
 
            break;
162
 
        case VERTO_EV_TYPE_IDLE:
163
 
            ev_idle_stop(ctx, (ev_idle*) evpriv);
164
 
            break;
165
 
        case VERTO_EV_TYPE_SIGNAL:
166
 
            ev_signal_stop(ctx, (ev_signal*) evpriv);
167
 
            break;
168
 
        case VERTO_EV_TYPE_CHILD:
169
 
            ev_child_stop(ctx, (ev_child*) evpriv);
170
 
            break;
171
 
        default:
172
 
            break;
173
 
    }
174
 
 
175
 
    free(evpriv);
176
 
}
177
 
 
178
 
VERTO_MODULE(k5ev, NULL,
179
 
             VERTO_EV_TYPE_IO |
180
 
             VERTO_EV_TYPE_TIMEOUT |
181
 
             VERTO_EV_TYPE_IDLE |
182
 
             VERTO_EV_TYPE_SIGNAL |
183
 
             VERTO_EV_TYPE_CHILD);
184
 
 
185
 
verto_ctx *
186
 
verto_convert_k5ev(struct ev_loop* loop)
187
 
{
188
 
    return verto_convert(k5ev, 0, loop);
189
 
}