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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
* Copyright (c) 2002-2013 Balabit
* 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 inline gint
_get_fd(PollEvents *s)
{
PollFdEvents *self = (PollFdEvents *) s;
return self->fd_watch.fd;
}
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_suspend_watches(PollEvents *s)
{
PollFdEvents *self = (PollFdEvents *) s;
iv_fd_set_handler_in(&self->fd_watch, NULL);
iv_fd_set_handler_out(&self->fd_watch, NULL);
iv_fd_set_handler_err(&self->fd_watch, NULL);
}
static void
poll_fd_events_update_watches(PollEvents *s, GIOCondition cond)
{
PollFdEvents *self = (PollFdEvents *) s;
poll_events_suspend_watches(s);
if (poll_events_check_watches(s))
{
if (cond & G_IO_IN)
iv_fd_set_handler_in(&self->fd_watch, IV_FD_CALLBACK(poll_events_invoke_callback));
if (cond & G_IO_OUT)
iv_fd_set_handler_out(&self->fd_watch, IV_FD_CALLBACK(poll_events_invoke_callback));
if (cond & (G_IO_IN + G_IO_OUT))
iv_fd_set_handler_err(&self->fd_watch, IV_FD_CALLBACK(poll_events_invoke_callback));
}
}
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;
self->super.suspend_watches = poll_fd_events_suspend_watches;
self->super.system_polled = TRUE;
self->super.get_fd = _get_fd;
IV_FD_INIT(&self->fd_watch);
self->fd_watch.fd = fd;
self->fd_watch.cookie = self;
return &self->super;
}
|