1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* Copyright (c) 2002-2013 BalaBit IT Ltd, Budapest, Hungary
* Copyright (c) 1998-2013 Balázs Scheidler
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#include "poll-fd-events.h"
#include <iv.h>
typedef struct _PollFdEvents
{
PollEvents super;
struct iv_fd fd_watch;
} PollFdEvents;
#define IV_FD_CALLBACK(x) ((void (*)(void *)) (x))
static void
poll_fd_events_start_watches(PollEvents *s)
{
PollFdEvents *self = (PollFdEvents *) s;
iv_fd_register(&self->fd_watch);
}
static void
poll_fd_events_stop_watches(PollEvents *s)
{
PollFdEvents *self = (PollFdEvents *) s;
if (iv_fd_registered(&self->fd_watch))
iv_fd_unregister(&self->fd_watch);
}
static void
poll_fd_events_update_watches(PollEvents *s, GIOCondition cond)
{
PollFdEvents *self = (PollFdEvents *) s;
if (cond & G_IO_IN)
iv_fd_set_handler_in(&self->fd_watch, IV_FD_CALLBACK(poll_events_invoke_callback));
else
iv_fd_set_handler_in(&self->fd_watch, NULL);
if (cond & G_IO_OUT)
iv_fd_set_handler_out(&self->fd_watch, IV_FD_CALLBACK(poll_events_invoke_callback));
else
iv_fd_set_handler_out(&self->fd_watch, NULL);
if (cond & (G_IO_IN + G_IO_OUT))
iv_fd_set_handler_err(&self->fd_watch, IV_FD_CALLBACK(poll_events_invoke_callback));
else
iv_fd_set_handler_err(&self->fd_watch, NULL);
}
PollEvents *
poll_fd_events_new(gint fd)
{
PollFdEvents *self = g_new0(PollFdEvents, 1);
g_assert(fd >= 0);
self->super.start_watches = poll_fd_events_start_watches;
self->super.stop_watches = poll_fd_events_stop_watches;
self->super.update_watches = poll_fd_events_update_watches;
IV_FD_INIT(&self->fd_watch);
self->fd_watch.fd = fd;
self->fd_watch.cookie = self;
return &self->super;
}
|