making no progress in fcgi support...

This commit is contained in:
hyung-hwan 2022-09-05 23:19:08 +00:00
parent c526c4c780
commit b6122cc92d
4 changed files with 111 additions and 65 deletions

View File

@ -27,6 +27,8 @@
#include "hio-prv.h"
typedef struct hio_svc_fcgic_conn_t hio_svc_fcgic_conn_t;
struct hio_svc_fcgic_t
@ -40,6 +42,8 @@ struct hio_svc_fcgic_t
hio_svc_fcgic_conn_t* conns;
};
#define CONN_SESS_CAPA_MAX (65536)
#define CONN_SESS_INC (32)
#define INVALID_SID HIO_TYPE_MAX(hio_oow_t)
struct hio_svc_fcgic_sess_t
@ -65,23 +69,22 @@ struct hio_svc_fcgic_conn_t
hio_svc_fcgic_conn_t* next;
};
#if 0
struct fcgic_sck_xtn_t
{
hio_svc_fcgic_t* fcgic;
hio_svc_fcgic_conn_t* conn;
#if 0
struct
{
hio_uint8_t* ptr;
hio_oow_t len;
hio_oow_t capa;
} rbuf; /* used by tcp socket */
#endif
};
typedef struct fcgic_sck_xtn_t fcgic_sck_xtn_t;
#if 0
/* ----------------------------------------------------------------------- */
struct fcgic_fcgi_msg_xtn_t
@ -108,9 +111,36 @@ typedef struct fcgic_fcgi_msg_xtn_t fcgic_fcgi_msg_xtn_t;
#endif
static hio_dev_sck_t* make_sck_dev (hio_t* hio, hio_skad_t* addr)
static void sck_on_disconnect (hio_dev_sck_t* sck)
{
fcgic_sck_xtn_t* sck_xtn = hio_dev_sck_getxtn(sck);
hio_svc_fcgic_conn_t* conn;
conn = sck_xtn->conn;
conn->sck = make_connection_socket(fcgic, fcgic->saddr);
}
static void sck_on_connect (hio_dev_sck_t* sck)
{
}
static int sck_on_write (hio_dev_sck_t* sck, hio_iolen_t wrlen, void* wrctx, const hio_skad_t* dstaddr)
{
return 0;
}
static int sck_on_read (hio_dev_sck_t* sck, const void* buf, hio_iolen_t len, const hio_skad_t* srcaddr)
{
return 0;
}
static hio_dev_sck_t* make_connection_socket (hio_svc_fcgic_t* fcgic, hio_skad_t* addr)
{
hio_t* hio = fcgic->hio;
hio_dev_sck_t* sck;
hio_dev_sck_make_t mi;
hio_dev_sck_connect_t ci;
fcgic_sck_xtn_t* sck_xtn;
HIO_MEMSET (&mi, 0, HIO_SIZEOF(mi));
switch (hio_skad_get_family(addr))
@ -139,14 +169,33 @@ static hio_dev_sck_t* make_sck_dev (hio_t* hio, hio_skad_t* addr)
}
mi.options = HIO_DEV_SCK_MAKE_LENIENT;
#if 0
mi.on_write = listener_on_write;
mi.on_read = listener_on_read;
mi.on_connect = listener_on_connect;
mi.on_disconnect = listener_on_disconnect;
#endif
mi.on_write = sck_on_write;
mi.on_read = sck_on_read;
mi.on_connect = sck_on_connect;
mi.on_disconnect = sck_on_disconnect;
return hio_dev_sck_make(hio, 0, &mi);
sck = hio_dev_sck_make(hio, HIO_SIZEOF(*sck_xtn), &mi);
if (HIO_UNLIKELY(!sck)) return HIO_NULL;
sck_xtn = hio_dev_sck_getxtn(sck);
sck_xtn->conn = conn;
return sck;
}
static void initiate_connection (hio_svc_fcgic_t* conn)
{
HIO_MEMSET (&ci, 0, HIO_SIZEOF(ci));
ci.remoteaddr = conn.addr
#if 0
// TODO:
//ci.connect_tmout = ...
#endif
if (hio_dev_sck_connect(sck, &ci) <= -1)
{
hio_dev_sck_kill (sck);
return HIO_NULL;
}
}
static hio_svc_fcgic_conn_t* get_connection (hio_svc_fcgic_t* fcgic, hio_skad_t* addr)
@ -157,27 +206,33 @@ 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 */
while (conn)
{
if (hio_equal_skads(&conn->addr, addr, 1)) return conn;
if (hio_equal_skads(&conn->addr, addr, 1))
{
if (conn->sess.free != INVALID_SID ||
conn->sess.capa <= (CONN_SESS_CAPA_MAX - CONN_SESS_INC)) return conn;
}
conn = conn->next;
}
conn = hio_callocmem(hio, HIO_SIZEOF(*conn));
if (HIO_UNLIKELY(!conn)) return HIO_NULL;
conn->dev = make_sck_dev(hio, addr);
conn->addr = *addr;
conn->sess.capa = 0;
conn->sess.free = INVALID_SID;
conn->dev = make_connection_socket(fcgic, addr);
if (HIO_UNLIKELY(!conn->dev))
{
hio_freemem (hio, conn);
return HIO_NULL;
}
conn->addr = *addr;
conn->sess.capa = 0;
conn->sess.free = INVALID_SID;
conn->next = fcgic->conns;
fcgic->conns = conn;
initiate_conection (conn);
return conn;
}
@ -211,7 +266,7 @@ static hio_svc_fcgic_sess_t* new_session (hio_svc_fcgic_t* fcgic, hio_skad_t* ad
hio_oow_t newcapa, i;
hio_svc_fcgic_sess_t* newptr;
newcapa = conn->sess.capa + 32;
newcapa = conn->sess.capa + CONN_SESS_INC;
newptr = hio_reallocmem (hio, conn->sess.ptr, HIO_SIZEOF(*sess) * newcapa);
if (HIO_UNLIKELY(!newptr)) return HIO_NULL;
@ -227,15 +282,13 @@ static hio_svc_fcgic_sess_t* new_session (hio_svc_fcgic_t* fcgic, hio_skad_t* ad
conn->sess.capa = newcapa;
conn->sess.ptr = newptr;
}
else
{
sess = &conn->sess.ptr[conn->sess.free];
conn->sess.free = sess->sid;
sess->sid = conn->sess.free;
HIO_ASSERT (hio, sess->fcgic == fcgic);
HIO_ASSERT (hio, sess->conn == conn);
}
sess = &conn->sess.ptr[conn->sess.free];
conn->sess.free = sess->sid;
sess->sid = conn->sess.free;
HIO_ASSERT (hio, sess->fcgic == fcgic);
HIO_ASSERT (hio, sess->conn == conn);
return sess;
}

View File

@ -67,6 +67,15 @@ static HIO_INLINE hio_t* hio_svc_fcgic_gethio(hio_svc_fcgic_t* svc) { return hio
# define hio_svc_fcgic_gethio(svc) hio_svc_gethio(svc)
#endif
HIO_EXPORT hio_svc_fcgic_sess_t* hio_svc_fcgic_tie (
hio_svc_fcgic_t* fcgic,
hio_skad_t* addr
);
HIO_EXPORT void hio_svc_fcgic_untie (
hio_svc_fcgic_sess_t* sess
);
#if defined(__cplusplus)
}
#endif

View File

@ -308,8 +308,8 @@ static void cgi_on_kill (cgi_t* cgi)
static void peer_on_close (hio_dev_pro_t* pro, hio_dev_pro_sid_t sid)
{
hio_t* hio = pro->hio;
cgi_peer_xtn_t* peer = hio_dev_pro_getxtn(pro);
cgi_t* cgi = peer->cgi;
cgi_peer_xtn_t* peer_xtn = hio_dev_pro_getxtn(pro);
cgi_t* cgi = peer_xtn->cgi;
if (!cgi) return; /* cgi state already gone */
@ -319,18 +319,18 @@ static void peer_on_close (hio_dev_pro_t* pro, hio_dev_pro_sid_t sid)
HIO_DEBUG3 (hio, "HTTS(%p) - peer %p(pid=%d) closing master\n", cgi->client->htts, pro, (int)pro->child_pid);
cgi->peer = HIO_NULL; /* clear this peer from the state */
HIO_ASSERT (hio, peer->cgi != HIO_NULL);
HIO_ASSERT (hio, peer_xtn->cgi != HIO_NULL);
/*printf ("DETACHING FROM CGI PEER DEVICE.....................%p %d\n", peer->cgi, (int)peer->cgi->rsrc_refcnt);*/
HIO_SVC_HTTS_RSRC_DETACH (peer->cgi);
HIO_SVC_HTTS_RSRC_DETACH (peer_xtn->cgi);
if (cgi->peer_htrd)
{
/* once this peer device is closed, peer's htrd is also never used.
* it's safe to detach the extra information attached on the htrd object. */
peer = hio_htrd_getxtn(cgi->peer_htrd);
HIO_ASSERT (hio, peer->cgi != HIO_NULL);
peer_xtn = hio_htrd_getxtn(cgi->peer_htrd);
HIO_ASSERT (hio, peer_xtn->cgi != HIO_NULL);
/*printf ("DETACHING FROM CGI PEER HTRD.....................%p %d\n", peer->cgi, (int)peer->cgi->rsrc_refcnt);*/
HIO_SVC_HTTS_RSRC_DETACH (peer->cgi);
HIO_SVC_HTTS_RSRC_DETACH (peer_xtn->cgi);
}
break;
@ -926,7 +926,7 @@ int hio_svc_htts_docgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
hio_t* hio = htts->hio;
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(csck);
cgi_t* cgi = HIO_NULL;
cgi_peer_xtn_t* peer;
cgi_peer_xtn_t* peer_xtn;
hio_dev_pro_make_t mi;
peer_fork_ctx_t fc;
@ -977,18 +977,18 @@ int hio_svc_htts_docgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
goto oops; /* TODO: must not go to oops. just destroy the cgi and finalize the request .. */
}
cgi->peer = hio_dev_pro_make(hio, HIO_SIZEOF(*peer), &mi);
cgi->peer = hio_dev_pro_make(hio, HIO_SIZEOF(*peer_xtn), &mi);
if (HIO_UNLIKELY(!cgi->peer)) goto oops;
peer = hio_dev_pro_getxtn(cgi->peer);
HIO_SVC_HTTS_RSRC_ATTACH (cgi, peer->cgi); /* peer->cgi in pro = cgi */
peer_xtn = hio_dev_pro_getxtn(cgi->peer);
HIO_SVC_HTTS_RSRC_ATTACH (cgi, peer_xtn->cgi); /* peer->cgi in pro = cgi */
cgi->peer_htrd = hio_htrd_open(hio, HIO_SIZEOF(*peer));
cgi->peer_htrd = hio_htrd_open(hio, HIO_SIZEOF(*peer_xtn));
if (HIO_UNLIKELY(!cgi->peer_htrd)) goto oops;
hio_htrd_setoption (cgi->peer_htrd, HIO_HTRD_SKIP_INITIAL_LINE | HIO_HTRD_RESPONSE);
hio_htrd_setrecbs (cgi->peer_htrd, &peer_htrd_recbs);
peer = hio_htrd_getxtn(cgi->peer_htrd);
HIO_SVC_HTTS_RSRC_ATTACH (cgi, peer->cgi); /* peer->cgi in htrd = cgi */
peer_xtn = hio_htrd_getxtn(cgi->peer_htrd);
HIO_SVC_HTTS_RSRC_ATTACH (cgi, peer_xtn->cgi); /* peer->cgi in htrd = cgi */
#if !defined(CGI_ALLOW_UNLIMITED_REQ_CONTENT_LENGTH)
if (cgi->req_content_length_unlimited)

View File

@ -1,6 +1,7 @@
#include "http-prv.h"
#include <hio-fmt.h>
#include <hio-chr.h>
#include <hio-fcgi.h>
#define FCGI_ALLOW_UNLIMITED_REQ_CONTENT_LENGTH
@ -22,7 +23,6 @@ typedef enum fcgi_res_mode_t fcgi_res_mode_t;
#define FCGI_OVER_ALL (FCGI_OVER_READ_FROM_CLIENT | FCGI_OVER_READ_FROM_PEER | FCGI_OVER_WRITE_TO_CLIENT | FCGI_OVER_WRITE_TO_PEER)
#define FCGI_VERSION (1)
#define FCGI_PADDING_SIZE 255
@ -99,7 +99,7 @@ struct fcgi_t
hio_oow_t num_pending_writes_to_client;
hio_oow_t num_pending_writes_to_peer;
//hio_dev_pro_t* peer;
hio_svc_fcgic_sess_t* peer;
hio_svc_htts_cli_t* client;
hio_http_version_t req_version; /* client request */
@ -502,7 +502,7 @@ int hio_svc_htts_dofcgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
hio_t* hio = htts->hio;
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(csck);
fcgi_t* fcgi = HIO_NULL;
//fcgi_peer_xtn_t* peer;
//fcgi_peer_xtn_t* peer_xtn;
/* ensure that you call this function before any contents is received */
HIO_ASSERT (hio, hio_htre_getcontentlen(req) == 0);
@ -529,29 +529,13 @@ int hio_svc_htts_dofcgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
HIO_SVC_HTTS_RSRC_ATTACH (fcgi, cli->rsrc); /* cli->rsrc = fcgi */
#if 0 // TODO
fcgi->peer = hio_dev_pro_make(hio, HIO_SIZEOF(*peer), &mi);
fcgi->peer = hio_dev_pro_make(hio, HIO_SIZEOF(*peer_xtn), &mi);
if (HIO_UNLIKELY(!fcgi->peer)) goto oops;
peer = hio_dev_pro_getxtn(fcgi->peer);
HIO_SVC_HTTS_RSRC_ATTACH (fcgi, peer->fcgi); /* peer->fcgi = fcgi */
peer_xtn = hio_dev_pro_getxtn(fcgi->peer);
HIO_SVC_HTTS_RSRC_ATTACH (fcgi, peer_xtn->fcgi); /* peer->fcgi = fcgi */
#else
/*
hio_fcgic_sess_t* fcgi_sess;
fcgi_sess = hio_svc_fcgic_tie(hio, "10.10.10.9:9000");
if (HIO_UNLIKELY(!fcgi_sess)) goto oops;
hio_svc_fcgic_untie (fcgic_sess); <--- this must release the session.
fcgi_sess = hio_svc_fcgic_tie(hio, "10.10.10.9:9000", callback?);
hio_svc_fcgic_write (hio, fcgi_sess, DATA, "aaaaaaaaaaaaaaaaaaaaa");
hio_svc_fcgic_write (hio, fcgi_sess, STDIO, "aaaaaaaaaaaaaaaaaaaaa");
fcgi->peer = hio_svc_fcgi_make(hio, XXXX);
fcgi->peer = hio_svc_fcgic_tie(hio, "10.10.10.9:9000" /* TODO: add a read callback */);
if (HIO_UNLIKELY(!fcgi->peer)) goto oops;
peer = hio_dev_pro_getxtn(fcgi->peer);
HIO_SVC_HTTS_RSRC_ATTACH (fcgi, peer->fcgi);
*/
#endif
#if 0 // TODO