just a bit of code to fcgi support
This commit is contained in:
parent
89d11ba3fd
commit
7a35f9ae4c
@ -204,6 +204,12 @@ if (hio_htre_getcontentlen(req) > 0)
|
|||||||
x = hio_svc_htts_dotxt(htts, csck, req, 200, "text/plain", qpath);
|
x = hio_svc_htts_dotxt(htts, csck, req, 200, "text/plain", qpath);
|
||||||
else if (hio_comp_bcstr_limited(qpath, "/cgi/", 5, 1) == 0)
|
else if (hio_comp_bcstr_limited(qpath, "/cgi/", 5, 1) == 0)
|
||||||
x = hio_svc_htts_docgi(htts, csck, req, "", qpath + 4);
|
x = hio_svc_htts_docgi(htts, csck, req, "", qpath + 4);
|
||||||
|
else if (hio_comp_bcstr_limited(qpath, "/fcgi/", 5, 1) == 0)
|
||||||
|
{
|
||||||
|
hio_skad_t fcgis_addr;
|
||||||
|
hio_bcstrtoskad(hio, "127.0.0.1:9000", &fcgis_addr);
|
||||||
|
x = hio_svc_htts_dofcgi(htts, csck, req, &fcgis_addr);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain");
|
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain");
|
||||||
if (x <= -1) goto oops;
|
if (x <= -1) goto oops;
|
||||||
|
@ -194,7 +194,6 @@ static int make_connection_socket (hio_svc_fcgic_conn_t* conn)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (conn->dev != HIO_NULL)
|
if (conn->dev != HIO_NULL)
|
||||||
{
|
{
|
||||||
/* TODO: is this necessary???? */
|
/* TODO: is this necessary???? */
|
||||||
@ -207,7 +206,7 @@ if (conn->dev != HIO_NULL)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static hio_svc_fcgic_conn_t* get_connection (hio_svc_fcgic_t* fcgic, hio_skad_t* addr)
|
static hio_svc_fcgic_conn_t* get_connection (hio_svc_fcgic_t* fcgic, const hio_skad_t* fcgis_addr)
|
||||||
{
|
{
|
||||||
hio_t* hio = fcgic->hio;
|
hio_t* hio = fcgic->hio;
|
||||||
hio_svc_fcgic_conn_t* conn = fcgic->conns;
|
hio_svc_fcgic_conn_t* conn = fcgic->conns;
|
||||||
@ -215,7 +214,7 @@ static hio_svc_fcgic_conn_t* get_connection (hio_svc_fcgic_t* fcgic, hio_skad_t*
|
|||||||
/* TODO: speed up? how many conns would be configured? sequential search may be ok here */
|
/* TODO: speed up? how many conns would be configured? sequential search may be ok here */
|
||||||
while (conn)
|
while (conn)
|
||||||
{
|
{
|
||||||
if (hio_equal_skads(&conn->addr, addr, 1))
|
if (hio_equal_skads(&conn->addr, fcgis_addr, 1))
|
||||||
{
|
{
|
||||||
if (conn->sess.free != INVALID_SID ||
|
if (conn->sess.free != INVALID_SID ||
|
||||||
conn->sess.capa <= (CONN_SESS_CAPA_MAX - CONN_SESS_INC)) return conn;
|
conn->sess.capa <= (CONN_SESS_CAPA_MAX - CONN_SESS_INC)) return conn;
|
||||||
@ -227,7 +226,7 @@ static hio_svc_fcgic_conn_t* get_connection (hio_svc_fcgic_t* fcgic, hio_skad_t*
|
|||||||
if (HIO_UNLIKELY(!conn)) return HIO_NULL;
|
if (HIO_UNLIKELY(!conn)) return HIO_NULL;
|
||||||
|
|
||||||
conn->fcgic = fcgic;
|
conn->fcgic = fcgic;
|
||||||
conn->addr = *addr;
|
conn->addr = *fcgis_addr;
|
||||||
conn->sess.capa = 0;
|
conn->sess.capa = 0;
|
||||||
conn->sess.free = INVALID_SID;
|
conn->sess.free = INVALID_SID;
|
||||||
|
|
||||||
@ -259,13 +258,13 @@ static void free_connections (hio_svc_fcgic_t* fcgic)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static hio_svc_fcgic_sess_t* new_session (hio_svc_fcgic_t* fcgic, hio_skad_t* addr)
|
static hio_svc_fcgic_sess_t* new_session (hio_svc_fcgic_t* fcgic, const hio_skad_t* fcgis_addr)
|
||||||
{
|
{
|
||||||
hio_t* hio = fcgic->hio;
|
hio_t* hio = fcgic->hio;
|
||||||
hio_svc_fcgic_conn_t* conn;
|
hio_svc_fcgic_conn_t* conn;
|
||||||
hio_svc_fcgic_sess_t* sess;
|
hio_svc_fcgic_sess_t* sess;
|
||||||
|
|
||||||
conn = get_connection(fcgic, addr);
|
conn = get_connection(fcgic, fcgis_addr);
|
||||||
if (HIO_UNLIKELY(!conn)) return HIO_NULL;
|
if (HIO_UNLIKELY(!conn)) return HIO_NULL;
|
||||||
|
|
||||||
if (conn->sess.free == INVALID_SID)
|
if (conn->sess.free == INVALID_SID)
|
||||||
@ -343,7 +342,7 @@ void hio_svc_fcgic_stop (hio_svc_fcgic_t* fcgic)
|
|||||||
hio_freemem (hio, fcgic);
|
hio_freemem (hio, fcgic);
|
||||||
}
|
}
|
||||||
|
|
||||||
hio_svc_fcgic_sess_t* hio_svc_fcgic_tie (hio_svc_fcgic_t* fcgic, hio_skad_t* addr)
|
hio_svc_fcgic_sess_t* hio_svc_fcgic_tie (hio_svc_fcgic_t* fcgic, const hio_skad_t* addr)
|
||||||
{
|
{
|
||||||
/* TODO: reference counting for safety?? */
|
/* TODO: reference counting for safety?? */
|
||||||
return new_session(fcgic, addr);
|
return new_session(fcgic, addr);
|
||||||
@ -355,3 +354,7 @@ void hio_svc_fcgic_untie (hio_svc_fcgic_sess_t* sess)
|
|||||||
release_session (sess);
|
release_session (sess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int hio_svc_fcgic_write (hio_svc_fcgic_sess_t* sess, const void* data, hio_iolen_t len)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -69,13 +69,19 @@ static HIO_INLINE hio_t* hio_svc_fcgic_gethio(hio_svc_fcgic_t* svc) { return hio
|
|||||||
|
|
||||||
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,
|
||||||
hio_skad_t* addr
|
const hio_skad_t* fcgis_addr
|
||||||
);
|
);
|
||||||
|
|
||||||
HIO_EXPORT void hio_svc_fcgic_untie (
|
HIO_EXPORT void hio_svc_fcgic_untie (
|
||||||
hio_svc_fcgic_sess_t* sess
|
hio_svc_fcgic_sess_t* sess
|
||||||
);
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT int hio_svc_fcgic_write (
|
||||||
|
hio_svc_fcgic_sess_t* sess,
|
||||||
|
const void* data,
|
||||||
|
hio_iolen_t len
|
||||||
|
);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <hio-sck.h>
|
#include <hio-sck.h>
|
||||||
#include <hio-htre.h>
|
#include <hio-htre.h>
|
||||||
#include <hio-thr.h>
|
#include <hio-thr.h>
|
||||||
|
#include <hio-fcgi.h>
|
||||||
|
|
||||||
/** \file
|
/** \file
|
||||||
* This file provides basic data types and functions for the http protocol.
|
* This file provides basic data types and functions for the http protocol.
|
||||||
@ -304,6 +305,14 @@ HIO_EXPORT int hio_svc_htts_docgi (
|
|||||||
const hio_bch_t* script
|
const hio_bch_t* script
|
||||||
);
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT int hio_svc_htts_dofcgi (
|
||||||
|
hio_svc_htts_t* htts,
|
||||||
|
hio_dev_sck_t* csck,
|
||||||
|
hio_htre_t* req,
|
||||||
|
const hio_skad_t* fcgis_addr
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_svc_htts_dofile (
|
HIO_EXPORT int hio_svc_htts_dofile (
|
||||||
hio_svc_htts_t* htts,
|
hio_svc_htts_t* htts,
|
||||||
hio_dev_sck_t* csck,
|
hio_dev_sck_t* csck,
|
||||||
|
@ -497,7 +497,7 @@ static void fcgi_on_kill (fcgi_t* fcgi)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int hio_svc_htts_dofcgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* req, hio_skad_t* fcgi_server_addr)
|
int hio_svc_htts_dofcgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* req, const hio_skad_t* fcgis_addr)
|
||||||
{
|
{
|
||||||
hio_t* hio = htts->hio;
|
hio_t* hio = htts->hio;
|
||||||
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(csck);
|
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(csck);
|
||||||
@ -507,6 +507,12 @@ int hio_svc_htts_dofcgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
|
|||||||
/* ensure that you call this function before any contents is received */
|
/* ensure that you call this function before any contents is received */
|
||||||
HIO_ASSERT (hio, hio_htre_getcontentlen(req) == 0);
|
HIO_ASSERT (hio, hio_htre_getcontentlen(req) == 0);
|
||||||
|
|
||||||
|
if (!htts->fcgic)
|
||||||
|
{
|
||||||
|
hio_seterrbfmt (hio, HIO_ENOCAPA, "fcgi client service not enabled");
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
fcgi = (fcgi_t*)hio_svc_htts_rsrc_make(htts, HIO_SIZEOF(*fcgi), fcgi_on_kill);
|
fcgi = (fcgi_t*)hio_svc_htts_rsrc_make(htts, HIO_SIZEOF(*fcgi), fcgi_on_kill);
|
||||||
if (HIO_UNLIKELY(!fcgi)) goto oops;
|
if (HIO_UNLIKELY(!fcgi)) goto oops;
|
||||||
|
|
||||||
@ -534,8 +540,10 @@ int hio_svc_htts_dofcgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
|
|||||||
peer_xtn = hio_dev_pro_getxtn(fcgi->peer);
|
peer_xtn = hio_dev_pro_getxtn(fcgi->peer);
|
||||||
HIO_SVC_HTTS_RSRC_ATTACH (fcgi, peer_xtn->fcgi); /* peer->fcgi = fcgi */
|
HIO_SVC_HTTS_RSRC_ATTACH (fcgi, peer_xtn->fcgi); /* peer->fcgi = fcgi */
|
||||||
#else
|
#else
|
||||||
fcgi->peer = hio_svc_fcgic_tie(hio, "10.10.10.9:9000" /* TODO: add a read callback */);
|
fcgi->peer = hio_svc_fcgic_tie(htts->fcgic, fcgis_addr /* TODO: add a read callback */);
|
||||||
if (HIO_UNLIKELY(!fcgi->peer)) goto oops;
|
if (HIO_UNLIKELY(!fcgi->peer)) goto oops;
|
||||||
|
|
||||||
|
hio_svc_fcgic_write (fcgi->peer, "hello", 5);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0 // TODO
|
#if 0 // TODO
|
||||||
|
@ -67,6 +67,7 @@ struct hio_svc_htts_t
|
|||||||
hio_oow_t count;
|
hio_oow_t count;
|
||||||
} l;
|
} l;
|
||||||
/*hio_dev_sck_t* lsck;*/
|
/*hio_dev_sck_t* lsck;*/
|
||||||
|
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_tmridx_t idle_tmridx;
|
hio_tmridx_t idle_tmridx;
|
||||||
|
@ -463,6 +463,12 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_o
|
|||||||
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);
|
||||||
|
|
||||||
|
htts->fcgic = hio_svc_fcgic_start(hio, HIO_NULL); /* TODO: set timeout properly */
|
||||||
|
if (HIO_UNLIKELY(!htts->fcgic))
|
||||||
|
{
|
||||||
|
/* TODO: only warning ... */
|
||||||
|
}
|
||||||
|
|
||||||
HIO_DEBUG1 (hio, "HTTS - STARTED SERVICE %p\n", htts);
|
HIO_DEBUG1 (hio, "HTTS - STARTED SERVICE %p\n", htts);
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -481,6 +487,12 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_o
|
|||||||
oops:
|
oops:
|
||||||
if (htts)
|
if (htts)
|
||||||
{
|
{
|
||||||
|
if (htts->fcgic)
|
||||||
|
{
|
||||||
|
hio_svc_fcgic_stop (htts->fcgic);
|
||||||
|
htts->fcgic = HIO_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (htts->l.sck)
|
if (htts->l.sck)
|
||||||
{
|
{
|
||||||
for (i = 0; i < htts->l.count; i++)
|
for (i = 0; i < htts->l.count; i++)
|
||||||
@ -502,6 +514,12 @@ void hio_svc_htts_stop (hio_svc_htts_t* htts)
|
|||||||
|
|
||||||
HIO_DEBUG1 (hio, "HTTS - STOPPING SERVICE %p\n", htts);
|
HIO_DEBUG1 (hio, "HTTS - STOPPING SERVICE %p\n", htts);
|
||||||
|
|
||||||
|
if (htts->fcgic)
|
||||||
|
{
|
||||||
|
hio_svc_fcgic_stop (htts->fcgic);
|
||||||
|
htts->fcgic = HIO_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < htts->l.count; i++)
|
for (i = 0; i < htts->l.count; i++)
|
||||||
{
|
{
|
||||||
/* the socket may be null:
|
/* the socket may be null:
|
||||||
|
Loading…
Reference in New Issue
Block a user