renamed main2.c to main-s.c

started adding client code
This commit is contained in:
2018-03-17 16:07:51 +00:00
parent 8aeeff3d93
commit 7db7e3e48f
7 changed files with 366 additions and 27 deletions

View File

@ -25,3 +25,206 @@
*/
#include "hcl-c.h"
#include "hcl-prv.h"
struct hcl_client_proto_t
{
hcl_client_t* client;
struct
{
hcl_bch_t* ptr;
hcl_oow_t len;
hcl_oow_t capa;
} req;
struct
{
hcl_ooch_t* ptr;
hcl_oow_t len;
hcl_oow_t capa;
} rep;
};
struct hcl_client_t
{
hcl_mmgr_t* mmgr;
hcl_cmgr_t* cmgr;
/*hcl_t* dummy_hcl;*/
};
/* ========================================================================= */
static void proto_start_request (hcl_client_proto_t* proto)
{
proto->req.len = 0;
}
static void proto_feed_request_data (hcl_client_proto_t* proto, xxxx);
{
}
static int proto_end_request (hcl_client_proto_t* proto)
{
if (proto->req.len <= 0) return -1;
return 0;
}
static void proto_start_response (hcl_client_proto_t* proto)
{
}
static void proto_feed_reply_data (hcl_client_proto_t* proto, const hcl_bch_t* ptr, hcl_oow_t len)
{
const hcl_bch_t* end = ptr + len;
while (ptr < end)
{
hcl_bch_t b = *ptr++;
switch (b)
{
case '\0':
}
}
}
/* ========================================================================= */
hcl_client_t* hcl_client_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_errnum_t* errnum)
{
hcl_client_t* client;
#if 0
hcl_t* hcl;
hcl_vmprim_t vmprim;
hcl_tmr_t* tmr;
dummy_hcl_xtn_t* xtn;
int pfd[2], fcv;
unsigned int trait;
#endif
client = (hcl_client_t*)HCL_MMGR_ALLOC(mmgr, HCL_SIZEOF(*client) + xtnsize);
if (!client)
{
if (errnum) *errnum = HCL_ESYSMEM;
return HCL_NULL;
}
#if 0
HCL_MEMSET (&vmprim, 0, HCL_SIZEOF(vmprim));
vmprim.log_write = log_write_for_dummy;
vmprim.syserrstrb = syserrstrb;
vmprim.dl_open = dl_open;
vmprim.dl_close = dl_close;
vmprim.dl_getsym = dl_getsym;
vmprim.vm_gettime = vm_gettime;
vmprim.vm_sleep = vm_sleep;
hcl = hcl_open(mmgr, HCL_SIZEOF(*xtn), 2048, &vmprim, errnum);
if (!hcl)
{
HCL_MMGR_FREE (mmgr, client);
return HCL_NULL;
}
tmr = hcl_tmr_open(hcl, 0, 1024); /* TOOD: make the timer's default size configurable */
if (!tmr)
{
hcl_close (hcl);
HCL_MMGR_FREE (mmgr, client);
return HCL_NULL;
}
if (pipe(pfd) <= -1)
{
hcl_tmr_close (tmr);
hcl_close (hcl);
HCL_MMGR_FREE (mmgr, client);
return HCL_NULL;
}
#if defined(O_CLOEXEC)
fcv = fcntl(pfd[0], F_GETFD, 0);
if (fcv >= 0) fcntl(pfd[0], F_SETFD, fcv | O_CLOEXEC);
fcv = fcntl(pfd[1], F_GETFD, 0);
if (fcv >= 0) fcntl(pfd[1], F_SETFD, fcv | O_CLOEXEC);
#endif
#if defined(O_NONBLOCK)
fcv = fcntl(pfd[0], F_GETFL, 0);
if (fcv >= 0) fcntl(pfd[0], F_SETFL, fcv | O_NONBLOCK);
fcv = fcntl(pfd[1], F_GETFL, 0);
if (fcv >= 0) fcntl(pfd[1], F_SETFL, fcv | O_NONBLOCK);
#endif
xtn = (dummy_hcl_xtn_t*)hcl_getxtn(hcl);
xtn->client = client;
HCL_MEMSET (client, 0, HCL_SIZEOF(*client) + xtnsize);
client->mmgr = mmgr;
client->cmgr = hcl_get_utf8_cmgr();
client->prim = *prim;
client->dummy_hcl = hcl;
client->tmr = tmr;
client->cfg.logmask = ~0u;
client->cfg.worker_stack_size = 512000UL;
client->cfg.actor_heap_size = 512000UL;
HCL_INITNTIME (&client->cfg.worker_idle_timeout, 0, 0);
HCL_INITNTIME (&client->cfg.actor_max_runtime, 0, 0);
client->mux_pipe[0] = pfd[0];
client->mux_pipe[1] = pfd[1];
client->wid_map.free_first = HCL_SERVER_WID_INVALID;
client->wid_map.free_last = HCL_SERVER_WID_INVALID;
pthread_mutex_init (&client->worker_mutex, HCL_NULL);
pthread_mutex_init (&client->tmr_mutex, HCL_NULL);
pthread_mutex_init (&client->log_mutex, HCL_NULL);
/* the dummy hcl is used for this client to perform primitive operations
* such as getting system time or logging. so the heap size doesn't
* need to be changed from the tiny value set above. */
hcl_setoption (client->dummy_hcl, HCL_LOG_MASK, &client->cfg.logmask);
hcl_setcmgr (client->dummy_hcl, client->cmgr);
hcl_getoption (client->dummy_hcl, HCL_TRAIT, &trait);
#if defined(HCL_BUILD_DEBUG)
if (client->cfg.trait & HCL_SERVER_TRAIT_DEBUG_GC) trait |= HCL_DEBUG_GC;
if (client->cfg.trait & HCL_SERVER_TRAIT_DEBUG_BIGINT) trait |= HCL_DEBUG_BIGINT;
#endif
hcl_setoption (client->dummy_hcl, HCL_TRAIT, &trait);
#else
HCL_MEMSET (client, 0, HCL_SIZEOF(*client) + xtnsize);
client->mmgr = mmgr;
client->cmgr = hcl_get_utf8_cmgr();
#endif
return client;
}
void hcl_client_close (hcl_client_t* client)
{
HCL_MMGR_FREE (client->mmgr, client);
}
int hcl_client_start (hcl_client_t* client, const hcl_bch_t* addrs)
{
/* connect */
/* send request */
}
int hcl_client_sendreq (hcl_client_t* client, const hcl_bch_t* addrs)
{
}