improvied fcgic session untie handling
This commit is contained in:
parent
3874e2c43a
commit
3c46823832
@ -76,6 +76,16 @@ struct hio_svc_fcgic_conn_t
|
|||||||
hio_svc_fcgic_conn_t* next;
|
hio_svc_fcgic_conn_t* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct hio_svc_fcgic_sess_t
|
||||||
|
{
|
||||||
|
int active;
|
||||||
|
hio_oow_t sid;
|
||||||
|
hio_svc_fcgic_conn_t* conn;
|
||||||
|
hio_svc_fcgic_on_read_t on_read;
|
||||||
|
hio_svc_fcgic_on_untie_t on_untie;
|
||||||
|
void* ctx;
|
||||||
|
};
|
||||||
|
|
||||||
struct fcgic_sck_xtn_t
|
struct fcgic_sck_xtn_t
|
||||||
{
|
{
|
||||||
hio_svc_fcgic_conn_t* conn;
|
hio_svc_fcgic_conn_t* conn;
|
||||||
@ -110,9 +120,7 @@ printf ("DISCONNECT SOCKET .................. sck->%p conn->%p\n", sck, conn);
|
|||||||
sess = &conn->sess.ptr[i];
|
sess = &conn->sess.ptr[i];
|
||||||
if (sess->active)
|
if (sess->active)
|
||||||
{
|
{
|
||||||
/* TODO: release the session???*/
|
|
||||||
release_session (sess); /* TODO: is this correct?? */
|
release_session (sess); /* TODO: is this correct?? */
|
||||||
/* or do we fire a callback??? */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conn->dev = HIO_NULL;
|
conn->dev = HIO_NULL;
|
||||||
@ -260,7 +268,7 @@ printf ("header completed remaining data %d expected body_len %d\n", (int)dlen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
HIO_ASSERT (hio, conn->r.content_len <= conn->r.len);
|
HIO_ASSERT (hio, conn->r.content_len <= conn->r.len);
|
||||||
sess->on_read (sess, conn->r.buf, conn->r.content_len); /* TODO: tell between stdout and stderr */
|
sess->on_read (sess, conn->r.buf, conn->r.content_len, sess->ctx); /* TODO: tell between stdout and stderr */
|
||||||
|
|
||||||
back_to_header:
|
back_to_header:
|
||||||
conn->r.state = R_AWAITING_HEADER;
|
conn->r.state = R_AWAITING_HEADER;
|
||||||
@ -322,6 +330,7 @@ static int make_connection_socket (hio_svc_fcgic_conn_t* conn)
|
|||||||
|
|
||||||
HIO_MEMSET (&ci, 0, HIO_SIZEOF(ci));
|
HIO_MEMSET (&ci, 0, HIO_SIZEOF(ci));
|
||||||
ci.remoteaddr = conn->addr;
|
ci.remoteaddr = conn->addr;
|
||||||
|
/*ci.connect_tmout.sec = 5; TODO: make this configurable */
|
||||||
|
|
||||||
if (hio_dev_sck_connect(sck, &ci) <= -1)
|
if (hio_dev_sck_connect(sck, &ci) <= -1)
|
||||||
{
|
{
|
||||||
@ -401,7 +410,7 @@ static void free_connections (hio_svc_fcgic_t* fcgic)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static hio_svc_fcgic_sess_t* new_session (hio_svc_fcgic_t* fcgic, const hio_skad_t* fcgis_addr, hio_svc_fcgic_on_read_t on_read, void* ctx)
|
static hio_svc_fcgic_sess_t* new_session (hio_svc_fcgic_t* fcgic, const hio_skad_t* fcgis_addr, hio_svc_fcgic_on_read_t on_read, hio_svc_fcgic_on_untie_t on_untie, void* ctx)
|
||||||
{
|
{
|
||||||
hio_t* hio = fcgic->hio;
|
hio_t* hio = fcgic->hio;
|
||||||
hio_svc_fcgic_conn_t* conn;
|
hio_svc_fcgic_conn_t* conn;
|
||||||
@ -439,6 +448,7 @@ static hio_svc_fcgic_sess_t* new_session (hio_svc_fcgic_t* fcgic, const hio_skad
|
|||||||
|
|
||||||
sess->sid = conn->sess.free;
|
sess->sid = conn->sess.free;
|
||||||
sess->on_read = on_read;
|
sess->on_read = on_read;
|
||||||
|
sess->on_untie = on_untie;
|
||||||
sess->active = 1;
|
sess->active = 1;
|
||||||
sess->ctx = ctx;
|
sess->ctx = ctx;
|
||||||
HIO_ASSERT (hio, sess->conn == conn);
|
HIO_ASSERT (hio, sess->conn == conn);
|
||||||
@ -449,6 +459,7 @@ static hio_svc_fcgic_sess_t* new_session (hio_svc_fcgic_t* fcgic, const hio_skad
|
|||||||
|
|
||||||
static void release_session (hio_svc_fcgic_sess_t* sess)
|
static void release_session (hio_svc_fcgic_sess_t* sess)
|
||||||
{
|
{
|
||||||
|
if (sess->on_untie) sess->on_untie (sess, sess->ctx);
|
||||||
sess->active = 0;
|
sess->active = 0;
|
||||||
sess->sid = sess->conn->sess.free;
|
sess->sid = sess->conn->sess.free;
|
||||||
sess->conn->sess.free = sess->sid;
|
sess->conn->sess.free = sess->sid;
|
||||||
@ -494,10 +505,10 @@ void hio_svc_fcgic_stop (hio_svc_fcgic_t* fcgic)
|
|||||||
HIO_DEBUG1 (hio, "FCGIC - STOPPED SERVICE %p\n", fcgic);
|
HIO_DEBUG1 (hio, "FCGIC - STOPPED SERVICE %p\n", fcgic);
|
||||||
}
|
}
|
||||||
|
|
||||||
hio_svc_fcgic_sess_t* hio_svc_fcgic_tie (hio_svc_fcgic_t* fcgic, const hio_skad_t* addr, hio_svc_fcgic_on_read_t on_read, void* ctx)
|
hio_svc_fcgic_sess_t* hio_svc_fcgic_tie (hio_svc_fcgic_t* fcgic, const hio_skad_t* addr, hio_svc_fcgic_on_read_t on_read, hio_svc_fcgic_on_untie_t on_untie, void* ctx)
|
||||||
{
|
{
|
||||||
/* TODO: reference counting for safety?? */
|
/* TODO: reference counting for safety?? */
|
||||||
return new_session(fcgic, addr, on_read, ctx);
|
return new_session(fcgic, addr, on_read, on_untie, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hio_svc_fcgic_untie (hio_svc_fcgic_sess_t* sess)
|
void hio_svc_fcgic_untie (hio_svc_fcgic_sess_t* sess)
|
||||||
|
@ -123,19 +123,16 @@ typedef struct hio_svc_fcgic_conn_t hio_svc_fcgic_conn_t;
|
|||||||
/* ---------------------------------------------------------------- */
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
typedef int (*hio_svc_fcgic_on_read_t) (
|
typedef int (*hio_svc_fcgic_on_read_t) (
|
||||||
hio_svc_fcgic_sess_t* sess,
|
hio_svc_fcgic_sess_t* sess,
|
||||||
const void* data,
|
const void* data,
|
||||||
hio_iolen_t dlen
|
hio_iolen_t dlen,
|
||||||
|
void* ctx
|
||||||
);
|
);
|
||||||
|
|
||||||
struct hio_svc_fcgic_sess_t
|
typedef void (*hio_svc_fcgic_on_untie_t) (
|
||||||
{
|
hio_svc_fcgic_sess_t* sess,
|
||||||
int active;
|
void* ctx;
|
||||||
hio_oow_t sid;
|
);
|
||||||
hio_svc_fcgic_conn_t* conn;
|
|
||||||
hio_svc_fcgic_on_read_t on_read;
|
|
||||||
void* ctx;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- */
|
/* ---------------------------------------------------------------- */
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
@ -160,10 +157,11 @@ static HIO_INLINE hio_t* hio_svc_fcgic_gethio(hio_svc_fcgic_t* svc) { return hio
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
HIO_EXPORT hio_svc_fcgic_sess_t* hio_svc_fcgic_tie (
|
HIO_EXPORT hio_svc_fcgic_sess_t* hio_svc_fcgic_tie (
|
||||||
hio_svc_fcgic_t* fcgic,
|
hio_svc_fcgic_t* fcgic,
|
||||||
const hio_skad_t* fcgis_addr,
|
const hio_skad_t* fcgis_addr,
|
||||||
hio_svc_fcgic_on_read_t on_read,
|
hio_svc_fcgic_on_read_t on_read,
|
||||||
void* ctx
|
hio_svc_fcgic_on_untie_t on_untie,
|
||||||
|
void* ctx
|
||||||
);
|
);
|
||||||
|
|
||||||
HIO_EXPORT void hio_svc_fcgic_untie (
|
HIO_EXPORT void hio_svc_fcgic_untie (
|
||||||
@ -188,12 +186,6 @@ HIO_EXPORT int hio_svc_fcgic_writestdin (
|
|||||||
hio_iolen_t size
|
hio_iolen_t size
|
||||||
);
|
);
|
||||||
|
|
||||||
#if defined(HIO_HAVE_INLINE)
|
|
||||||
static HIO_INLINE void* hio_svc_fcgic_getsessctx (hio_svc_fcgic_sess_t* sess) { return sess->ctx; }
|
|
||||||
#else
|
|
||||||
#define hio_svc_fcgic_getsessctx(sess) ((sess)->ctx)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -215,25 +215,13 @@ static HIO_INLINE void fcgi_mark_over (fcgi_t* fcgi, int over_bits)
|
|||||||
|
|
||||||
if (!(old_over & FCGI_OVER_READ_FROM_PEER) && (fcgi->over & FCGI_OVER_READ_FROM_PEER))
|
if (!(old_over & FCGI_OVER_READ_FROM_PEER) && (fcgi->over & FCGI_OVER_READ_FROM_PEER))
|
||||||
{
|
{
|
||||||
#if 0 // TODO:
|
if (fcgi->peer) hio_svc_fcgic_untie(fcgi->peer);
|
||||||
if (fcgi->peer && hio_dev_pro_read(fcgi->peer, HIO_DEV_PRO_OUT, 0) <= -1)
|
|
||||||
{
|
|
||||||
HIO_DEBUG2 (fcgi->htts->hio, "HTTS(%p) - halting peer(%p) for failure to disable input watching\n", fcgi->htts, fcgi->peer);
|
|
||||||
hio_dev_pro_halt (fcgi->peer);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old_over != FCGI_OVER_ALL && fcgi->over == FCGI_OVER_ALL)
|
if (old_over != FCGI_OVER_ALL && fcgi->over == FCGI_OVER_ALL)
|
||||||
{
|
{
|
||||||
/* ready to stop */
|
/* ready to stop */
|
||||||
#if 0 // TODO:
|
if (fcgi->peer) hio_svc_fcgic_untie(fcgi->peer);
|
||||||
if (fcgi->peer)
|
|
||||||
{
|
|
||||||
HIO_DEBUG2 (fcgi->htts->hio, "HTTS(%p) - halting peer(%p) as it is unneeded\n", fcgi->htts, fcgi->peer);
|
|
||||||
hio_dev_pro_halt (fcgi->peer); // TODO: untie???
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fcgi->csck)
|
if (fcgi->csck)
|
||||||
{
|
{
|
||||||
@ -477,9 +465,9 @@ oops:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int fcgi_peer_on_read (hio_svc_fcgic_sess_t* peer, const void* data, hio_iolen_t dlen)
|
static int fcgi_peer_on_read (hio_svc_fcgic_sess_t* peer, const void* data, hio_iolen_t dlen, void* ctx)
|
||||||
{
|
{
|
||||||
fcgi_t* fcgi = hio_svc_fcgic_getsessctx(peer);
|
fcgi_t* fcgi = (fcgi_t*)ctx;
|
||||||
hio_svc_htts_t* htts = fcgi->htts;
|
hio_svc_htts_t* htts = fcgi->htts;
|
||||||
hio_t* hio = htts->hio;
|
hio_t* hio = htts->hio;
|
||||||
|
|
||||||
@ -538,6 +526,13 @@ oops:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int fcgi_peer_on_untie (hio_svc_fcgic_sess_t* peer, void* ctx)
|
||||||
|
{
|
||||||
|
fcgi_t* fcgi = (fcgi_t*)ctx;
|
||||||
|
if (fcgi->peer) fcgi->peer = HIO_NULL; /* in case this untie event originates from the fcgi client itself */
|
||||||
|
fcgi_halt_participating_devices (fcgi); /* TODO: kill the session only??? */
|
||||||
|
}
|
||||||
|
|
||||||
static int peer_capture_response_header (hio_htre_t* req, const hio_bch_t* key, const hio_htre_hdrval_t* val, void* ctx)
|
static int peer_capture_response_header (hio_htre_t* req, const hio_bch_t* key, const hio_htre_hdrval_t* val, void* ctx)
|
||||||
{
|
{
|
||||||
hio_svc_htts_cli_t* cli = (hio_svc_htts_cli_t*)ctx;
|
hio_svc_htts_cli_t* cli = (hio_svc_htts_cli_t*)ctx;
|
||||||
@ -803,7 +798,7 @@ int hio_svc_htts_dofcgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
|
|||||||
HIO_SVC_HTTS_TASK_REF ((hio_svc_htts_task_t*)fcgi, pxtn->fcgi); /* peer->fcgi in htrd = fcgi */
|
HIO_SVC_HTTS_TASK_REF ((hio_svc_htts_task_t*)fcgi, pxtn->fcgi); /* peer->fcgi in htrd = fcgi */
|
||||||
|
|
||||||
/* create a session in in the fcgi client service */
|
/* create a session in in the fcgi client service */
|
||||||
fcgi->peer = hio_svc_fcgic_tie(htts->fcgic, fcgis_addr, fcgi_peer_on_read, fcgi);
|
fcgi->peer = hio_svc_fcgic_tie(htts->fcgic, fcgis_addr, fcgi_peer_on_read, fcgi_peer_on_untie, fcgi);
|
||||||
if (HIO_UNLIKELY(!fcgi->peer)) goto oops;
|
if (HIO_UNLIKELY(!fcgi->peer)) goto oops;
|
||||||
|
|
||||||
/* send FCGI_BEGIN_REQUEST */
|
/* send FCGI_BEGIN_REQUEST */
|
||||||
|
Loading…
Reference in New Issue
Block a user