Select Git revision
aes-encrypt-internal.c
Forked from
Nettle / nettle
Source project has a limited visibility.
-
Niels Möller authoredNiels Möller authored
select.c 4.60 KiB
/* select.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. */
#include "oop.h"
#include <assert.h>
#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
struct select_set {
fd_set rfd,wfd,xfd;
};
struct oop_adapter_select {
oop_source *source;
struct select_set watch,active;
struct timeval timeout;
int num_fd,do_timeout,is_active,num_fd_active;
oop_call_select *call;
void *data;
};
static oop_call_fd on_fd;
static oop_call_time on_timeout,on_collect;
oop_adapter_select *oop_select_new(
oop_source *source,
oop_call_select *call,void *data)
{
oop_adapter_select *s = oop_malloc(sizeof(*s));
if (NULL == s) return s;
s->source = source;
FD_ZERO(&s->watch.rfd);
FD_ZERO(&s->watch.wfd);
FD_ZERO(&s->watch.xfd);
FD_ZERO(&s->active.rfd);
FD_ZERO(&s->active.wfd);
FD_ZERO(&s->active.xfd);
s->num_fd = 0;
s->num_fd_active = 0;
s->do_timeout = 0;
s->is_active = 0;
s->call = call;
s->data = data;
return s;
}
static void *activate(oop_adapter_select *s) {
if (!s->is_active) {
s->is_active = 1;
s->source->on_time(s->source,OOP_TIME_NOW,on_collect,s);
}
return OOP_CONTINUE;
}
static void deactivate(oop_adapter_select *s) {
if (s->is_active) {
s->source->cancel_time(s->source,OOP_TIME_NOW,on_collect,s);
s->is_active = 0;
s->num_fd_active = 0;
FD_ZERO(&s->active.rfd);