code clean-up of xproto code.
All checks were successful
continuous-integration/drone/push Build is passing

added ifname to ifindex conversion code
This commit is contained in:
hyung-hwan 2024-04-21 16:29:55 +09:00
parent ccbaae98a4
commit 6eee6bc9eb
9 changed files with 330 additions and 43 deletions

View File

@ -684,8 +684,6 @@ static int handle_request (hcl_client_t* client, const char* ipaddr, const char*
goto oops; goto oops;
} }
/* TODO: create hcl_xproto_open... */ /* TODO: create hcl_xproto_open... */
memset (proto, 0, HCL_SIZEOF(*proto)); memset (proto, 0, HCL_SIZEOF(*proto));
proto->hcl = hcl_openstdwithmmgr(hcl_client_getmmgr(client), 0, HCL_NULL); // TODO: proto->hcl = hcl_openstdwithmmgr(hcl_client_getmmgr(client), 0, HCL_NULL); // TODO:

101
configure vendored
View File

@ -1872,6 +1872,66 @@ fi
} # ac_fn_c_try_run } # ac_fn_c_try_run
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
# ----------------------------------------------------
# Tries to find if the field MEMBER exists in type AGGR, after including
# INCLUDES, setting cache variable VAR accordingly.
ac_fn_c_check_member ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
printf %s "checking for $2.$3... " >&6; }
if eval test \${$4+y}
then :
printf %s "(cached) " >&6
else $as_nop
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$5
int
main (void)
{
static $2 ac_aggr;
if (ac_aggr.$3)
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
eval "$4=yes"
else $as_nop
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$5
int
main (void)
{
static $2 ac_aggr;
if (sizeof ac_aggr.$3)
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
eval "$4=yes"
else $as_nop
eval "$4=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
eval ac_res=\$$4
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_member
# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES # ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
# -------------------------------------------- # --------------------------------------------
# Tries to find the compile-time value of EXPR in a program that includes # Tries to find the compile-time value of EXPR in a program that includes
@ -15514,6 +15574,19 @@ then :
fi fi
ac_fn_c_check_header_compile "$LINENO" "sys/ioctl.h" "ac_cv_header_sys_ioctl_h" "$ac_includes_default"
if test "x$ac_cv_header_sys_ioctl_h" = xyes
then :
printf "%s\n" "#define HAVE_SYS_IOCTL_H 1" >>confdefs.h
fi
ac_fn_c_check_header_compile "$LINENO" "net/if.h" "ac_cv_header_net_if_h" "$ac_includes_default"
if test "x$ac_cv_header_net_if_h" = xyes
then :
printf "%s\n" "#define HAVE_NET_IF_H 1" >>confdefs.h
fi
ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday" ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday"
@ -16101,6 +16174,34 @@ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
fi fi
ac_fn_c_check_member "$LINENO" "struct ifreq" "ifr_ifindex" "ac_cv_member_struct_ifreq_ifr_ifindex" "#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
"
if test "x$ac_cv_member_struct_ifreq_ifr_ifindex" = xyes
then :
printf "%s\n" "#define HAVE_STRUCT_IFREQ_IFR_IFINDEX 1" >>confdefs.h
fi
ac_fn_c_check_member "$LINENO" "struct ifreq" "ifr_mtu" "ac_cv_member_struct_ifreq_ifr_mtu" "#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
"
if test "x$ac_cv_member_struct_ifreq_ifr_mtu" = xyes
then :
printf "%s\n" "#define HAVE_STRUCT_IFREQ_IFR_MTU 1" >>confdefs.h
fi
# The cast to long int works around a bug in the HP C Compiler # The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.

View File

@ -112,6 +112,7 @@ AC_CHECK_HEADERS([time.h sys/time.h utime.h spawn.h execinfo.h ucontext.h])
AC_CHECK_HEADERS([dlfcn.h ltdl.h sys/mman.h sys/uio.h]) AC_CHECK_HEADERS([dlfcn.h ltdl.h sys/mman.h sys/uio.h])
AC_CHECK_HEADERS([sys/devpoll.h sys/epoll.h poll.h]) AC_CHECK_HEADERS([sys/devpoll.h sys/epoll.h poll.h])
AC_CHECK_HEADERS([libunwind.h quadmath.h]) AC_CHECK_HEADERS([libunwind.h quadmath.h])
AC_CHECK_HEADERS([sys/ioctl.h net/if.h])
dnl check data types dnl check data types
dnl AC_CHECK_TYPE([wchar_t], dnl AC_CHECK_TYPE([wchar_t],
@ -217,6 +218,13 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <string.h>
]) ])
AC_CHECK_MEMBERS([struct ifreq.ifr_ifindex, struct ifreq.ifr_mtu], [], [],
[#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif])
dnl check the size of primitive data types dnl check the size of primitive data types
AC_CHECK_SIZEOF(char,,[[]]) AC_CHECK_SIZEOF(char,,[[]])
AC_CHECK_SIZEOF(short,,[[]]) AC_CHECK_SIZEOF(short,,[[]])

View File

@ -123,6 +123,9 @@
/* Define to 1 if you have the `nanosleep' function. */ /* Define to 1 if you have the `nanosleep' function. */
#undef HAVE_NANOSLEEP #undef HAVE_NANOSLEEP
/* Define to 1 if you have the <net/if.h> header file. */
#undef HAVE_NET_IF_H
/* Define to 1 if you have the `pipe2' function. */ /* Define to 1 if you have the `pipe2' function. */
#undef HAVE_PIPE2 #undef HAVE_PIPE2
@ -207,6 +210,12 @@
/* Define to 1 if you have the `strtoflt128' function. */ /* Define to 1 if you have the `strtoflt128' function. */
#undef HAVE_STRTOFLT128 #undef HAVE_STRTOFLT128
/* Define to 1 if `ifr_ifindex' is a member of `struct ifreq'. */
#undef HAVE_STRUCT_IFREQ_IFR_IFINDEX
/* Define to 1 if `ifr_mtu' is a member of `struct ifreq'. */
#undef HAVE_STRUCT_IFREQ_IFR_MTU
/* Define to 1 if you have the `swapcontext' function. */ /* Define to 1 if you have the `swapcontext' function. */
#undef HAVE_SWAPCONTEXT #undef HAVE_SWAPCONTEXT
@ -216,6 +225,9 @@
/* Define to 1 if you have the <sys/epoll.h> header file. */ /* Define to 1 if you have the <sys/epoll.h> header file. */
#undef HAVE_SYS_EPOLL_H #undef HAVE_SYS_EPOLL_H
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/mman.h> header file. */ /* Define to 1 if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H #undef HAVE_SYS_MMAN_H

View File

@ -89,6 +89,12 @@ struct bb_t
}; };
typedef struct bb_t bb_t; typedef struct bb_t bb_t;
struct proto_xtn_t
{
hcl_server_worker_t* worker;
};
typedef struct proto_xtn_t proto_xtn_t;
struct worker_hcl_xtn_t struct worker_hcl_xtn_t
{ {
hcl_server_worker_t* worker; hcl_server_worker_t* worker;
@ -113,7 +119,8 @@ typedef enum hcl_xproto_rcv_state_t hcl_xproto_rcv_state_t;
struct hcl_xproto_t struct hcl_xproto_t
{ {
hcl_server_worker_t* worker; hcl_oow_t _instsize;
hcl_mmgr_t* _mmgr;
hcl_tmr_index_t exec_runtime_event_index; hcl_tmr_index_t exec_runtime_event_index;
struct struct
@ -724,12 +731,14 @@ static void exec_runtime_handler (hcl_tmr_t* tmr, const hcl_ntime_t* now, hcl_tm
hcl_xproto_t* proto; hcl_xproto_t* proto;
hcl_server_worker_t* worker; hcl_server_worker_t* worker;
proto_xtn_t* prtxtn;
proto = (hcl_xproto_t*)evt->ctx; proto = (hcl_xproto_t*)evt->ctx;
worker = proto->worker; prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
/* TODO: can we use worker->hcl for logging before abort?? */ /* TODO: can we use worker->hcl for logging before abort?? */
HCL_LOG1 (worker->server->dummy_hcl, SERVER_LOGMASK_INFO, "Aborting script execution for max_actor_runtime exceeded [%zu]\n", proto->worker->wid); HCL_LOG1 (worker->server->dummy_hcl, SERVER_LOGMASK_INFO, "Aborting script execution for max_actor_runtime exceeded [%zu]\n", worker->wid);
hcl_abort (worker->hcl); hcl_abort (worker->hcl);
} }
@ -740,9 +749,11 @@ static void exec_runtime_updater (hcl_tmr_t* tmr, hcl_tmr_index_t old_index, hcl
hcl_xproto_t* proto; hcl_xproto_t* proto;
hcl_server_worker_t* worker; hcl_server_worker_t* worker;
proto_xtn_t* prtxtn;
proto = (hcl_xproto_t*)evt->ctx; proto = (hcl_xproto_t*)evt->ctx;
worker = proto->worker; prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
HCL_ASSERT (worker->hcl, proto->exec_runtime_event_index == old_index); HCL_ASSERT (worker->hcl, proto->exec_runtime_event_index == old_index);
/* the event is being removed by hcl_tmr_fire() or by hcl_tmr_delete() /* the event is being removed by hcl_tmr_fire() or by hcl_tmr_delete()
@ -756,10 +767,12 @@ static int insert_exec_timer (hcl_xproto_t* proto, const hcl_ntime_t* tmout)
hcl_tmr_event_t event; hcl_tmr_event_t event;
hcl_tmr_index_t index; hcl_tmr_index_t index;
proto_xtn_t* prtxtn;
hcl_server_worker_t* worker; hcl_server_worker_t* worker;
hcl_server_t* server; hcl_server_t* server;
worker = proto->worker; prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
server = worker->server; server = worker->server;
HCL_ASSERT (worker->hcl, proto->exec_runtime_event_index == HCL_TMR_INVALID_INDEX); HCL_ASSERT (worker->hcl, proto->exec_runtime_event_index == HCL_TMR_INVALID_INDEX);
@ -789,10 +802,12 @@ static void delete_exec_timer (hcl_xproto_t* proto)
/* [NOTE] this is executed in the worker thread. if the event has been fired /* [NOTE] this is executed in the worker thread. if the event has been fired
* in the server thread, proto->exec_runtime_event_index should be * in the server thread, proto->exec_runtime_event_index should be
* HCL_TMR_INVALID_INDEX as set by exec_runtime_handler */ * HCL_TMR_INVALID_INDEX as set by exec_runtime_handler */
proto_xtn_t* prtxtn;
hcl_server_worker_t* worker; hcl_server_worker_t* worker;
hcl_server_t* server; hcl_server_t* server;
worker = proto->worker; prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
server = worker->server; server = worker->server;
pthread_mutex_lock (&server->tmr_mutex); pthread_mutex_lock (&server->tmr_mutex);
@ -812,10 +827,12 @@ static int execute_script (hcl_xproto_t* proto, const hcl_bch_t* trigger)
{ {
hcl_oop_t obj; hcl_oop_t obj;
const hcl_ooch_t* failmsg = HCL_NULL; const hcl_ooch_t* failmsg = HCL_NULL;
proto_xtn_t* prtxtn;
hcl_server_worker_t* worker; hcl_server_worker_t* worker;
hcl_server_t* server; hcl_server_t* server;
worker = proto->worker; prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
server = worker->server; server = worker->server;
#if 0 #if 0
@ -888,32 +905,46 @@ static void reformat_synerr (hcl_t* hcl)
static void send_proto_hcl_error (hcl_xproto_t* proto) static void send_proto_hcl_error (hcl_xproto_t* proto)
{ {
hcl_server_worker_t* worker = proto->worker; proto_xtn_t* prtxtn;
hcl_server_worker_t* worker;
prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
if (HCL_ERRNUM(worker->hcl) == HCL_ESYNERR) reformat_synerr (worker->hcl); if (HCL_ERRNUM(worker->hcl) == HCL_ESYNERR) reformat_synerr (worker->hcl);
send_error_message (proto, hcl_geterrmsg(worker->hcl)); send_error_message (proto, hcl_geterrmsg(worker->hcl));
} }
static void show_server_workers (hcl_xproto_t* proto) static void show_server_workers (hcl_xproto_t* proto)
{ {
proto_xtn_t* prtxtn;
hcl_server_worker_t* worker, * w;
hcl_server_t* server; hcl_server_t* server;
hcl_server_worker_t* w;
server = proto->worker->server; prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
server = worker->server;
pthread_mutex_lock (&server->worker_mutex); pthread_mutex_lock (&server->worker_mutex);
for (w = server->worker_list[HCL_SERVER_WORKER_STATE_ALIVE].head; w; w = w->next_worker) for (w = server->worker_list[HCL_SERVER_WORKER_STATE_ALIVE].head; w; w = w->next_worker)
{ {
/* TODO: implement this better... */ /* TODO: implement this better... */
hcl_prbfmt (proto->worker->hcl, "%zu %d %d\n", w->wid, w->sck, 1000); hcl_prbfmt (worker->hcl, "%zu %d %d\n", w->wid, w->sck, 1000);
} }
pthread_mutex_unlock (&server->worker_mutex); pthread_mutex_unlock (&server->worker_mutex);
} }
static int kill_server_worker (hcl_xproto_t* proto, hcl_oow_t wid) static int kill_server_worker (hcl_xproto_t* proto, hcl_oow_t wid)
{ {
proto_xtn_t* prtxtn;
hcl_server_worker_t* worker;
hcl_server_t* server; hcl_server_t* server;
int xret = 0; int xret = 0;
server = proto->worker->server; prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
server = worker->server;
pthread_mutex_lock (&server->worker_mutex); pthread_mutex_lock (&server->worker_mutex);
if (wid >= server->wid_map.capa) if (wid >= server->wid_map.capa)
{ {
@ -950,7 +981,13 @@ static int kill_server_worker (hcl_xproto_t* proto, hcl_oow_t wid)
static int handle_packet (hcl_xproto_t* proto, hcl_xpkt_type_t type, void* data, hcl_oow_t len) static int handle_packet (hcl_xproto_t* proto, hcl_xpkt_type_t type, void* data, hcl_oow_t len)
{ {
hcl_t* hcl = proto->worker->hcl; proto_xtn_t* prtxtn;
hcl_server_worker_t* worker;
hcl_t* hcl;
prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
hcl = worker->hcl;
printf ("HANDLE PACKET TYPE => %d\n", type); printf ("HANDLE PACKET TYPE => %d\n", type);
switch (type) switch (type)
@ -1023,7 +1060,6 @@ static int send_iov (int sck, struct iovec* iov, int count)
msg.msg_iov = (struct iovec*)&iov[index]; msg.msg_iov = (struct iovec*)&iov[index];
msg.msg_iovlen = count - index; msg.msg_iovlen = count - index;
nwritten = sendmsg(sck, &msg, 0); nwritten = sendmsg(sck, &msg, 0);
/*nwritten = writev(proto->worker->sck, (const struct iovec*)&iov[index], count - index);*/
if (nwritten <= -1) if (nwritten <= -1)
{ {
/* error occurred inside the worker thread shouldn't affect the error information /* error occurred inside the worker thread shouldn't affect the error information
@ -1046,11 +1082,16 @@ static int send_iov (int sck, struct iovec* iov, int count)
static int send_stdout_bytes (hcl_xproto_t* proto, const hcl_bch_t* data, hcl_oow_t len) static int send_stdout_bytes (hcl_xproto_t* proto, const hcl_bch_t* data, hcl_oow_t len)
{ {
proto_xtn_t* prtxtn;
hcl_server_worker_t* worker;
hcl_xpkt_hdr_t hdr; hcl_xpkt_hdr_t hdr;
struct iovec iov[2]; struct iovec iov[2];
const hcl_bch_t* ptr, * cur, * end; const hcl_bch_t* ptr, * cur, * end;
hcl_uint16_t seglen; hcl_uint16_t seglen;
prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
ptr = cur = data; ptr = cur = data;
end = data + len; end = data + len;
@ -1070,7 +1111,7 @@ printf ("SENDING BYTES [%.*s]\n", (int)len, data);
iov[1].iov_base = ptr; iov[1].iov_base = ptr;
iov[1].iov_len = seglen; iov[1].iov_len = seglen;
if (send_iov(proto->worker->sck, iov, 2) <= -1) if (send_iov(worker->sck, iov, 2) <= -1)
{ {
/* TODO: error message */ /* TODO: error message */
return -1; return -1;
@ -1085,12 +1126,16 @@ printf ("SENDING BYTES [%.*s]\n", (int)len, data);
#if defined(HCL_OOCH_IS_UCH) #if defined(HCL_OOCH_IS_UCH)
static int send_stdout_chars (hcl_xproto_t* proto, const hcl_ooch_t* data, hcl_oow_t len) static int send_stdout_chars (hcl_xproto_t* proto, const hcl_ooch_t* data, hcl_oow_t len)
{ {
hcl_server_worker_t* worker = proto->worker; proto_xtn_t* prtxtn;
hcl_server_worker_t* worker;
const hcl_ooch_t* ptr, * end; const hcl_ooch_t* ptr, * end;
hcl_bch_t tmp[256]; hcl_bch_t tmp[256];
hcl_oow_t tln, pln; hcl_oow_t tln, pln;
int n; int n;
prtxtn = (proto_xtn_t*)hcl_xproto_getxtn(proto);
worker = prtxtn->worker;
ptr = data; ptr = data;
end = data + len; end = data + len;
@ -1112,15 +1157,16 @@ static int send_stdout_chars (hcl_xproto_t* proto, const hcl_ooch_t* data, hcl_o
/* ========================================================================= */ /* ========================================================================= */
hcl_xproto_t* hcl_xproto_open (hcl_oow_t xtnsize, hcl_server_worker_t* worker) hcl_xproto_t* hcl_xproto_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize)
{ {
hcl_xproto_t* proto; hcl_xproto_t* proto;
proto = (hcl_xproto_t*)hcl_server_allocmem(worker->server, HCL_SIZEOF(*proto)); proto = (hcl_xproto_t*)HCL_MMGR_ALLOC(mmgr, HCL_SIZEOF(*proto) + xtnsize);
if (HCL_UNLIKELY(!proto)) return HCL_NULL; if (HCL_UNLIKELY(!proto)) return HCL_NULL;
HCL_MEMSET (proto, 0, HCL_SIZEOF(*proto)); HCL_MEMSET (proto, 0, HCL_SIZEOF(*proto));
proto->worker = worker; proto->_instsize = HCL_SIZEOF(*proto);
proto->_mmgr = mmgr;
proto->exec_runtime_event_index = HCL_TMR_INVALID_INDEX; proto->exec_runtime_event_index = HCL_TMR_INVALID_INDEX;
proto->rcv.state = HCL_XPROTO_RCV_HDR; proto->rcv.state = HCL_XPROTO_RCV_HDR;
proto->rcv.len_needed = HCL_XPKT_HDR_LEN; proto->rcv.len_needed = HCL_XPKT_HDR_LEN;
@ -1131,7 +1177,32 @@ hcl_xproto_t* hcl_xproto_open (hcl_oow_t xtnsize, hcl_server_worker_t* worker)
void hcl_xproto_close (hcl_xproto_t* proto) void hcl_xproto_close (hcl_xproto_t* proto)
{ {
hcl_server_freemem (proto->worker->server, proto); HCL_MMGR_FREE (proto->_mmgr, proto);
}
void* hcl_xproto_getxtn (hcl_xproto_t* proto)
{
return (proto + 1);
}
int hcl_xprpto_feed (hcl_xproto_t* proto, const void* data, hcl_oow_t len)
{
}
hcl_uint8_t* hcl_xproto_getbuf (hcl_xproto_t* proto, hcl_oow_t* capa)
{
*capa = HCL_COUNTOF(proto->rcv.buf) - proto->rcv.len;
return &proto->rcv.buf[proto->rcv.len];
}
void hcl_xproto_seteof (hcl_xproto_t* proto, int v)
{
proto->rcv.eof = v;
}
void hcl_xproto_advbuf (hcl_xproto_t* proto, hcl_oow_t inc)
{
proto->rcv.len += inc;
} }
int hcl_xproto_ready (hcl_xproto_t* proto) int hcl_xproto_ready (hcl_xproto_t* proto)
@ -1140,7 +1211,7 @@ int hcl_xproto_ready (hcl_xproto_t* proto)
return proto->rcv.len >= proto->rcv.len_needed; return proto->rcv.len >= proto->rcv.len_needed;
} }
static int hcl_xproto_process (hcl_xproto_t* proto) int hcl_xproto_process (hcl_xproto_t* proto)
{ {
int n; int n;
hcl_xpkt_hdr_t* hdr; hcl_xpkt_hdr_t* hdr;
@ -1601,7 +1672,11 @@ static int worker_step (hcl_server_worker_t* worker)
if (pfd.revents & POLLIN) if (pfd.revents & POLLIN)
{ {
x = recv(worker->sck, &proto->rcv.buf[proto->rcv.len], HCL_COUNTOF(proto->rcv.buf) - proto->rcv.len, 0); hcl_oow_t bcap;
hcl_uint8_t* bptr;
bptr = hcl_xproto_getbuf(proto, &bcap);;
x = recv(worker->sck, bptr, bcap, 0);
if (x <= -1) if (x <= -1)
{ {
if (errno == EINTR) goto carry_on; /* didn't read read */ if (errno == EINTR) goto carry_on; /* didn't read read */
@ -1610,9 +1685,8 @@ static int worker_step (hcl_server_worker_t* worker)
return -1; return -1;
} }
if (x == 0) proto->rcv.eof = 1; if (x == 0) hcl_xproto_seteof(proto, 1);
proto->rcv.len += x; hcl_xproto_advbuf (proto, x);
} }
} }
@ -1704,10 +1778,14 @@ static void fini_worker_hcl (hcl_server_worker_t* worker)
static int init_worker_proto (hcl_server_worker_t* worker) static int init_worker_proto (hcl_server_worker_t* worker)
{ {
hcl_xproto_t* proto; hcl_xproto_t* proto;
proto_xtn_t* xtn;
proto = hcl_xproto_open(0, worker); proto = hcl_xproto_open(hcl_server_getmmgr(worker->server), HCL_SIZEOF(*xtn));
if (HCL_UNLIKELY(!proto)) return -1; if (HCL_UNLIKELY(!proto)) return -1;
xtn = hcl_xproto_getxtn(proto);
xtn->worker = worker;
worker->proto = proto; worker->proto = proto;
return 0; return 0;
} }

View File

@ -400,14 +400,41 @@ HCL_EXPORT void hcl_client_freemem (
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
HCL_EXPORT hcl_xproto_t* hcl_xproto_open ( HCL_EXPORT hcl_xproto_t* hcl_xproto_open (
hcl_oow_t xtnsize, hcl_mmgr_t* mmgr,
hcl_server_worker_t* worker hcl_oow_t xtnsize
); );
HCL_EXPORT void hcl_xproto_close ( HCL_EXPORT void hcl_xproto_close (
hcl_xproto_t* proto hcl_xproto_t* proto
); );
HCL_EXPORT void* hcl_xproto_getxtn (
hcl_xproto_t* proto
);
hcl_uint8_t* hcl_xproto_getbuf (
hcl_xproto_t* proto,
hcl_oow_t* capa
);
void hcl_xproto_seteof (
hcl_xproto_t* proto,
int v
);
void hcl_xproto_advbuf (
hcl_xproto_t* proto,
hcl_oow_t inc
);
int hcl_xproto_ready (
hcl_xproto_t* proto
);
int hcl_xproto_process (
hcl_xproto_t* proto
);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif

View File

@ -3697,7 +3697,7 @@ static HCL_INLINE int open_udo_stream (hcl_t* hcl, hcl_io_udoarg_t* arg)
if (xtn->udo_path) if (xtn->udo_path)
hcl_seterrbfmtwithsyserr (hcl, 0, errno, "unable to open udo stream '%hs'", xtn->udo_path); hcl_seterrbfmtwithsyserr (hcl, 0, errno, "unable to open udo stream '%hs'", xtn->udo_path);
else else
hcl_seterrbfmtwithsyserr (hcl, 0, errno, "unable to open udo stream", xtn->udo_path); hcl_seterrbfmtwithsyserr (hcl, 0, errno, "unable to open udo stream");
return -1; return -1;
} }

View File

@ -176,6 +176,59 @@ static int str_to_ipv6 (const ooch_t* src, hcl_oow_t len, struct in6_addr* inadd
} }
#endif #endif
static int str_to_ifindex (hcl_t* hcl, const ooch_t* ptr, hcl_oow_t len, unsigned int* ifindex)
{
#if defined(SIOCGIFINDEX)
int h, x;
struct ifreq ifr;
/* use AF_INET6 because str_to_ifindex is called for ipv6 only in this file */
h = socket(AF_INET6, SOCK_DGRAM, 0);
if (h <= -1)
{
hcl_seterrbfmtwithsyserr (hcl, 0, errno, "unable to open socket for if_nametoindex conversion");
return -1;
}
HCL_MEMSET (&ifr, 0, HCL_SIZEOF(ifr));
#if (ooch_mode == 2)
hcl_oow_t ucslen, bcslen;
ucslen = len;
bcslen = HCL_COUNTOF(ifr.ifr_name) - 1;
if (hcl_convutobchars(hcl, ptr, &ucslen, ifr.ifr_name, &bcslen) <= -1)
{
close (h);
return -1;
}
ifr.ifr_name[bcslen] = '\0';
#else
if (hcl_copy_bchars_to_bcstr(ifr.ifr_name, HCL_COUNTOF(ifr.ifr_name), ptr, len) < len)
{
close (h);
return -1;
}
#endif
x = ioctl(h, SIOCGIFINDEX, &ifr);
close (h);
if (x >= 0)
{
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
*ifindex = ifr.ifr_ifindex;
#else
*ifindex = ifr.ifr_index;
#endif
}
return x;
#else
/* TODO: use if_nametoindex()? */
hcl_seterrbfmt (hcl, HCL_ENOIMPL, "ifname to ifindex conversion not implemented");
return -1;
#endif
}
int str_to_sockaddr (hcl_t* hcl, const ooch_t* str, hcl_oow_t len, hcl_sckaddr_t* sckaddr, hcl_scklen_t* scklen) int str_to_sockaddr (hcl_t* hcl, const ooch_t* str, hcl_oow_t len, hcl_sckaddr_t* sckaddr, hcl_scklen_t* scklen)
{ {
@ -235,19 +288,16 @@ int str_to_sockaddr (hcl_t* hcl, const ooch_t* str, hcl_oow_t len, hcl_sckaddr_t
p++; p++;
} }
while (p < end && *p >= '0' && *p <= '9'); while (p < end && *p >= '0' && *p <= '9');
//nwad->in6.sin6_scope_id = y; nwad->in6.sin6_scope_id = y;
} }
else else
{ {
#if 0
TODO:
/* interface name as a scope id? */ /* interface name as a scope id? */
const ooch_t* stmp = p; const ooch_t* stmp = p;
unsigned int index; unsigned int index;
do p++; while (p < end && *p != ']'); do p++; while (p < end && *p != ']');
if (hcl_nwifwcsntoindex(stmp, p - stmp, &index) <= -1) return -1; if (str_to_ifindex(hcl, stmp, p - stmp, &index) <= -1) return -1;
tmpad.u.in6.scope = index; nwad->in6.sin6_scope_id = index;
#endif
} }
if (p >= end || *p != ']') goto no_rbrack; if (p >= end || *p != ']') goto no_rbrack;
@ -311,19 +361,16 @@ TODO:
p++; p++;
} }
while (p < end && *p >= '0' && *p <= '9'); while (p < end && *p >= '0' && *p <= '9');
//nwad->in6.sin6_scope_id = y; nwad->in6.sin6_scope_id = y;
} }
else else
{ {
#if 0
TODO
/* interface name as a scope id? */ /* interface name as a scope id? */
const ooch_t* stmp = p; const ooch_t* stmp = p;
unsigned int index; unsigned int index;
do p++; while (p < end); do p++; while (p < end);
if (hcl_nwifwcsntoindex(stmp, p - stmp, &index) <= -1) return -1; if (str_to_ifindex(hcl, stmp, p - stmp, &index) <= -1) return -1;
nwad->in6.sin6_scope_id = index; nwad->in6.sin6_scope_id = index;
#endif
} }
} }

View File

@ -37,7 +37,15 @@
# include <sys/socket.h> # include <sys/socket.h>
# include <netinet/in.h> # include <netinet/in.h>
#else #else
# if defined(HAVE_SYS_IOCTL_H)
# include <sys/ioctl.h>
# endif
# if defined(HAVE_NET_IF_H)
# include <net/if.h>
# endif
# include <netinet/in.h> # include <netinet/in.h>
# include <unistd.h>
# include <errno.h>
#endif #endif
union sockaddr_t union sockaddr_t
@ -52,29 +60,37 @@ union sockaddr_t
}; };
typedef union sockaddr_t sockaddr_t; typedef union sockaddr_t sockaddr_t;
#undef ooch_mode
#undef ooch_t #undef ooch_t
#undef oocs_t #undef oocs_t
#undef str_to_ipv4 #undef str_to_ipv4
#undef str_to_ipv6 #undef str_to_ipv6
#undef str_to_sockaddr #undef str_to_sockaddr
#undef str_to_ifindex
#define ooch_mode (1)
#define ooch_t hcl_bch_t #define ooch_t hcl_bch_t
#define oocs_t hcl_bcs_t #define oocs_t hcl_bcs_t
#define str_to_ipv4 bchars_to_ipv4 #define str_to_ipv4 bchars_to_ipv4
#define str_to_ipv6 bchars_to_ipv6 #define str_to_ipv6 bchars_to_ipv6
#define str_to_ifindex bchars_to_ifindex
#define str_to_sockaddr hcl_bcharstosckaddr #define str_to_sockaddr hcl_bcharstosckaddr
#include "xutl-sa.h" #include "xutl-sa.h"
#undef ooch_mode
#undef ooch_t #undef ooch_t
#undef oocs_t #undef oocs_t
#undef str_to_ipv4 #undef str_to_ipv4
#undef str_to_ipv6 #undef str_to_ipv6
#undef str_to_ifindex
#undef str_to_sockaddr #undef str_to_sockaddr
#define ooch_mode (2)
#define ooch_t hcl_uch_t #define ooch_t hcl_uch_t
#define oocs_t hcl_ucs_t #define oocs_t hcl_ucs_t
#define str_to_ipv4 uchars_to_ipv4 #define str_to_ipv4 uchars_to_ipv4
#define str_to_ipv6 uchars_to_ipv6 #define str_to_ipv6 uchars_to_ipv6
#define str_to_ifindex uchars_to_ifindex
#define str_to_sockaddr hcl_ucharstosckaddr #define str_to_sockaddr hcl_ucharstosckaddr
#include "xutl-sa.h" #include "xutl-sa.h"