Select Git revision
cast128-meta.c
glib.c 2.91 KiB
/* glib.c, liboop, copyright 1999 Dan Egnor
This is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License, version 2.1 or later.
See the file COPYING for details. */
#ifdef HAVE_GLIB
#include "glib.h"
#include "oop-glib.h"
#include "oop.h"
#include <assert.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h> /* Needed on NetBSD1.1/SPARC due to bzero/FD_ZERO. */
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h> /* Needed on AIX 4.2 due to bzero/FD_ZERO. */
#endif
static int use_count = 0;
static oop_source_sys *sys;
static oop_adapter_select *sel;
static fd_set read_set,write_set,except_set;
static int count;
static void *ret = NULL;
static void *on_select(
oop_adapter_select *s,int num,fd_set *r,fd_set *w,fd_set *x,
struct timeval now,void *unused)
{
read_set = *r;
write_set = *w;
except_set = *x;
count = num;
return &use_count;
}
static gint on_poll(GPollFD *array,guint num,gint timeout) {
struct timeval tv;
int i;
FD_ZERO(&read_set);
FD_ZERO(&write_set);
FD_ZERO(&except_set);
count = 0;
for (i = 0; i < num; ++i) {
if (array[i].events & G_IO_IN)
FD_SET(array[i].fd,&read_set);
if (array[i].events & G_IO_OUT)
FD_SET(array[i].fd,&write_set);
if (array[i].events & G_IO_PRI)
FD_SET(array[i].fd,&except_set);
/* {G_IO_,POLL}{ERR,HUP,INVAL} don't correspond to anything
in select(2), and aren't `normal' events anyway. */
if (array[i].fd >= count)
count = 1 + array[i].fd;
}