added timer and enhanced httpd to use timer for idling detection
This commit is contained in:
@ -41,6 +41,7 @@ pkginclude_HEADERS = \
|
||||
task.h \
|
||||
time.h \
|
||||
tio.h \
|
||||
tmr.h \
|
||||
tre.h \
|
||||
uni.h \
|
||||
uri.h \
|
||||
|
@ -85,8 +85,8 @@ am__pkginclude_HEADERS_DIST = alg.h chr.h cp949.h cp950.h dir.h dll.h \
|
||||
env.h fio.h fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h \
|
||||
lda.h main.h map.h mb8.h mbwc.h mem.h mux.h nwad.h nwif.h \
|
||||
nwio.h oht.h opt.h path.h pio.h pma.h rbt.h rex.h sio.h sll.h \
|
||||
slmb.h str.h task.h time.h tio.h tre.h uni.h uri.h utf8.h \
|
||||
xma.h Mmgr.hpp StdMmgr.hpp Mmged.hpp
|
||||
slmb.h str.h task.h time.h tio.h tmr.h tre.h uni.h uri.h \
|
||||
utf8.h xma.h Mmgr.hpp StdMmgr.hpp Mmged.hpp
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
@ -299,7 +299,7 @@ pkginclude_HEADERS = alg.h chr.h cp949.h cp950.h dir.h dll.h env.h \
|
||||
fio.h fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h lda.h \
|
||||
main.h map.h mb8.h mbwc.h mem.h mux.h nwad.h nwif.h nwio.h \
|
||||
oht.h opt.h path.h pio.h pma.h rbt.h rex.h sio.h sll.h slmb.h \
|
||||
str.h task.h time.h tio.h tre.h uni.h uri.h utf8.h xma.h \
|
||||
str.h task.h time.h tio.h tmr.h tre.h uni.h uri.h utf8.h xma.h \
|
||||
$(am__append_1)
|
||||
all: all-am
|
||||
|
||||
|
@ -110,7 +110,7 @@ struct qse_btime_t
|
||||
/*int offset;*/
|
||||
};
|
||||
|
||||
#define qse_cleartime(x) ((x)->tv = (x)->nsec = 0);
|
||||
#define qse_cleartime(x) ((x)->sec = (x)->nsec = 0);
|
||||
#define qse_cmptime(x,y) \
|
||||
(((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): \
|
||||
((x)->sec - (y)->sec))
|
||||
|
133
qse/include/qse/cmn/tmr.h
Normal file
133
qse/include/qse/cmn/tmr.h
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2014 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
||||
QSE is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
QSE is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_TMR_H_
|
||||
#define _QSE_CMN_TMR_H_
|
||||
|
||||
#include <qse/cmn/time.h>
|
||||
|
||||
typedef struct qse_tmr_t qse_tmr_t;
|
||||
typedef struct qse_tmr_event_t qse_tmr_event_t;
|
||||
|
||||
typedef void (*qse_tmr_handler_t) (
|
||||
qse_tmr_t* tmr,
|
||||
const qse_ntime_t* now,
|
||||
void* ctx
|
||||
);
|
||||
|
||||
typedef void (*qse_tmr_updater_t) (
|
||||
qse_tmr_t* tmr,
|
||||
qse_size_t old_index,
|
||||
qse_size_t new_index,
|
||||
void* ctx
|
||||
);
|
||||
|
||||
struct qse_tmr_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
qse_size_t capa;
|
||||
qse_size_t size;
|
||||
qse_tmr_event_t* event;
|
||||
};
|
||||
|
||||
struct qse_tmr_event_t
|
||||
{
|
||||
qse_ntime_t when;
|
||||
void* ctx;
|
||||
qse_tmr_handler_t handler;
|
||||
qse_tmr_updater_t updater;
|
||||
};
|
||||
|
||||
#define QSE_TMR_INVALID ((qse_size_t)-1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
QSE_EXPORT qse_tmr_t* qse_tmr_open (
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t xtnsize,
|
||||
qse_size_t capa
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_tmr_close (
|
||||
qse_tmr_t* tmr
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_tmr_init (
|
||||
qse_tmr_t* tmr,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t capa
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_tmr_fini (
|
||||
qse_tmr_t* tmr
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_mmgr_t* qse_tmr_getmmgr (
|
||||
qse_tmr_t* tmr
|
||||
);
|
||||
|
||||
QSE_EXPORT void* qse_tmr_getxtn (
|
||||
qse_tmr_t* tmr
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_tmr_clear (
|
||||
qse_tmr_t* tmr
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_tmr_insert() function schedules a new event.
|
||||
*
|
||||
* \return #QSE_TMR_INVALID on failure, valid index on success.
|
||||
*/
|
||||
|
||||
QSE_EXPORT qse_size_t qse_tmr_insert (
|
||||
qse_tmr_t* tmr,
|
||||
const qse_tmr_event_t* event
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_size_t qse_tmr_update (
|
||||
qse_tmr_t* tmr,
|
||||
qse_size_t index,
|
||||
const qse_tmr_event_t* event
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_tmr_remove (
|
||||
qse_tmr_t* tmr,
|
||||
qse_size_t index
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_size_t qse_tmr_fire (
|
||||
qse_tmr_t* tmr,
|
||||
const qse_ntime_t* tm
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_tmr_gettmout (
|
||||
qse_tmr_t* tmr,
|
||||
const qse_ntime_t* tm,
|
||||
qse_ntime_t* tmout
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -27,6 +27,7 @@
|
||||
#include <qse/http/htrd.h>
|
||||
#include <qse/cmn/nwad.h>
|
||||
#include <qse/cmn/time.h>
|
||||
#include <qse/cmn/tmr.h>
|
||||
|
||||
typedef struct qse_httpd_t qse_httpd_t;
|
||||
typedef struct qse_httpd_mate_t qse_httpd_mate_t;
|
||||
@ -421,6 +422,9 @@ struct qse_httpd_client_t
|
||||
qse_httpd_task_trigger_t trigger;
|
||||
qse_ntime_t last_active;
|
||||
|
||||
qse_size_t tmr_idle;
|
||||
qse_size_t tmr_dns;
|
||||
|
||||
qse_httpd_client_t* prev;
|
||||
qse_httpd_client_t* next;
|
||||
|
||||
@ -468,6 +472,7 @@ struct qse_httpd_server_t
|
||||
qse_ubi_t handle;
|
||||
|
||||
/* private */
|
||||
qse_httpd_t* httpd;
|
||||
qse_httpd_server_t* next;
|
||||
qse_httpd_server_t* prev;
|
||||
};
|
||||
|
Reference in New Issue
Block a user