create a task list in the htts service
This commit is contained in:
parent
97133f8c12
commit
d9cadf0793
@ -91,6 +91,8 @@ typedef void (*hio_svc_htts_rsrc_on_kill_t) (
|
|||||||
hio_svc_htts_t* htts; \
|
hio_svc_htts_t* htts; \
|
||||||
hio_oow_t rsrc_size; \
|
hio_oow_t rsrc_size; \
|
||||||
hio_oow_t rsrc_refcnt; \
|
hio_oow_t rsrc_refcnt; \
|
||||||
|
hio_svc_htts_rsrc_t* task_prev; \
|
||||||
|
hio_svc_htts_rsrc_t* task_next; \
|
||||||
hio_svc_htts_rsrc_on_kill_t rsrc_on_kill
|
hio_svc_htts_rsrc_on_kill_t rsrc_on_kill
|
||||||
|
|
||||||
struct hio_svc_htts_rsrc_t
|
struct hio_svc_htts_rsrc_t
|
||||||
|
@ -72,6 +72,7 @@ struct hio_svc_htts_t
|
|||||||
hio_svc_fcgic_t* fcgic;
|
hio_svc_fcgic_t* fcgic;
|
||||||
|
|
||||||
hio_svc_htts_cli_t cli; /* list head for client list */
|
hio_svc_htts_cli_t cli; /* list head for client list */
|
||||||
|
hio_svc_htts_rsrc_t task; /* list head for task list */
|
||||||
hio_tmridx_t idle_tmridx;
|
hio_tmridx_t idle_tmridx;
|
||||||
|
|
||||||
hio_bch_t* server_name;
|
hio_bch_t* server_name;
|
||||||
@ -109,4 +110,31 @@ struct hio_svc_httc_t
|
|||||||
#define HIO_SVC_HTTS_CLIL_IS_EMPTY(lh) (HIO_SVC_HTTS_CLIL_FIRST_CLI(lh) == (lh))
|
#define HIO_SVC_HTTS_CLIL_IS_EMPTY(lh) (HIO_SVC_HTTS_CLIL_FIRST_CLI(lh) == (lh))
|
||||||
#define HIO_SVC_HTTS_CLIL_IS_NIL_CLI(lh,cli) ((cli) == (lh))
|
#define HIO_SVC_HTTS_CLIL_IS_NIL_CLI(lh,cli) ((cli) == (lh))
|
||||||
|
|
||||||
|
|
||||||
|
/* task list */
|
||||||
|
#define HIO_SVC_HTTS_TASKL_APPEND_TASK(lh,task) do { \
|
||||||
|
(task)->task_next = (lh); \
|
||||||
|
(task)->task_prev = (lh)->task_prev; \
|
||||||
|
(task)->task_prev->task_next = (task); \
|
||||||
|
(lh)->task_prev = (task); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#define HIO_SVC_HTTS_TASKL_UNLINK_TASK(task) do { \
|
||||||
|
(task)->task_prev->task_next = (task)->task_next; \
|
||||||
|
(task)->task_next->task_prev = (task)->task_prev; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define HIO_SVC_HTTS_TASKL_UNLINK_TASK_CLEAN(task) do { \
|
||||||
|
(task)->task_prev->task_next = (task)->task_next; \
|
||||||
|
(task)->task_next->task_prev = (task)->task_prev; \
|
||||||
|
(task)->task_prev = (task); \
|
||||||
|
(task)->task_next = (task); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define HIO_SVC_HTTS_TASKL_INIT(lh) ((lh)->task_next = (lh)->task_prev = lh)
|
||||||
|
#define HIO_SVC_HTTS_TASKL_FIRST_TASK(lh) ((lh)->task_next)
|
||||||
|
#define HIO_SVC_HTTS_TASKL_LAST_TASK(lh) ((lh)->task_prev)
|
||||||
|
#define HIO_SVC_HTTS_TASKL_IS_EMPTY(lh) (HIO_SVC_HTTS_TASKL_FIRST_TASK(lh) == (lh))
|
||||||
|
#define HIO_SVC_HTTS_TASKL_IS_NIL_TASK(lh,task) ((task) == (lh))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -466,6 +466,7 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_oow_t xtnsize, hio_dev_sck_b
|
|||||||
|
|
||||||
HIO_SVCL_APPEND_SVC (&hio->actsvc, (hio_svc_t*)htts);
|
HIO_SVCL_APPEND_SVC (&hio->actsvc, (hio_svc_t*)htts);
|
||||||
HIO_SVC_HTTS_CLIL_INIT (&htts->cli);
|
HIO_SVC_HTTS_CLIL_INIT (&htts->cli);
|
||||||
|
HIO_SVC_HTTS_TASKL_INIT (&htts->task);
|
||||||
|
|
||||||
htts->fcgic = hio_svc_fcgic_start(hio, HIO_NULL); /* TODO: set timeout properly */
|
htts->fcgic = hio_svc_fcgic_start(hio, HIO_NULL); /* TODO: set timeout properly */
|
||||||
if (HIO_UNLIKELY(!htts->fcgic))
|
if (HIO_UNLIKELY(!htts->fcgic))
|
||||||
@ -538,12 +539,11 @@ void hio_svc_htts_stop (hio_svc_htts_t* htts)
|
|||||||
hio_dev_sck_kill (cli->sck);
|
hio_dev_sck_kill (cli->sck);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
while (!HIO_SVC_HTTS_TASKL_IS_EMPTY(&htts->task))
|
while (!HIO_SVC_HTTS_TASKL_IS_EMPTY(&htts->task))
|
||||||
{
|
{
|
||||||
|
hio_svc_htts_rsrc_t* task = HIO_SVC_HTTS_TASKL_FIRST_TASK(&htts->task);
|
||||||
|
hio_svc_htts_rsrc_kill (task);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
HIO_SVCL_UNLINK_SVC (htts);
|
HIO_SVCL_UNLINK_SVC (htts);
|
||||||
if (htts->server_name && htts->server_name != htts->server_name_buf) hio_freemem (hio, htts->server_name);
|
if (htts->server_name && htts->server_name != htts->server_name_buf) hio_freemem (hio, htts->server_name);
|
||||||
|
@ -49,6 +49,7 @@ typedef enum THR_TASK_RES_mode_t THR_TASK_RES_mode_t;
|
|||||||
|
|
||||||
struct thr_func_start_t
|
struct thr_func_start_t
|
||||||
{
|
{
|
||||||
|
hio_t* hio; /* for faster and safer access in case htts has been already destroyed */
|
||||||
hio_svc_htts_t* htts;
|
hio_svc_htts_t* htts;
|
||||||
hio_svc_htts_thr_func_t thr_func;
|
hio_svc_htts_thr_func_t thr_func;
|
||||||
void* thr_ctx;
|
void* thr_ctx;
|
||||||
@ -310,7 +311,7 @@ static void thr_task_on_kill (hio_svc_htts_rsrc_t* rsrc)
|
|||||||
thr_task->client_org_on_disconnect = HIO_NULL;
|
thr_task->client_org_on_disconnect = HIO_NULL;
|
||||||
thr_task->client_htrd_recbs_changed = 0;
|
thr_task->client_htrd_recbs_changed = 0;
|
||||||
|
|
||||||
/////HIO_SVC_HTTS_TASKL_UNLINK_CLI (thr_task); /* detached from the htts service */
|
HIO_SVC_HTTS_TASKL_UNLINK_TASK (thr_task); /* detach from the htts service */
|
||||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - killed the task\n", thr_task->htts, thr_task, thr_task->client, (thr_task->csck? thr_task->csck->hnd: -1), thr_task->peer);
|
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - killed the task\n", thr_task->htts, thr_task, thr_task->client, (thr_task->csck? thr_task->csck->hnd: -1), thr_task->peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -800,8 +801,32 @@ oops:
|
|||||||
|
|
||||||
static void free_thr_start_info (void* ctx)
|
static void free_thr_start_info (void* ctx)
|
||||||
{
|
{
|
||||||
|
/* this function is a thread cleanup handler.
|
||||||
|
* it can get invoked after htts is destroyed by hio_svc_htts_stop() because
|
||||||
|
* hio_dev_thr_kill() pushes back the job using hio_addcfmb() and the
|
||||||
|
* actual cfmb clean-up is performed after the service stop.
|
||||||
|
* it is not realiable to use tfs->htts or tfs->htts->hio. use tfs->hio only here.
|
||||||
|
==3845396== Invalid read of size 8
|
||||||
|
==3845396== at 0x40A7D5: free_thr_start_info (http-thr.c:804)
|
||||||
|
==3845396== by 0x40A7D5: thr_func (http-thr.c:815)
|
||||||
|
==3845396== by 0x41AE46: run_thr_func (thr.c:127)
|
||||||
|
==3845396== by 0x4A132A4: start_thread (in /usr/lib64/libpthread-2.33.so)
|
||||||
|
==3845396== by 0x4B2B322: clone (in /usr/lib64/libc-2.33.so)
|
||||||
|
==3845396== Address 0x4c38b00 is 0 bytes inside a block of size 464 free'd
|
||||||
|
==3845396== at 0x48430E4: free (vg_replace_malloc.c:872)
|
||||||
|
==3845396== by 0x4091EE: hio_svc_htts_stop (http-svr.c:555)
|
||||||
|
==3845396== by 0x40F5BE: hio_fini (hio.c:185)
|
||||||
|
==3845396== by 0x40F848: hio_close (hio.c:101)
|
||||||
|
==3845396== by 0x402CB4: main (webs.c:511)
|
||||||
|
==3845396== Block was alloc'd at
|
||||||
|
==3845396== at 0x484086F: malloc (vg_replace_malloc.c:381)
|
||||||
|
==3845396== by 0x412873: hio_callocmem (hio.c:2019)
|
||||||
|
==3845396== by 0x40978E: hio_svc_htts_start (http-svr.c:350)
|
||||||
|
==3845396== by 0x403900: webs_start (webs.c:385)
|
||||||
|
==3845396== by 0x402C6C: main (webs.c:498)
|
||||||
|
*/
|
||||||
thr_func_start_t* tfs = (thr_func_start_t*)ctx;
|
thr_func_start_t* tfs = (thr_func_start_t*)ctx;
|
||||||
hio_t* hio = tfs->htts->hio;
|
hio_t* hio = tfs->hio;
|
||||||
if (tfs->tfi.req_path) hio_freemem (hio, tfs->tfi.req_path);
|
if (tfs->tfi.req_path) hio_freemem (hio, tfs->tfi.req_path);
|
||||||
if (tfs->tfi.req_param) hio_freemem (hio, tfs->tfi.req_param);
|
if (tfs->tfi.req_param) hio_freemem (hio, tfs->tfi.req_param);
|
||||||
hio_freemem (hio, tfs);
|
hio_freemem (hio, tfs);
|
||||||
@ -858,6 +883,7 @@ int hio_svc_htts_dothr (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
|
|||||||
tfs = hio_callocmem(hio, HIO_SIZEOF(*tfs));
|
tfs = hio_callocmem(hio, HIO_SIZEOF(*tfs));
|
||||||
if (!tfs) goto oops;
|
if (!tfs) goto oops;
|
||||||
|
|
||||||
|
tfs->hio = hio;
|
||||||
tfs->htts = htts;
|
tfs->htts = htts;
|
||||||
tfs->thr_func = func;
|
tfs->thr_func = func;
|
||||||
tfs->thr_ctx = ctx;
|
tfs->thr_ctx = ctx;
|
||||||
@ -1018,7 +1044,7 @@ int hio_svc_htts_dothr (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
|
|||||||
/* TODO: store current input watching state and use it when destroying the thr_task data */
|
/* TODO: store current input watching state and use it when destroying the thr_task data */
|
||||||
if (hio_dev_sck_read(csck, !(thr_task->over & THR_TASK_OVER_READ_FROM_CLIENT)) <= -1) goto oops;
|
if (hio_dev_sck_read(csck, !(thr_task->over & THR_TASK_OVER_READ_FROM_CLIENT)) <= -1) goto oops;
|
||||||
|
|
||||||
// HIO_SVC_HTTS_TASKL_APPEND_TASK(htts->task, thr_task);
|
HIO_SVC_HTTS_TASKL_APPEND_TASK(&htts->task, thr_task);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
oops:
|
oops:
|
||||||
|
Loading…
Reference in New Issue
Block a user