<commit_before>/*
 * Copyright (c) 1995-2003, Index Data
 * See the file LICENSE for details.
 * <NAME>, <NAME>
 *
 * $Id: eventl.c,v 1.37 2003-02-18 11:59:14 adam Exp $
 */

#include <stdio.h>
#include <assert.h>
#ifdef WIN32
#include <winsock.h>
#else
#include <unistd.h>
#endif
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#include <yaz/yconfig.h>
#include <yaz/log.h>
#include <yaz/comstack.h>
#include <yaz/xmalloc.h>
#include "eventl.h"
#include "session.h"
#include <yaz/statserv.h>

#if YAZ_GNU_THREADS
#include <pth.h>
#define YAZ_EV_SELECT pth_select
#endif

#ifndef YAZ_EV_SELECT
#define YAZ_EV_SELECT select
#endif

IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
{
    IOCHAN new_iochan;

    if (!(new_iochan = (IOCHAN)xmalloc(sizeof(*new_iochan))))
    	return 0;
    new_iochan->destroyed = 0;
    new_iochan->fd = fd;
    new_iochan->flags = flags;
    new_iochan->fun = cb;
    new_iochan->force_event = 0;
    new_iochan->last_event = new_iochan->max_idle = 0;
    new_iochan->next = NULL;
    return new_iochan;
}

int event_loop(IOCHAN *iochans)
{
    do /* loop as long as there are active associations to process */
    {
    	IOCHAN p, nextp;
	fd_set in, out, except;
	int res, max;
	static struct timeval to;
        time_t now = time(0);

        if (statserv_must_terminate())
        {
            for (p = *iochans; p; p = p->next)
                p->force_event = EVENT_TIMEOUT;
        }
	FD_ZERO(&in);
	FD_ZERO(&out);
	FD_ZERO(&except);
	to.tv_sec = 3600;
	to.tv_usec = 1;
	max = 0;
    	for (p = *iochans; p; p = p->next)
    	{
            time_t w, ftime;
            yaz_log(LOG_DEBUG, "fd=%d flags=%d force_event=%d",
                    p->fd, p->flags, p->force_event);
	    if (p->force_event)
                to.tv_sec = 0;          /* polling select */
	    if (p->flags & EVENT_INPUT)
		FD_SET(p->fd, &in);<commit_msg>Improve net I/O performance for server.<commit_after>/*
 * Copyright (c) 1995-2003, Index Data
 * See the file LICENSE for details.
 * <NAME>, <NAME>
 *
 * $Id: eventl.c,v 1.38 2003-02-20 15:13:28 adam Exp $
 */

#include <stdio.h>
#include <assert.h>
#ifdef WIN32
#include <winsock.h>
#else
#include <unistd.h>
#endif
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#include <yaz/yconfig.h>
#include <yaz/log.h>
#include <yaz/comstack.h>
#include <yaz/xmalloc.h>
#include "eventl.h"
#include "session.h"
#include <yaz/statserv.h>

#if YAZ_GNU_THREADS
#include <pth.h>
#define YAZ_EV_SELECT pth_select
#endif

#ifndef YAZ_EV_SELECT
#define YAZ_EV_SELECT select
#endif

IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
{
    IOCHAN new_iochan;

    if (!(new_iochan = (IOCHAN)xmalloc(sizeof(*new_iochan))))
    	return 0;
    new_iochan->destroyed = 0;
    new_iochan->fd = fd;
    new_iochan->flags = flags;
    new_iochan->fun = cb;
    new_iochan->force_event = 0;
    new_iochan->last_event = new_iochan->max_idle = 0;
    new_iochan->next = NULL;
    return new_iochan;
}

int event_loop(IOCHAN *iochans)
{
    do /* loop as long as there are active associations to process */
    {
    	IOCHAN p, nextp;
	fd_set in, out, except;
	int res, max;
	static struct timeval to;
        time_t now = time(0);

        if (statserv_must_terminate())
        {
            for (p = *iochans; p; p = p->next)
                p->force_event = EVENT_TIMEOUT;
        }
	FD_ZERO(&in);
	FD_ZERO(&out);
	FD_ZERO(&except);
	to.tv_sec = 3600;
	to.tv_usec = 0;
	max = 0;
    	for (p = *iochans; p; p = p->next)
    	{
            time_t w, ftime;
            yaz_log(LOG_DEBUG, "fd=%d flags=%d force_event=%d",
                    p->fd, p->flags, p->force_event);
	    if (p->force_event)
                to.tv_sec = 0;          /* polling select */
	    if (p->flags & EVENT_INPUT)
		FD_SET(p->fd, &in);
{'fraction_non_alphanumeric': 0.14541622760800843, 'fraction_numerical': 0.02054794520547945, 'mean_word_length': 2.797, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6910734', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1520, 'n_words': 354}