2019-01-29 16:57:16 +00:00
|
|
|
/*
|
2020-02-20 15:35:16 +00:00
|
|
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
2019-01-29 16:57:16 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
2022-06-11 05:32:01 +00:00
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
2019-01-29 16:57:16 +00:00
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
#ifndef _HIO_SYS_PRV_H_
|
|
|
|
#define _HIO_SYS_PRV_H_
|
2019-01-29 16:57:16 +00:00
|
|
|
|
2019-01-30 10:18:58 +00:00
|
|
|
/* this is a private header file used by sys-XXX files */
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
#include "hio-prv.h"
|
2019-01-29 16:57:16 +00:00
|
|
|
|
2021-07-24 15:23:55 +00:00
|
|
|
#if defined(HAVE_SYS_EVENT_H) && defined(HAVE_KQUEUE) && defined(HAVE_KEVENT)
|
2022-06-22 06:44:28 +00:00
|
|
|
# include <sys/types.h>
|
2021-07-24 15:23:55 +00:00
|
|
|
# include <sys/event.h>
|
|
|
|
# define USE_KQUEUE
|
2021-07-25 14:16:04 +00:00
|
|
|
#elif defined(HAVE_SYS_EPOLL_H)
|
2019-01-29 16:57:16 +00:00
|
|
|
# include <sys/epoll.h>
|
|
|
|
# define USE_EPOLL
|
|
|
|
#elif defined(HAVE_SYS_POLL_H)
|
|
|
|
# include <sys/poll.h>
|
|
|
|
# define USE_POLL
|
|
|
|
#else
|
|
|
|
# error NO SUPPORTED MULTIPLEXER
|
|
|
|
#endif
|
|
|
|
|
2021-07-17 15:17:07 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2019-01-29 16:57:16 +00:00
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#if defined(USE_POLL)
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
struct hio_sys_mux_t
|
2019-01-29 16:57:16 +00:00
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t* ptr;
|
|
|
|
hio_oow_t size;
|
|
|
|
hio_oow_t capa;
|
2019-01-29 16:57:16 +00:00
|
|
|
} map; /* handle to index */
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct pollfd* pfd;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_dev_t** dptr;
|
|
|
|
hio_oow_t size;
|
|
|
|
hio_oow_t capa;
|
2019-01-29 16:57:16 +00:00
|
|
|
} pd; /* poll data */
|
2021-07-17 17:21:38 +00:00
|
|
|
|
|
|
|
int ctrlp[2];
|
2019-01-29 16:57:16 +00:00
|
|
|
};
|
|
|
|
|
2021-07-24 15:23:55 +00:00
|
|
|
#elif defined(USE_KQUEUE)
|
|
|
|
|
2021-07-25 17:52:05 +00:00
|
|
|
struct hio_sys_mux_t
|
2021-07-24 15:23:55 +00:00
|
|
|
{
|
|
|
|
int kq;
|
|
|
|
|
|
|
|
struct kevent revs[1024]; /* TODO: is it a good size? */
|
2023-01-11 14:59:41 +00:00
|
|
|
|
2021-07-24 15:23:55 +00:00
|
|
|
int ctrlp[2];
|
|
|
|
};
|
2021-07-25 17:52:05 +00:00
|
|
|
|
2019-01-29 16:57:16 +00:00
|
|
|
#elif defined(USE_EPOLL)
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
struct hio_sys_mux_t
|
2019-01-29 16:57:16 +00:00
|
|
|
{
|
|
|
|
int hnd;
|
2020-07-24 17:29:52 +00:00
|
|
|
struct epoll_event revs[1024]; /* TODO: is it a good size? */
|
2021-07-17 17:21:38 +00:00
|
|
|
|
|
|
|
int ctrlp[2];
|
2019-01-29 16:57:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
typedef struct hio_sys_mux_t hio_sys_mux_t;
|
2019-01-29 16:57:16 +00:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
struct hio_sys_log_t
|
2019-01-29 16:57:16 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int fd_flag; /* bitwise OR'ed of logfd_flag_t bits */
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_bch_t buf[4096];
|
|
|
|
hio_oow_t len;
|
2019-01-29 16:57:16 +00:00
|
|
|
} out;
|
2021-07-17 15:17:07 +00:00
|
|
|
|
|
|
|
pthread_mutex_t mtx;
|
2019-01-29 16:57:16 +00:00
|
|
|
};
|
2021-07-22 07:30:20 +00:00
|
|
|
typedef struct hio_sys_log_t hio_sys_log_t;
|
2019-01-29 16:57:16 +00:00
|
|
|
|
2019-01-30 10:18:58 +00:00
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
struct hio_sys_time_t
|
2019-01-30 10:18:58 +00:00
|
|
|
{
|
|
|
|
#if defined(_WIN32)
|
|
|
|
HANDLE waitable_timer;
|
|
|
|
DWORD tc_last;
|
|
|
|
DWORD tc_overflow;
|
|
|
|
#elif defined(__OS2__)
|
|
|
|
ULONG tc_last;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_ntime_t tc_last_ret;
|
2019-01-30 10:18:58 +00:00
|
|
|
#elif defined(__DOS__)
|
|
|
|
clock_t tc_last;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_ntime_t tc_last_ret;
|
2019-01-30 10:18:58 +00:00
|
|
|
#else
|
|
|
|
/* nothing */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
typedef struct hio_sys_time_t hio_sys_time_t;
|
2019-01-30 10:18:58 +00:00
|
|
|
|
2019-01-29 16:57:16 +00:00
|
|
|
/* -------------------------------------------------------------------------- */
|
2021-07-22 07:30:20 +00:00
|
|
|
struct hio_sys_t
|
2019-01-29 16:57:16 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_sys_log_t log;
|
|
|
|
hio_sys_mux_t mux;
|
|
|
|
hio_sys_time_t time;
|
2019-01-29 16:57:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
int hio_sys_initlog (
|
|
|
|
hio_t* hio
|
2019-01-29 16:57:16 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_sys_finilog (
|
|
|
|
hio_t* hio
|
2019-01-29 16:57:16 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
int hio_sys_initmux (
|
|
|
|
hio_t* hio
|
2019-01-29 16:57:16 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_sys_finimux (
|
|
|
|
hio_t* hio
|
2019-01-29 16:57:16 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
int hio_sys_inittime (
|
|
|
|
hio_t* hio
|
2019-01-30 10:18:58 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_sys_finitime (
|
|
|
|
hio_t* hio
|
2019-01-30 10:18:58 +00:00
|
|
|
);
|
2019-01-29 16:57:16 +00:00
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|