Ejemplo n.º 1
0
static struct ioloop_notify_handler_context *io_loop_notify_handler_init(void)
{
	struct ioloop_notify_handler_context *ctx;

	ctx = current_ioloop->notify_handler_context =
		i_new(struct ioloop_notify_handler_context, 1);
	ctx->kq = kqueue();
	if (ctx->kq < 0)
		i_fatal("kqueue(notify) failed: %m");
	fd_close_on_exec(ctx->kq, TRUE);
	return ctx;
}
Ejemplo n.º 2
0
int network_init()
{
	memset(g_fds, 0, sizeof(network_socket*) * MAXCLIENTS);
	g_kqueue = kqueue();
	if(g_kqueue == -1)
	{
		log_write(ERROR, "kqueue control fd could not be created. check your platform?");
		return -1;
	}

	return 0;
}
Ejemplo n.º 3
0
  void kqueue_monitor::initialize_kqueue()
  {
    if (kq != -1) throw libfsw_exception(_("kqueue already running."));

    kq = kqueue();

    if (kq == -1)
    {
      perror("kqueue()");
      throw libfsw_exception(_("kqueue failed."));
    }
  }
Ejemplo n.º 4
0
ATF_TC_BODY(file, tc)
{
	char buffer[128];
	struct kevent event[1];
	pid_t pid;
	int fd, kq, n, num, status;

	RL(pid = fork());
	if (pid == 0) {
		child();
		/* NOTREACHED */
	}

	RL(fd = open(FILENAME, O_RDONLY|O_CREAT, 0644));

#if 1		/* XXX: why was this disabled? */
	RL(lseek(fd, 0, SEEK_END));
#endif

	RL(kq = kqueue());

	EV_SET(&event[0], fd, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
	RL(kevent(kq, event, 1, NULL, 0, NULL));

	for (num = 0; num < NLINES;) {
		RL(n = kevent(kq, NULL, 0, event, 1, NULL));
		num += n;

		(void)printf("kevent num %d flags: %#x, fflags: %#x, data: "
#ifdef __FreeBSD__
		    "%" PRIdPTR "\n", n, event[0].flags, event[0].fflags,
#else
		    "%" PRId64 "\n", n, event[0].flags, event[0].fflags,
#endif
		    event[0].data);

		if (event[0].data < 0)
#if 1	/* XXXLUKEM */
			RL(lseek(fd, 0, SEEK_END));
#else
			RL(lseek(fd, event[0].data, SEEK_END));
#endif

		RL(n = read(fd, buffer, 128));
		buffer[n] = '\0';
		(void)printf("file(%d): %s", num, buffer);
	}

	(void)waitpid(pid, &status, 0);

	(void)printf("read: successful end\n");
}
Ejemplo n.º 5
0
static tb_void_t tb_aiop_rtor_kqueue_cler(tb_aiop_rtor_impl_t* rtor)
{
    tb_aiop_rtor_kqueue_impl_t* impl = (tb_aiop_rtor_kqueue_impl_t*)rtor;
    if (impl)
    {
        // close kqfd
        if (impl->kqfd >= 0)
        {
            close(impl->kqfd);
            impl->kqfd = kqueue();
        }
    }
}
Ejemplo n.º 6
0
/*
 * netio_init
 *
 * This is a needed exported function which will be called to initialise
 * the network loop code.
 */
void
netio_init(void)
{
  int fd;

  if ((fd = kqueue()) < 0)
  {
    ilog(LOG_TYPE_IRCD, "netio_init: couldn't open kqueue fd: %s", strerror(errno));
    exit(EXIT_FAILURE); /* Whee! */
  }

  fd_open(&kqfd, fd, 0, "kqueue() file descriptor");
}
Ejemplo n.º 7
0
static int fdevent_freebsd_kqueue_reset(fdevents * ev)
{
	if (-1 == (ev->kq_fd = kqueue()))
	{
		fprintf(stderr,
				"%s.%d: kqueue failed (%s), try to set server.event-handler = \"poll\" or \"select\"\n",
				__FILE__, __LINE__, strerror(errno));

		return -1;
	}

	return 0;
}
void inline_size
kqueue_fork (EV_P)
{
  close (backend_fd);

  while ((backend_fd = kqueue ()) < 0)
    ev_syserr ("(libev) kqueue");

  fcntl (backend_fd, F_SETFD, FD_CLOEXEC);

  /* re-register interest in fds */
  fd_rearm_all (EV_A);
}
Ejemplo n.º 9
0
/*
 * init_netio
 *
 * This is a needed exported function which will be called to initialise
 * the network loop code.
 */
void
init_netio(void)
{
  int fd;

  if ((fd = kqueue()) < 0)
  {
    ilog(LOG_TYPE_IRCD, "init_netio: Couldn't open kqueue fd!");
    exit(115); /* Whee! */
  }

  fd_open(&kqfd, fd, 0, "kqueue() file descriptor");
}
Ejemplo n.º 10
0
void
test_kqueue(void *unused)
{
    int kqfd;

    (void)unused;

    if ((kqfd = kqueue()) < 0)
        die("kqueue()");
    test_no_kevents(kqfd);
    if (close(kqfd) < 0)
        die("close()");
}
Ejemplo n.º 11
0
KQueueEngine::KQueueEngine(InspIRCd* Instance) : SocketEngine(Instance)
{
	EngineHandle = kqueue();
	if (EngineHandle == -1)
	{
		ServerInstance->Log(SPARSE,"ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
		ServerInstance->Log(SPARSE,"ERROR: this is a fatal error, exiting now.");
		printf("ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
		printf("ERROR: this is a fatal error, exiting now.");
		InspIRCd::Exit(ERROR);
	}
	CurrentSetSize = 0;
}
Ejemplo n.º 12
0
void
test_evfilt_user()
{
    kqfd = kqueue();

    add_and_delete();
    event_wait();
    disable_and_enable();
    oneshot();
    /* TODO: try different fflags operations */

    close(kqfd);
}
Ejemplo n.º 13
0
/*
 * init_netio
 *
 * This is a needed exported function which will be called to initialise
 * the network loop code.
 */
void
init_netio(void)
{
  if ((kq = kqueue()) < 0)
  {
    ilog(L_CRIT, "init_netio: Couldn't open kqueue fd!");
    exit(115); /* Whee! */
  }
  kqmax = getdtablesize();
  kqlst = MyMalloc(sizeof(struct kevent) * kqmax);
  zero_timespec.tv_sec = 0;
  zero_timespec.tv_nsec = 0;
}
Ejemplo n.º 14
0
void
sockinit(Handle f, void *x, int64 ns)
{
    tick = f;
    tickval = x;
    ival = ns;
    ivalts.tv_sec = ns / 1000000000;
    ivalts.tv_nsec = ns % 1000000000;
    kq = kqueue();
    if (kq == -1) {
        twarn("kqueue");
        exit(1);
    }
}
Ejemplo n.º 15
0
void wz_work()
{
	time_t last_clean_time = time(0);

	kQueue = kqueue();
	if (kQueue == -1)
	{
		log_error("Error creating kqueue: %s", strerror(errno));
		throw std::logic_error("error creating kqueue");
	}

	while (!doQuit && !doRestart)
	{
		struct timespec timeout = {5, 0};
		int r;

		r = kevent(kQueue, kChanges, nChanges, kChanges, aChanges, &timeout);
		nChanges = 0;

		if (r > 0)
		{
			struct kevent* ke = kChanges;
			int i;
			for (i = 0; i < r; i++, ke++)
			{
				if (ke->flags & EV_EOF)
				{
					watchEvent(ke->ident, EVFILT_READ, EV_DELETE, 0, 0);
					close(ke->ident);
					continue;
				}
				handle_event(ke->ident);
			}
		}
		else
		{
			if (r < 0 && errno != EINTR && errno != EAGAIN)
			{
				log_error("Strange error %s, %d", strerror(errno), errno);
			}
		}

		if (time(0) - last_clean_time > 5)
		{
			last_clean_time = clean_talkers();
			plugins.idle();
		}
	}

}
Ejemplo n.º 16
0
int Observer::initObserver() {
	int localFD = nodeNet->getNodeDescriptor();

	this->obsQueue = kqueue();
	EV_SET(&this->nodeEventSets, localFD,
			EVFILT_READ, EV_ADD, 0, 0, NULL);

	if (kevent(this->obsQueue, &this->nodeEventSets, 1, NULL, 0, NULL) < 0) {
		// error
		return FAILURE;
	}

	return SUCCESS;
}
Ejemplo n.º 17
0
_inline int InitSocketMultiplexing() {
	int smfd;

	#if defined(_USE_KQUEUE)
		smfd = kqueue();
	#elif defined(_USE_EPOLL)
		smfd = epoll_create(NUM_CONNS_PER_POOL);
	#elif defined(_USE_DEVPOLL)
		smfd = open("/dev/poll", O_RDWR));
		if (smfd < 0)
			return -1;
	#endif
	return smfd;
}
Ejemplo n.º 18
0
void _modinit(module_t *m)
{
	int kq;

	kq = kqueue();
	if (kq == -1)
	{
		m->mflags = MODTYPE_FAIL;
		return;
	}
	kq_conn = connection_add("procwatch kqueue", kq, 0, procwatch_readhandler, NULL);

	service_named_bind_command("operserv", &os_procwatch);
}
Ejemplo n.º 19
0
int kqueue_init(mspool *nsp) {
  struct kqueue_engine_info *kinfo;

  kinfo = (struct kqueue_engine_info *)safe_malloc(sizeof(struct kqueue_engine_info));

  kinfo->kqfd = kqueue();
  kinfo->maxfd = -1;
  kinfo->evlen = INITIAL_EV_COUNT;
  kinfo->events = (struct kevent *)safe_malloc(INITIAL_EV_COUNT * sizeof(struct kevent));

  nsp->engine_data = (void *)kinfo;

  return 1;
}
Ejemplo n.º 20
0
int kill_and_wait_sigchild(pid_t child_pid, int signal, uint32_t timeout_seconds) {
  if (kill(child_pid, signal) == -1)   { ERRMSG("kill() failed"); return -1; }

  int kq;
  if ((kq  = kqueue()) == -1) { ERRMSG("kqueue() failed"); return -1; }
  if (poll_add(kq, SIGCHLD, EVFILT_SIGNAL) == -1) { ERRMSG("poll_add() failed"); close(kq); return -1; }

  struct timespec timeout;
  timeout.tv_sec = timeout_seconds;
  timeout.tv_nsec = 0;
  if (kevent(kq, NULL, 0, NULL, 0, &timeout) == -1) { ERRMSG("kevent() failed"); close(kq); return -1; }
  close(kq);
  return 0;
}
Ejemplo n.º 21
0
Archivo: bsd.c Proyecto: abpin/kore
void
kore_platform_event_init(void)
{
	if ((kfd = kqueue()) == -1)
		fatal("kqueue(): %s", errno_s);

	nchanges = 0;
	event_count = worker_max_connections + 1;
	events = kore_calloc(event_count, sizeof(struct kevent));
	changelist = kore_calloc(event_count, sizeof(struct kevent));

	kore_platform_event_schedule(server.fd,
	    EVFILT_READ, EV_ADD | EV_DISABLE, &server);
}
Ejemplo n.º 22
0
int event_kqueue_reload(struct _fdevent *ev)
{
	int nfd;
	if ((nfd = dup(ev->kq_fd)) != -1) {
		close(nfd);
		close(ev->kq_fd);
	}

	if ((ev->kq_fd = kqueue()) == -1) {
		return 0;
	}
	
	return 1;	
}
Ejemplo n.º 23
0
static int iv_fd_kqueue_init(struct iv_state *st)
{
	int kqueue_fd;

	kqueue_fd = kqueue();
	if (kqueue_fd < 0)
		return -1;

	iv_fd_set_cloexec(kqueue_fd);

	st->u.kqueue.kqueue_fd = kqueue_fd;
	INIT_IV_LIST_HEAD(&st->u.kqueue.notify);

	return 0;
}
Ejemplo n.º 24
0
	BSDDirectoryWatcherStrategy(DirectoryWatcher& owner):
		DirectoryWatcherStrategy(owner),
		_queueFD(-1),
		_dirFD(-1),
		_stopped(false)
	{
		_dirFD = open(owner.directory().path().c_str(), O_EVTONLY);
		if (_dirFD < 0) throw Poco::FileNotFoundException(owner.directory().path());
		_queueFD = kqueue();
		if (_queueFD < 0)
		{
			close(_dirFD);
			throw Poco::SystemException("Cannot create kqueue", errno);
		}
	}
Ejemplo n.º 25
0
static gpointer
tp_kqueue_init (SocketIOData *data)
{
    tp_kqueue_data *result;

    result = g_new0 (tp_kqueue_data, 1);
    result->fd = kqueue ();
    if (result->fd == -1)
        return NULL;

    data->shutdown = tp_kqueue_shutdown;
    data->modify = tp_kqueue_modify;
    data->wait = tp_kqueue_wait;
    return result;
}
Ejemplo n.º 26
0
KeyHashtableTimeout::KeyHashtableTimeout(HashTable *_keyHashtable, int _timeout) {
	if (! _keyHashtable) {
		systemLog->sysLog(CRITICAL, "keyHashtable is NULL, something is terribly wrong");
		return;
	}
	kQueue = kqueue();
	if (kQueue < 0) {
		systemLog->sysLog(CRITICAL, "cannot initialize kQueue for KeyHashtableTimeout object: %s", strerror(errno));
		return;
	}
	timeout = _timeout;
	keyHashtable = _keyHashtable;

	return;
}
Ejemplo n.º 27
0
ATF_TC_BODY(pipe1, tc)
{
	struct kevent event[1];
	int fds[2];
	int kq, n;

	RL(pipe(fds));
	RL(kq = kqueue());
	RL(close(fds[0]));

	EV_SET(&event[0], fds[1], EVFILT_WRITE, EV_ADD|EV_ENABLE, 0, 0, 0);
	ATF_REQUIRE_EQ_MSG((n = kevent(kq, event, 1, NULL, 0, NULL)),
	    -1, "got: %d", n);
	ATF_REQUIRE_EQ_MSG(errno, EBADF, "got: %s", strerror(errno));
}
Ejemplo n.º 28
0
Archivo: com.c Proyecto: iwaim/groonga
grn_rc
grn_com_event_init(grn_ctx *ctx, grn_com_event *ev, int max_nevents, int data_size)
{
    ev->max_nevents = max_nevents;
    if ((ev->hash = grn_hash_create(ctx, NULL, sizeof(grn_sock), data_size, 0))) {
        MUTEX_INIT(ev->mutex);
        COND_INIT(ev->cond);
        GRN_COM_QUEUE_INIT(&ev->recv_old);
        ev->msg_handler = NULL;
        memset(&(ev->curr_edge_id), 0, sizeof(grn_com_addr));
        ev->acceptor = NULL;
        ev->opaque = NULL;
#ifndef USE_SELECT
# ifdef USE_EPOLL
        if ((ev->events = GRN_MALLOC(sizeof(struct epoll_event) * max_nevents))) {
            if ((ev->epfd = epoll_create(max_nevents)) != -1) {
                goto exit;
            } else {
                SERR("epoll_create");
            }
            GRN_FREE(ev->events);
        }
# else /* USE_EPOLL */
#  ifdef USE_KQUEUE
        if ((ev->events = GRN_MALLOC(sizeof(struct kevent) * max_nevents))) {
            if ((ev->kqfd = kqueue()) != -1) {
                goto exit;
            } else {
                SERR("kqueue");
            }
            GRN_FREE(ev->events);
        }
#  else /* USE_KQUEUE */
        if ((ev->events = GRN_MALLOC(sizeof(struct pollfd) * max_nevents))) {
            goto exit;
        }
#  endif /* USE_KQUEUE*/
# endif /* USE_EPOLL */
        grn_hash_close(ctx, ev->hash);
        ev->hash = NULL;
        ev->events = NULL;
#else /* USE_SELECT */
        goto exit;
#endif /* USE_SELECT */
    }
exit :
    return ctx->rc;
}
Ejemplo n.º 29
0
/* setup buffers for kqueue */
void ir_kqueue_init(void)
{
  ir_kqueue_change_size = 0;
  ir_kqueue_event_max = 64;
  FD_ZERO(&ir_kqueue_readset);
  FD_ZERO(&ir_kqueue_writeset);

  ir_kqueue_fd = kqueue ();
  if (ir_kqueue_fd < 0) {
    fprintf(stderr, "Failed to start kqueue()\n");
    ir_kqueue_fd = FD_UNUSED;
  } else {
    fcntl(ir_kqueue_fd, F_SETFD, FD_CLOEXEC);
    ir_kqueue_set_buffer();
  }
}
Ejemplo n.º 30
0
QT_BEGIN_NAMESPACE

// #define KEVENT_DEBUG
#ifdef KEVENT_DEBUG
#  define DEBUG qDebug
#else
#  define DEBUG if(false)qDebug
#endif

QKqueueFileSystemWatcherEngine *QKqueueFileSystemWatcherEngine::create()
{
    int kqfd = kqueue();
    if (kqfd == -1)
        return 0;
    return new QKqueueFileSystemWatcherEngine(kqfd);
}