10#ifdef _VCOM_SUPPORT_TLS
14#define VC_PULL_TIME 10000000
15#define VC_PULL_PSEC (VC_PULL_TIME / 1000000)
16#define VC_PULL_PUSEC (VC_PULL_TIME % 1000000)
20#define VC_TIME_USED(a) (VC_PULL_TIME - (a.tv_sec * 1000000 + a.tv_usec));
22#define stk_full(a) ((a)->top>=STACK_MAX-1)
23#define stk_empty(a) ((a)->top<0)
24#define stk_bot(a) ((a)->top==0)
36#ifdef _VCOM_SUPPORT_TLS
53#define attr_p(a, b) (((a)->attr[(a)->attr_ptr]).b)
54#define eki_p(a, b) ((a)->eki.b)
56#define check_attr_stat(a, b) (attr_p(a, b) == eki_p(a, b)?ATTR_SAME:ATTR_DIFF)
58#define update_eki_attr(a, b, c) do{eki_p(a, b) = c;}while(0)
70 struct vc_ops * (*event)(
struct vc_attr *,
struct timeval *, fd_set *r, fd_set *w, fd_set *e);
73#define try_ops1(a, b, c) (((a)->b > 0)?(a)->b(c):a)
74#define try_ops2(a, b, c, d) (((a)->b > 0)?(a)->b(c, d):a)
75#define try_ops3(a, b, c, d, e) (((a)->b > 0)?(a)->b(c, d, e):a)
76#define try_ops4(a, b, c, d, e, f) (((a)->b > 0)?(a)->b(c, d, e, f):a)
77#define try_ops5(a, b, c, d, e, f, g) (((a)->b > 0)?(a)->b(c, d, e, f, g):a)
79#define try_ovrld(_1, _2, _3, _4, _5, _6, _7, func,...) func
80#define try_ops(args...) try_ovrld(args, try_ops5 \
86static inline struct vc_ops * stk_curnt(
struct stk_vc *stk);
95#ifndef _VCOM_MONITOR_H
96#define mon_update(...) do{}while(0)
97#define mon_init(a) do{}while(0)
98#define mon_update_check(...) do{}while(0)
101#define EXCP_SLEEPTIME 3
102#define EXCP_RECONN_TIME 5
107#define INO_PUSH_SWITCH 0
108#define INO_POP_SWITCH 0
109#define INO_RPLS_SWITCH 0
110#define INO_RESTART_SWITCH 0
115static inline int _stk_log(
struct stk_vc *stk,
char * __form, ...)
123 if(stk == 0 || stk->
top < 0){
124 printf(
"%s on empty stk\n", __func__);
128 len += snprintf(tmp,
sizeof(tmp),
"(%s)",
129 stk_curnt(stk)->
name());
131 va_start(args, __form);
132 len += vsnprintf(&tmp[
len],
sizeof(tmp) -
len , __form, args);
150#define _expmsg_extra(msg, len, ...) \
151do{ int r; if(stk->top >= 0) {\
152_Pragma("GCC diagnostic ignored \"-Wformat-zero-length\"")\
153 r= snprintf(msg, len, "(%s)%s,%d:", stk->stk_stat[stk->top]->name(), \
154 __func__, __LINE__); \
155 snprintf(&msg[r],len -r, "" __VA_ARGS__);\
157 r= snprintf(msg, len, "(NULL)%s,%d:", __func__, __LINE__ ); \
158 snprintf(&msg[r],len -r, "" __VA_ARGS__);\
160_Pragma("GCC diagnostic warning \"-Wformat-zero-length\"")\
163#define stk_push(a, b) _stk_push(a, b)
168 printf(
"%s : stack full\n", __func__);
179#define stk_pop(a) _stk_pop(a)
181_stk_pop(
struct stk_vc *stk)
184 printf(
"%s : stack empty\n", __func__);
195#define stk_excp(a, ...) do{char msg[256]; _expmsg_extra(msg, sizeof(msg),\
197 _stk_excp(a, msg);}while(0)
199_stk_excp(
struct stk_vc *stk,
char * msg)
201 static time_t pre_excp_t = 0;
205 printf(
"%s : at the bottom of stack now\n", __func__);
209 printf(
"stack exception !! %s\n", msg);
220 pre_excp_t = now_excp_t;
226#define stk_rpls(a, b) _stk_rpls(a, b)
236static inline struct vc_ops * stk_curnt(
struct stk_vc *stk)
239 printf(
"%s : no state in stack\n", __func__);
246#define stk_restart(a) _stk_restart(a)
248_stk_restart(
struct stk_vc *stk)
251 printf(
"at the bottom of stack now, should not call <%s> ...\n", __func__);
260static inline int __vc_sock_enblock(
int sk,
int enable)
263 skarg = fcntl(sk, F_GETFL, 0);
265 printf(
"failed to GETFL\n");
274 skarg &= ~O_NONBLOCK;
278 if( fcntl(sk, F_SETFL, skarg) < 0){
279 printf(
"failed to SETFL\n");
286#define VC_SKOPT_BLOCK 0
287#define VC_SKOPT_NONBLOCK 1
288#define VC_SKOPT_ENKALIVE 2
289#define VC_SKOPT_DISKALIVE 3
293static inline int vc_config_sock(
int sk,
int option,
void * arg)
296#define OPT_ISMATCH(OPT, TMP) (OPT==TMP?1:0)
312#define VC_MAX_SKNUM 16
313#define VC_PROTO_PORT 5202
314#define VC_SSL_PROXY 5555
316static inline int __set_sockaddr_port(
struct addrinfo *info,
unsigned short port)
318 struct sockaddr_in * sin;
319 struct sockaddr_in6 * sin6;
321 switch(info->ai_family){
323 printf(
"adding port %u to IPv4 address\n", port);
324 sin = (
struct sockaddr_in *)info->ai_addr;
325 sin->sin_port = htons(port);
328 printf(
"adding port %u to IPv6 address\n", port);
329 sin6 = (
struct sockaddr_in6 *)info->ai_addr;
330 sin6->sin6_port = htons(port);
333 printf(
"unknown address type cannot add port\n");
342static inline int fdcheck(
int fd,
int type,
struct timeval * ctv)
361 ret = select(fd + 1, &rfds, &wfds, 0, ctv);
363 ret = select(fd + 1, &rfds, &wfds, 0, &tv);
371 if(FD_ISSET(fd, &rfds)){
375 if(FD_ISSET(fd, &wfds)){
382static inline int vc_check_send(
struct vc_attr *attr,
385#ifdef _VCOM_SUPPORT_TLS
391 if(
ssl_send_simple(attr->ssl, packet, plen, 1000, &ssl_errno) != plen){
392 char ssl_errstr[256];
393 printf(
"failed to send %s over SSL\n", dbg_msg);
397 _stk_log(stk,
"%s;%s", dbg_msg, ssl_errstr);
404 printf(
"cannot send %s\n", dbg_msg);
408 if(send(attr->
sk, packet, plen, MSG_NOSIGNAL) != plen){
409 printf(
"failed to send %s\n", dbg_msg);
419static inline int vc_buf_update(
struct vc_attr * port,
int rb_id)
441 printf(
"get attrptr failed\n");
445 printf(
"unknown buf type\n");
449 if(ioctl(fd, cmd_head, &
head) < 0){
450 printf(
"cannot get head\n");
454 if(ioctl(fd, cmd_tail, &
tail) < 0){
455 printf(
"cannot get tail\n");
465static inline void vc_buf_clear(
struct vc_attr * port,
unsigned int clrflags)
470 printf(
"couldn't set iocsclr\n");
475 printf(
"move RX head failed\n");
484static inline int vc_buf_setup(
struct vc_attr * port,
int rb_id)
488 char * mbase = port->
mbase;
509 printf(
"unknown buf type\n");
513 if(ioctl(fd, cmd_begin, &
begin)){
520 if(ioctl(fd, cmd_size, &
size)){
521 printf(
"failed to get size\n");
526 buf->mbase = &mbase[
begin];
534 return vc_buf_update(port, rb_id);
#define ADV_CLR_TX
Definition advioctl.h:30
#define ADVVCOM_IOCGRXTAIL
Definition advioctl.h:8
#define ADVVCOM_IOCSCLR
Definition advioctl.h:18
#define ADVVCOM_IOCGTXBEGIN
Definition advioctl.h:12
#define ADVVCOM_IOCGRXHEAD
Definition advioctl.h:7
#define ADVVCOM_IOCGTXHEAD
Definition advioctl.h:4
#define ADV_CLR_RX
Definition advioctl.h:29
#define ADVVCOM_IOCGRXSIZE
Definition advioctl.h:9
#define ADVVCOM_IOCGATTRPTR
Definition advioctl.h:15
#define ADVVCOM_IOCGTXTAIL
Definition advioctl.h:5
#define ADVVCOM_IOCGATTRBEGIN
Definition advioctl.h:14
#define ADVVCOM_IOCGTXSIZE
Definition advioctl.h:6
#define ADVVCOM_IOCSRXHEAD
Definition advioctl.h:11
#define ADVVCOM_IOCGRXBEGIN
Definition advioctl.h:13
int ssl_errno_str(ssl_info *info, int ssl_errno, char *buf, int buflen)
Definition ssl_select.c:301
int ssl_send_simple(ssl_info *info, void *buf, int len, int to_ms, int *ssl_errno)
int head
Definition advvcom.h:27
int size
Definition advvcom.h:30
int begin
Definition advvcom.h:29
int tail
Definition advvcom.h:28
Definition ssl_select.h:18
struct vc_ops * stk_stat[STACK_MAX]
Definition vcom.h:27
int top
Definition vcom.h:26
int ttyid
Definition vcom.h:35
struct adv_port_info eki
Definition vcom.h:46
int sk
Definition vcom.h:32
int fd
Definition vcom.h:31
unsigned short devid
Definition vcom.h:41
unsigned int tid
Definition vcom.h:40
unsigned int port
Definition vcom.h:39
void * mbase
Definition vcom.h:43
struct adv_port_info * attr
Definition vcom.h:47
char * ip_ptr
Definition vcom.h:44
int xmit_pending
Definition vcom.h:34
int attr_ptr
Definition vcom.h:33
struct ring_buf rx
Definition vcom.h:49
char * ip_red
Definition vcom.h:45
struct ring_buf tx
Definition vcom.h:48
struct stk_vc stk
Definition vcom.h:42
char *(* name)(void)
Definition vcom.h:71
Definition vcom_proto.h:52
struct vc_ops vc_netdown_ops
Definition vc_client_netdown.c:27
#define INO_RPLS_SWITCH
Definition vcom.h:109
#define FD_WR_RDY
Definition vcom.h:340
#define VC_SKOPT_ENKALIVE
Definition vcom.h:288
#define STACK_MAX
Definition vcom.h:21
#define VC_BUF_TX
Definition vcom.h:417
#define EXCP_SLEEPTIME
Definition vcom.h:101
#define OPT_ISMATCH(OPT, TMP)
#define VC_SKOPT_DISKALIVE
Definition vcom.h:289
#define VC_BUF_RX
Definition vcom.h:416
#define VC_SKOPT_NONBLOCK
Definition vcom.h:287
#define INO_RESTART_SWITCH
Definition vcom.h:110
#define stk_full(a)
Definition vcom.h:22
struct vc_ops vc_netup_ops
Definition vc_client_netup.c:28
#define VC_BUF_ATTR
Definition vcom.h:418
#define mon_update_check(...)
Definition vcom.h:98
#define stk_bot(a)
Definition vcom.h:24
#define INO_PUSH_SWITCH
Definition vcom.h:107
#define INO_POP_SWITCH
Definition vcom.h:108
void * stk_mon
Definition vcom_client.c:33
#define stk_empty(a)
Definition vcom.h:23
#define EXCP_RECONN_TIME
Definition vcom.h:102
#define VC_SKOPT_BLOCK
Definition vcom.h:286
#define FD_RD_RDY
Definition vcom.h:339
unsigned short len
Definition vcom_proto.h:3