|
version 1.22.6.1, 2014/01/28 13:56:25
|
version 1.23.6.1, 2014/11/17 23:28:55
|
|
Line 12 terms:
|
Line 12 terms:
|
| All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
|
| Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 | Copyright 2004 - 2014 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
|
| Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
|
Line 1290 rpc_srv_execCall(rpc_cli_t * __restrict cli, struct ta
|
Line 1290 rpc_srv_execCall(rpc_cli_t * __restrict cli, struct ta
|
| func = AIT_GET_LIKE(&funcname, rpc_callback_t); |
func = AIT_GET_LIKE(&funcname, rpc_callback_t); |
| return func(cli, rpc, args); |
return func(cli, rpc, args); |
| } |
} |
| |
|
| |
|
| |
/* |
| |
* rpc_srv_initServer2() - Init & create layer2 RPC Server |
| |
* |
| |
* @InstID = Instance for authentication & recognition |
| |
* @concurentClients = Concurent clients at same time to this server |
| |
* @netBuf = Network buffer length (min:512 bytes), if =0 == BUFSIZ (also meaning max RPC packet) |
| |
* @csIface = Interface name for bind server, if NULL first interface on host |
| |
* @protoNum = Protocol ethernet number for bind server, if Port == 0 default port is selected |
| |
* return: NULL == error or !=NULL bind and created RPC server instance |
| |
*/ |
| |
rpc_srv_t * |
| |
rpc_srv_initServer2(u_char InstID, int concurentClients, int netBuf, |
| |
const char *csIface, u_short protoNum) |
| |
{ |
| |
int n = 1; |
| |
rpc_srv_t *srv = NULL; |
| |
sockaddr_t sa = E_SOCKADDR_INIT; |
| |
char szIface[64], szStr[STRSIZ]; |
| |
register int i; |
| |
struct ifreq ifr; |
| |
|
| |
if (!concurentClients) { |
| |
rpc_SetErr(EINVAL, "Invalid parameters can`t init RPC server"); |
| |
return NULL; |
| |
} |
| |
if (!csIface) { |
| |
if (e_get1stiface(szIface, sizeof szIface)) |
| |
return NULL; |
| |
} else |
| |
strlcpy(szIface, csIface, sizeof szIface); |
| |
if (e_getifacebyname(szIface, &sa)) |
| |
return NULL; |
| |
if (!protoNum) |
| |
protoNum = RPC_DEFPORT; |
| |
|
| |
#ifdef HAVE_SRANDOMDEV |
| |
srandomdev(); |
| |
#else |
| |
time_t tim; |
| |
|
| |
srandom((time(&tim) ^ getpid())); |
| |
#endif |
| |
|
| |
srv = e_malloc(sizeof(rpc_srv_t)); |
| |
if (!srv) { |
| |
LOGERR; |
| |
return NULL; |
| |
} else |
| |
memset(srv, 0, sizeof(rpc_srv_t)); |
| |
|
| |
srv->srv_proto = protoNum; |
| |
srv->srv_netbuf = netBuf; |
| |
srv->srv_session.sess_version = RPC_VERSION; |
| |
srv->srv_session.sess_instance = InstID; |
| |
|
| |
srv->srv_server.cli_parent = srv; |
| |
memcpy(&srv->srv_server.cli_sa, &sa, sizeof srv->srv_server.cli_sa); |
| |
|
| |
/* init functions */ |
| |
pthread_mutex_init(&srv->srv_funcs.mtx, NULL); |
| |
SLIST_INIT(&srv->srv_funcs); |
| |
AVL_INIT(&srv->srv_funcs); |
| |
|
| |
/* init scheduler */ |
| |
srv->srv_root = schedBegin(); |
| |
if (!srv->srv_root) { |
| |
rpc_SetErr(sched_GetErrno(), "%s", sched_GetError()); |
| |
pthread_mutex_destroy(&srv->srv_funcs.mtx); |
| |
e_free(srv); |
| |
return NULL; |
| |
} |
| |
|
| |
/* init pool for clients */ |
| |
srv->srv_clients = array_Init(concurentClients); |
| |
if (!srv->srv_clients) { |
| |
rpc_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); |
| |
schedEnd(&srv->srv_root); |
| |
pthread_mutex_destroy(&srv->srv_funcs.mtx); |
| |
e_free(srv); |
| |
return NULL; |
| |
} |
| |
|
| |
/* create server handler */ |
| |
for (i = 0; i < 10; i++) { |
| |
memset(szStr, 0, sizeof szStr); |
| |
snprintf(szStr, sizeof szStr, "/dev/bpf%d", i); |
| |
srv->srv_server.cli_sock = open(szStr, O_RDWR); |
| |
if (srv->srv_server.cli_sock > STDERR_FILENO) |
| |
break; |
| |
} |
| |
if (srv->srv_server.cli_sock < 3) { |
| |
LOGERR; |
| |
array_Destroy(&srv->srv_clients); |
| |
schedEnd(&srv->srv_root); |
| |
pthread_mutex_destroy(&srv->srv_funcs.mtx); |
| |
e_free(srv); |
| |
return NULL; |
| |
} |
| |
|
| |
if (ioctl(srv->srv_server.cli_sock, BIOCIMMEDIATE, &n) == -1) { |
| |
LOGERR; |
| |
goto err; |
| |
} |
| |
n = (netBuf < RPC_MIN_BUFSIZ) ? getpagesize() : E_ALIGN(netBuf, 2); |
| |
if (ioctl(srv->srv_server.cli_sock, BIOCSBLEN, &n) == -1) { |
| |
LOGERR; |
| |
goto err; |
| |
} else |
| |
srv->srv_netbuf = n; |
| |
|
| |
memset(&ifr, 0, sizeof ifr); |
| |
strlcpy(ifr.ifr_name, szIface, sizeof ifr.ifr_name); |
| |
if (ioctl(srv->srv_server.cli_sock, BIOCSETIF, &ifr) == -1) { |
| |
LOGERR; |
| |
goto err; |
| |
} else |
| |
fcntl(srv->srv_server.cli_sock, F_SETFL, |
| |
fcntl(srv->srv_server.cli_sock, F_GETFL) | O_NONBLOCK); |
| |
|
| |
rpc_register_srvPing(srv); |
| |
|
| |
return srv; |
| |
err: /* error condition */ |
| |
close(srv->srv_server.cli_sock); |
| |
array_Destroy(&srv->srv_clients); |
| |
schedEnd(&srv->srv_root); |
| |
pthread_mutex_destroy(&srv->srv_funcs.mtx); |
| |
e_free(srv); |
| |
return NULL; |
| |
} |
| |
|