cleaning up mio_dev_thr_t code
This commit is contained in:
@ -1652,111 +1652,6 @@ mio_bch_t* mio_svc_htts_dupmergepaths (mio_svc_htts_t* htts, const mio_bch_t* ba
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#if 0
|
||||
typedef void (*mio_svc_htts_rsrc_cgi_t) (
|
||||
int rfd,
|
||||
int wfd
|
||||
);
|
||||
|
||||
struct mio_svc_htts_rsrc_cgi_peer_t
|
||||
{
|
||||
int rfd;
|
||||
int wfd;
|
||||
};
|
||||
typedef struct mio_svc_htts_rsrc_cgi_peer_t mio_svc_htts_rsrc_cgi_peer_t;
|
||||
|
||||
enum mio_svc_htts_rsrc_cgi_type_t
|
||||
{
|
||||
MIO_SVC_HTTS_RSRC_CGI_TYPE_FUNC,
|
||||
MIO_SVC_HTTS_RSRC_CGI_TYPE_PROC
|
||||
};
|
||||
typedef enum mio_svc_htts_rsrc_cgi_type_t mio_svc_htts_rsrc_cgi_type_t;
|
||||
|
||||
struct rsrc_cgi_xtn_t
|
||||
{
|
||||
mio_svc_htts_rsrc_cgi_type_t type;
|
||||
int rfd;
|
||||
int wfd;
|
||||
|
||||
mio_svc_htts_rsrc_cgi_t handler;
|
||||
pthread_t thr;
|
||||
mio_svc_htts_rsrc_cgi_peer_t peer;
|
||||
};
|
||||
typedef struct rsrc_cgi_xtn_t rsrc_cgi_xtn_t;
|
||||
|
||||
static void rsrc_cgi_on_kill (mio_svc_htts_rsrc_t* rsrc)
|
||||
{
|
||||
rsrc_cgi_xtn_t* cgi = (rsrc_cgi_xtn_t*)mio_svc_htts_rsrc_getxtn(rsrc);
|
||||
|
||||
close (cgi->rfd); cgi->rfd = -1;
|
||||
close (cgi->wfd); cgi->wfd = -1;
|
||||
|
||||
switch (cgi->type)
|
||||
{
|
||||
case MIO_SVC_HTTS_RSRC_CGI_TYPE_FUNC:
|
||||
/* TODO: check cgi->thr is valid.
|
||||
* non-blocking way? if alive, kill gracefully?? */
|
||||
pthread_join (cgi->thr, MIO_NULL);
|
||||
break;
|
||||
|
||||
case MIO_SVC_HTTS_RSRC_CGI_TYPE_PROC:
|
||||
/* TODO:
|
||||
waitpid with no wait
|
||||
still alive kill
|
||||
waitpid with no wait.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void* cgi_thr_func (void* ctx)
|
||||
{
|
||||
rsrc_cgi_xtn_t* func = (rsrc_cgi_xtn_t*)ctx;
|
||||
func->handler (func->peer.rfd, func->peer.wfd);
|
||||
close (func->peer.rfd); func->peer.rfd = -1;
|
||||
close (func->peer.wfd); func->peer.wfd = -1;
|
||||
return MIO_NULL;
|
||||
}
|
||||
|
||||
int mio_svc_htts_sendcgi (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_svc_htts_rsrc_cgi_t handler, mio_htre_t* req)
|
||||
{
|
||||
mio_svc_htts_rsrc_t* rsrc = MIO_NULL;
|
||||
rsrc_cgi_xtn_t* cgi = MIO_NULL;
|
||||
int pfd[2];
|
||||
|
||||
rsrc = mio_svc_htts_rsrc_make(htts, csck, rsrc_cgi_on_kill, MIO_SIZEOF(*cgi));
|
||||
if (MIO_UNLIKELY(!rsrc)) goto oops;
|
||||
|
||||
cgi = mio_svc_htts_rsrc_getxtn(rsrc);
|
||||
cgi->type = MIO_SVC_HTTS_RSRC_CGI_TYPE_FUNC;
|
||||
cgi->handler = handler;
|
||||
cgi->rfd = -1;
|
||||
cgi->wfd = -1;
|
||||
cgi->peer.rfd = -1;
|
||||
cgi->peer.wfd = -1;
|
||||
|
||||
if (pipe(pfd) == -1) goto oops;
|
||||
cgi->peer.rfd = pfd[0];
|
||||
cgi->wfd = pfd[1];
|
||||
|
||||
if (pipe(pfd) == -1) goto oops;
|
||||
cgi->rfd = pfd[0];
|
||||
cgi->peer.wfd = pfd[1];
|
||||
|
||||
if (pthread_create(&cgi->thr, MIO_NULL, cgi_thr_func, cgi) != 0) goto oops;
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
if (cgi)
|
||||
{
|
||||
if (cgi->peer.rfd >= 0) { close (cgi->peer.rfd); cgi->peer.rfd = -1; }
|
||||
if (cgi->peer.wfd >= 0) { close (cgi->peer.wfd); cgi->peer.wfd = -1; }
|
||||
if (cgi->rfd >= 0) { close (cgi->rfd); cgi->rfd = -1; }
|
||||
if (cgi->wfd >= 0) { close (cgi->wfd); cgi->wfd = -1; }
|
||||
}
|
||||
if (rsrc) mio_svc_htts_rsrc_kill (rsrc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
int mio_svc_htts_sendrsrc (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_svc_htts_rsrc_t* rsrc, int status_code, mio_http_method_t method, const mio_http_version_t* version, int keepalive)
|
||||
|
Reference in New Issue
Block a user