removed unused files and added hcl_sys_send_iov() for common use
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-04-22 12:39:59 +09:00
parent 7e782809f9
commit 189ceb6d3a
8 changed files with 54 additions and 6756 deletions

View File

@ -452,42 +452,6 @@ static int handle_logopt (hcl_client_t* client, const hcl_bch_t* str)
/* ========================================================================= */
static int send_iov (int sck, struct iovec* iov, int count)
{
int index = 0;
while (1)
{
ssize_t nwritten;
struct msghdr msg;
memset (&msg, 0, HCL_SIZEOF(msg));
msg.msg_iov = (struct iovec*)&iov[index];
msg.msg_iovlen = count - index;
nwritten = sendmsg(sck, &msg, 0);
/*nwritten = writev(proto->worker->sck, (const struct iovec*)&iov[index], count - index);*/
if (nwritten <= -1)
{
/* error occurred inside the worker thread shouldn't affect the error information
* in the server object. so here, i just log a message */
fprintf (stderr, "Unable to sendmsg on %d - %s\n", sck, strerror(errno));
return -1;
}
while (index < count && (size_t)nwritten >= iov[index].iov_len)
nwritten -= iov[index++].iov_len;
if (index == count) break;
iov[index].iov_base = (void*)((hcl_uint8_t*)iov[index].iov_base + nwritten);
iov[index].iov_len -= nwritten;
}
return 0;
}
/* ========================================================================= */
struct proto_xtn_t
{
int x;
@ -627,7 +591,7 @@ static int handle_request (hcl_client_t* client, const char* ipaddr, const char*
iov[1].iov_base = scptr;
iov[1].iov_len = seglen;
send_iov (sck, iov, 2); /* TODO: error check */
hcl_sys_send_iov (sck, iov, 2); /* TODO: error check */
scptr = sccur;
@ -639,7 +603,7 @@ static int handle_request (hcl_client_t* client, const char* ipaddr, const char*
iov[0].iov_base = &hdr;
iov[0].iov_len = HCL_SIZEOF(hdr);
send_iov (sck, iov, 1);
hcl_sys_send_iov (sck, iov, 1);
if (shut_wr_after_req)
{
@ -653,7 +617,7 @@ static int handle_request (hcl_client_t* client, const char* ipaddr, const char*
iov[0].iov_base = &hdr;
iov[0].iov_len = HCL_SIZEOF(hdr);
send_iov (sck, iov, 1);
hcl_sys_send_iov (sck, iov, 1);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,271 +0,0 @@
/*
Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if 0
#ifndef _HCL_C_H_
#define _HCL_C_H_
#include <hcl.h>
typedef struct hcl_client_t hcl_client_t;
enum hcl_client_option_t
{
HCL_CLIENT_TRAIT,
HCL_CLIENT_LOG_MASK,
};
typedef enum hcl_client_option_t hcl_client_option_t;
enum hcl_client_trait_t
{
/* no trait defined at this moment. XXXX is just a placeholder */
HCL_CLIENT_XXXX = (1 << 0)
};
typedef enum hcl_client_trait_t hcl_client_trait_t;
/* ========================================================================= */
enum hcl_client_state_t
{
HCL_CLIENT_STATE_START,
HCL_CLIENT_STATE_IN_REPLY_NAME,
HCL_CLIENT_STATE_IN_REPLY_VALUE_START,
HCL_CLIENT_STATE_IN_REPLY_VALUE_UNQUOTED,
HCL_CLIENT_STATE_IN_REPLY_VALUE_QUOTED,
HCL_CLIENT_STATE_IN_REPLY_VALUE_QUOTED_TRAILER,
HCL_CLIENT_STATE_IN_ATTR_KEY,
HCL_CLIENT_STATE_IN_ATTR_VALUE_START,
HCL_CLIENT_STATE_IN_ATTR_VALUE_UNQUOTED,
HCL_CLIENT_STATE_IN_ATTR_VALUE_QUOTED,
HCL_CLIENT_STATE_IN_ATTR_VALUE_QUOTED_TRAILER,
HCL_CLIENT_STATE_IN_LENGTH_BOUNDED_DATA,
HCL_CLIENT_STATE_IN_CHUNKED_DATA
};
typedef enum hcl_client_state_t hcl_client_state_t;
/* ========================================================================= */
enum hcl_client_reply_type_t
{
HCL_CLIENT_REPLY_TYPE_OK = 0,
HCL_CLIENT_REPLY_TYPE_ERROR = 1
};
typedef enum hcl_client_reply_type_t hcl_client_reply_type_t;
typedef void (*hcl_client_log_write_t) (
hcl_client_t* client,
hcl_bitmask_t mask,
const hcl_ooch_t* msg,
hcl_oow_t len
);
typedef int (*hcl_client_start_reply_t) (
hcl_client_t* client,
hcl_client_reply_type_t type,
const hcl_ooch_t* dptr,
hcl_oow_t dlen
);
typedef int (*hcl_client_feed_attr_t) (
hcl_client_t* client,
const hcl_oocs_t* key,
const hcl_oocs_t* val
);
typedef int (*hcl_client_start_data_t) (
hcl_client_t* client
);
typedef int (*hcl_client_feed_data_t) (
hcl_client_t* client,
const void* ptr,
hcl_oow_t len
);
typedef int (*hcl_client_end_data_t) (
hcl_client_t* client
);
enum hcl_client_end_reply_state_t
{
HCL_CLIENT_END_REPLY_STATE_OK,
HCL_CLIENT_END_REPLY_STATE_REVOKED
};
typedef enum hcl_client_end_reply_state_t hcl_client_end_reply_state_t;
typedef int (*hcl_client_end_reply_t) (
hcl_client_t* client,
hcl_client_end_reply_state_t state
);
struct hcl_client_prim_t
{
hcl_client_log_write_t log_write;
hcl_client_start_reply_t start_reply; /* mandatory */
hcl_client_feed_attr_t feed_attr; /* optional */
hcl_client_feed_data_t feed_data; /* optional */
hcl_client_end_reply_t end_reply; /* mandatory */
};
typedef struct hcl_client_prim_t hcl_client_prim_t;
/* ========================================================================= */
#if defined(__cplusplus)
extern "C" {
#endif
HCL_EXPORT hcl_client_t* hcl_client_open (
hcl_mmgr_t* mmgr,
hcl_oow_t xtnsize,
hcl_client_prim_t* prim,
hcl_errnum_t* errnum
);
HCL_EXPORT void hcl_client_close (
hcl_client_t* client
);
HCL_EXPORT void hcl_client_reset (
hcl_client_t* client
);
HCL_EXPORT int hcl_client_feed (
hcl_client_t* client,
const void* ptr,
hcl_oow_t len,
hcl_oow_t* xlen
);
HCL_EXPORT hcl_client_state_t hcl_client_getstate (
hcl_client_t* client
);
HCL_EXPORT int hcl_client_setoption (
hcl_client_t* client,
hcl_client_option_t id,
const void* value
);
HCL_EXPORT int hcl_client_getoption (
hcl_client_t* client,
hcl_client_option_t id,
void* value
);
HCL_EXPORT void* hcl_client_getxtn (
hcl_client_t* client
);
HCL_EXPORT hcl_mmgr_t* hcl_client_getmmgr (
hcl_client_t* client
);
HCL_EXPORT hcl_cmgr_t* hcl_client_getcmgr (
hcl_client_t* client
);
HCL_EXPORT void hcl_client_setcmgr (
hcl_client_t* client,
hcl_cmgr_t* cmgr
);
HCL_EXPORT hcl_errnum_t hcl_client_geterrnum (
hcl_client_t* client
);
HCL_EXPORT const hcl_ooch_t* hcl_client_geterrstr (
hcl_client_t* client
);
HCL_EXPORT const hcl_ooch_t* hcl_client_geterrmsg (
hcl_client_t* client
);
HCL_EXPORT void hcl_client_seterrnum (
hcl_client_t* client,
hcl_errnum_t errnum
);
HCL_EXPORT void hcl_client_seterrbfmt (
hcl_client_t* client,
hcl_errnum_t errnum,
const hcl_bch_t* fmt,
...
);
HCL_EXPORT void hcl_client_seterrufmt (
hcl_client_t* client,
hcl_errnum_t errnum,
const hcl_uch_t* fmt,
...
);
HCL_EXPORT void hcl_client_logbfmt (
hcl_client_t* client,
hcl_bitmask_t mask,
const hcl_bch_t* fmt,
...
);
HCL_EXPORT void hcl_client_logufmt (
hcl_client_t* client,
hcl_bitmask_t mask,
const hcl_uch_t* fmt,
...
);
HCL_EXPORT void* hcl_client_allocmem (
hcl_client_t* client,
hcl_oow_t size
);
HCL_EXPORT void* hcl_client_callocmem (
hcl_client_t* client,
hcl_oow_t size
);
HCL_EXPORT void* hcl_client_reallocmem (
hcl_client_t* client,
void* ptr,
hcl_oow_t size
);
HCL_EXPORT void hcl_client_freemem (
hcl_client_t* client,
void* ptr
);
#if defined(__cplusplus)
}
#endif
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,226 +0,0 @@
/*
Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if 0
#ifndef _HCL_S_H_
#define _HCL_S_H_
#include <hcl.h>
typedef struct hcl_server_proto_t hcl_server_proto_t;
typedef struct hcl_server_worker_t hcl_server_worker_t;
typedef struct hcl_server_t hcl_server_t;
enum hcl_server_option_t
{
HCL_SERVER_TRAIT,
HCL_SERVER_LOG_MASK,
HCL_SERVER_WORKER_MAX_COUNT,
HCL_SERVER_WORKER_STACK_SIZE,
HCL_SERVER_WORKER_IDLE_TIMEOUT,
HCL_SERVER_ACTOR_HEAP_SIZE,
HCL_SERVER_ACTOR_MAX_RUNTIME,
HCL_SERVER_SCRIPT_INCLUDE_PATH,
HCL_SERVER_MODULE_INCTX
};
typedef enum hcl_server_option_t hcl_server_option_t;
enum hcl_server_trait_t
{
#if defined(HCL_BUILD_DEBUG)
HCL_SERVER_TRAIT_DEBUG_GC = (1 << 0),
HCL_SERVER_TRAIT_DEBUG_BIGINT = (1 << 1)
#endif
};
typedef enum hcl_server_trait_t hcl_server_trait_t;
#define HCL_SERVER_WID_INVALID ((hcl_oow_t)-1)
#define HCL_SERVER_WID_MAX (HCL_SERVER_WID_INVALID - 1)
typedef void (*hcl_server_log_write_t) (
hcl_server_t* server,
hcl_oow_t wid,
hcl_bitmask_t mask,
const hcl_ooch_t* msg,
hcl_oow_t len
);
struct hcl_server_prim_t
{
hcl_server_log_write_t log_write;
};
typedef struct hcl_server_prim_t hcl_server_prim_t;
#if defined(__cplusplus)
extern "C" {
#endif
HCL_EXPORT hcl_server_t* hcl_server_open (
hcl_mmgr_t* mmgr,
hcl_oow_t xtnsize,
hcl_server_prim_t* prim,
hcl_errnum_t* errnum
);
HCL_EXPORT void hcl_server_close (
hcl_server_t* server
);
HCL_EXPORT int hcl_server_start (
hcl_server_t* server,
const hcl_bch_t* addrs
);
HCL_EXPORT void hcl_server_stop (
hcl_server_t* server
);
HCL_EXPORT int hcl_server_setoption (
hcl_server_t* server,
hcl_server_option_t id,
const void* value
);
HCL_EXPORT int hcl_server_getoption (
hcl_server_t* server,
hcl_server_option_t id,
void* value
);
HCL_EXPORT void* hcl_server_getxtn (
hcl_server_t* server
);
HCL_EXPORT hcl_mmgr_t* hcl_server_getmmgr (
hcl_server_t* server
);
HCL_EXPORT hcl_cmgr_t* hcl_server_getcmgr (
hcl_server_t* server
);
HCL_EXPORT void hcl_server_setcmgr (
hcl_server_t* server,
hcl_cmgr_t* cmgr
);
HCL_EXPORT hcl_errnum_t hcl_server_geterrnum (
hcl_server_t* server
);
HCL_EXPORT const hcl_ooch_t* hcl_server_geterrstr (
hcl_server_t* server
);
HCL_EXPORT const hcl_ooch_t* hcl_server_geterrmsg (
hcl_server_t* server
);
HCL_EXPORT void hcl_server_seterrnum (
hcl_server_t* server,
hcl_errnum_t errnum
);
HCL_EXPORT void hcl_server_seterrbfmt (
hcl_server_t* server,
hcl_errnum_t errnum,
const hcl_bch_t* fmt,
...
);
HCL_EXPORT void hcl_server_seterrufmt (
hcl_server_t* server,
hcl_errnum_t errnum,
const hcl_uch_t* fmt,
...
);
HCL_EXPORT void hcl_server_logbfmt (
hcl_server_t* server,
hcl_bitmask_t mask,
const hcl_bch_t* fmt,
...
);
HCL_EXPORT void hcl_server_logufmt (
hcl_server_t* server,
hcl_bitmask_t mask,
const hcl_uch_t* fmt,
...
);
HCL_EXPORT void* hcl_server_allocmem (
hcl_server_t* server,
hcl_oow_t size
);
HCL_EXPORT void* hcl_server_callocmem (
hcl_server_t* server,
hcl_oow_t size
);
HCL_EXPORT void* hcl_server_reallocmem (
hcl_server_t* server,
void* ptr,
hcl_oow_t size
);
HCL_EXPORT void hcl_server_freemem (
hcl_server_t* server,
void* ptr
);
HCL_EXPORT int hcl_server_proto_feed_reply (
hcl_server_proto_t* proto,
const hcl_ooch_t* ptr,
hcl_oow_t len,
int escape
);
HCL_EXPORT int hcl_server_proto_feed_reply_bytes (
hcl_server_proto_t* proto,
const hcl_bch_t* ptr,
hcl_oow_t len,
int escape
);
HCL_EXPORT int hcl_server_proto_handle_request (
hcl_server_proto_t* proto
);
#if defined(__cplusplus)
}
#endif
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -25,8 +25,8 @@
#ifndef _HCL_X_T_
#define _HCL_X_T_
/*#include <hcl-cmn.h>*/
#include <hcl.h>
#include <sys/uio.h>
enum hcl_xpkt_type_t
{
@ -85,6 +85,11 @@ typedef struct hcl_xproto_cb_t hcl_xproto_cb_t;
/* ---------------------------------------------------------------------- */
/* forward declaration to skip including <sys/uio.h> just for struct iovec */
typedef struct iovec hcl_iovec_t;
/* ---------------------------------------------------------------------- */
typedef struct hcl_server_proto_t hcl_server_proto_t;
typedef struct hcl_server_worker_t hcl_server_worker_t;
typedef struct hcl_server_t hcl_server_t;
@ -426,33 +431,41 @@ HCL_EXPORT void* hcl_xproto_getxtn (
hcl_xproto_t* proto
);
hcl_uint8_t* hcl_xproto_getbuf (
HCL_EXPORT hcl_uint8_t* hcl_xproto_getbuf (
hcl_xproto_t* proto,
hcl_oow_t* capa
);
int hcl_xproto_geteof (
HCL_EXPORT int hcl_xproto_geteof (
hcl_xproto_t* proto
);
void hcl_xproto_seteof (
HCL_EXPORT void hcl_xproto_seteof (
hcl_xproto_t* proto,
int v
);
void hcl_xproto_advbuf (
HCL_EXPORT void hcl_xproto_advbuf (
hcl_xproto_t* proto,
hcl_oow_t inc
);
int hcl_xproto_ready (
HCL_EXPORT int hcl_xproto_ready (
hcl_xproto_t* proto
);
int hcl_xproto_process (
HCL_EXPORT int hcl_xproto_process (
hcl_xproto_t* proto
);
/* ---------------------------------------------------------------------- */
HCL_EXPORT int hcl_sys_send_iov (
int sck,
hcl_iovec_t* iov, /* note this is not read-only and can change */
int count
);
#if defined(__cplusplus)
}
#endif

View File

@ -994,39 +994,6 @@ oops:
return -1;
}
static int send_iov (int sck, struct iovec* iov, int count)
{
int index = 0;
while (1)
{
ssize_t nwritten;
struct msghdr msg;
memset (&msg, 0, HCL_SIZEOF(msg));
msg.msg_iov = (struct iovec*)&iov[index];
msg.msg_iovlen = count - index;
nwritten = sendmsg(sck, &msg, 0);
if (nwritten <= -1)
{
/* error occurred inside the worker thread shouldn't affect the error information
* in the server object. so here, i just log a message */
fprintf (stderr, "Unable to sendmsg on %d - %s\n", sck, strerror(errno));
return -1;
}
while (index < count && (size_t)nwritten >= iov[index].iov_len)
nwritten -= iov[index++].iov_len;
if (index == count) break;
iov[index].iov_base = (void*)((hcl_uint8_t*)iov[index].iov_base + nwritten);
iov[index].iov_len -= nwritten;
}
return 0;
}
static int send_stdout_bytes (hcl_xproto_t* proto, const hcl_bch_t* data, hcl_oow_t len)
{
hcl_server_worker_t* worker;
@ -1056,9 +1023,10 @@ printf ("SENDING BYTES [%.*s]\n", (int)len, data);
iov[1].iov_base = ptr;
iov[1].iov_len = seglen;
if (send_iov(worker->sck, iov, 2) <= -1)
if (hcl_sys_send_iov(worker->sck, iov, 2) <= -1)
{
/* TODO: error message */
fprintf (stderr, "Unable to sendmsg on %d - %s\n", worker->sck, strerror(errno));
return -1;
}
@ -2283,3 +2251,32 @@ void hcl_server_freemem (hcl_server_t* server, void* ptr)
{
HCL_MMGR_FREE (server->_mmgr, ptr);
}
/* ========================================================================= */
int hcl_sys_send_iov (int sck, hcl_iovec_t* iov, int count)
{
int index = 0;
while (1)
{
ssize_t nwritten;
struct msghdr msg;
memset (&msg, 0, HCL_SIZEOF(msg));
msg.msg_iov = (struct iovec*)&iov[index];
msg.msg_iovlen = count - index;
nwritten = sendmsg(sck, &msg, 0);
if (nwritten <= -1) return -1;
while (index < count && (size_t)nwritten >= iov[index].iov_len)
nwritten -= iov[index++].iov_len;
if (index == count) break;
iov[index].iov_base = (void*)((hcl_uint8_t*)iov[index].iov_base + nwritten);
iov[index].iov_len -= nwritten;
}
return 0;
}