hio/hio/lib/sys-prv.h

165 lines
3.4 KiB
C
Raw Normal View History

2019-01-29 16:57:16 +00:00
/*
* $Id$
*
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
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAfRRANTIES
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
/* 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
#if defined(HAVE_SYS_EPOLL_H)
# 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 */
int ctrlp[2];
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;
struct epoll_event revs[1024]; /* TODO: is it a good size? */
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
/* -------------------------------------------------------------------------- */
2021-07-22 07:30:20 +00:00
struct hio_sys_time_t
{
#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;
#elif defined(__DOS__)
clock_t tc_last;
2021-07-22 07:30:20 +00:00
hio_ntime_t tc_last_ret;
#else
/* nothing */
#endif
};
2021-07-22 07:30:20 +00:00
typedef struct hio_sys_time_t hio_sys_time_t;
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
);
2021-07-22 07:30:20 +00:00
void hio_sys_finitime (
hio_t* hio
);
2019-01-29 16:57:16 +00:00
#if defined(__cplusplus)
}
#endif
#endif