Select Git revision
string-malloc.c
backend.c 5.52 KiB
/*\
||| This file a part of Pike, and is copyright by Fredrik Hubinette
||| Pike is distributed as GPL (General Public License)
||| See the files COPYING and DISCLAIMER for more information.
\*/
#include "global.h"
RCSID("$Id: backend.c,v 1.8 1997/01/26 22:47:03 per Exp $");
#include "backend.h"
#include <errno.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <sys/param.h>
#include <string.h>
#include "interpret.h"
#include "object.h"
#include "types.h"
#include "error.h"
#include "fd_control.h"
#include "main.h"
#include "callback.h"
#include "threads.h"
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#define SELECT_READ 1
#define SELECT_WRITE 2
struct selectors
{
fd_set read;
fd_set write;
};
static struct selectors selectors;
file_callback read_callback[MAX_OPEN_FILEDESCRIPTORS];
void *read_callback_data[MAX_OPEN_FILEDESCRIPTORS];
file_callback write_callback[MAX_OPEN_FILEDESCRIPTORS];
void *write_callback_data[MAX_OPEN_FILEDESCRIPTORS];
static int max_fd;
struct timeval current_time;
struct timeval next_timeout;
static struct callback_list backend_callbacks;
struct callback *add_backend_callback(callback_func call,
void *arg,
callback_func free_func)
{
return add_to_callback(&backend_callbacks, call, arg, free_func);
}
void init_backend()
{
FD_ZERO(&selectors.read);
FD_ZERO(&selectors.write);
}
void set_read_callback(int fd,file_callback cb,void *data)
{
#ifdef DEBUG
if(fd<0 || fd>=MAX_OPEN_FILEDESCRIPTORS)
fatal("File descriptor out of range.\n %d",fd);
#endif
read_callback[fd]=cb;