diff options
Diffstat (limited to 'src/nSocket/nstack')
-rw-r--r-- | src/nSocket/nstack/nstack.c | 38 | ||||
-rw-r--r-- | src/nSocket/nstack/nstack_info_parse.c | 48 | ||||
-rw-r--r-- | src/nSocket/nstack/nstack_module.h | 5 | ||||
-rw-r--r-- | src/nSocket/nstack/nstack_socket.c | 95 |
4 files changed, 118 insertions, 68 deletions
diff --git a/src/nSocket/nstack/nstack.c b/src/nSocket/nstack/nstack.c index 225c297..9d6a2ba 100644 --- a/src/nSocket/nstack/nstack.c +++ b/src/nSocket/nstack/nstack.c @@ -285,44 +285,8 @@ match_version (char *nstack_ver, char *my_ver) return 0; } - char *nstack_ver_head = NULL; - char *my_ver_head = NULL; - char nstack_version[NSTACK_VERSION_LEN] = { 0 }; - char my_version[NSTACK_VERSION_LEN] = { 0 }; - - // !!!STRTOK_S will modify the original string, so use use temp for parameter - /* use STRCPY_S instead of MEMCPY_S to avoid invalid memory visit */ - if (EOK != STRCPY_S (nstack_version, sizeof (nstack_version), nstack_ver)) - { - return 0; - } - - nstack_ver_head = get_ver_head (nstack_version); - if (NULL == nstack_ver_head) - { - return 0; - } - - /*use STRCPY_S instead of MEMCPY_S to avoid invalid memory visit */ - if (EOK != STRCPY_S (my_version, sizeof (my_version), my_ver)) - { - return 0; - } - - my_ver_head = get_ver_head (my_version); - if (NULL == my_ver_head) - { - return 0; - } - - if (strlen (my_ver_head) != strlen (nstack_ver_head)) - { - return 0; - } - - - if (0 != strncmp (nstack_ver_head, my_ver_head, strlen (nstack_ver_head))) + if (0 != strncmp (nstack_ver, my_ver, 5)) { return 0; } diff --git a/src/nSocket/nstack/nstack_info_parse.c b/src/nSocket/nstack/nstack_info_parse.c index 04abb4e..8b2d62f 100644 --- a/src/nSocket/nstack/nstack_info_parse.c +++ b/src/nSocket/nstack/nstack_info_parse.c @@ -66,8 +66,14 @@ } \ else \ { \ - NSSOC_LOGERR("can't get obj from %s index:%d", name, (index)); \ - goto RETURN_ERROR; \ + if (strcmp(name, "deploytype") == 0 || strcmp(name, "stackid") == 0) \ + { \ + NSSOC_LOGERR("can't get obj from %s index:%d", name, (index)); \ + } \ + else\ + { \ + NSSOC_LOGWAR("can't get obj from %s index:%d", name, (index)); \ + } \ } \ } while ( 0 ); @@ -85,6 +91,7 @@ nstack_parse_module_cfg_json (char *param) int ret = NSTACK_RETURN_FAIL; int index = 0; int icnt = 0; + int ret_val; if (!obj) { @@ -125,10 +132,21 @@ nstack_parse_module_cfg_json (char *param) NSTACK_JSON_PARSE_STRING (module_obj, "stack_name", MODULE_NAME_MAX, &(g_nstack_module_desc[icnt].modName[0]), index); - NSTACK_JSON_PARSE_STRING (module_obj, "function_name", - MODULE_NAME_MAX, - &(g_nstack_module_desc - [icnt].register_fn_name[0]), index); + STRCPY_S (&(g_nstack_module_desc[icnt].register_fn_name[0]), + sizeof (& + (g_nstack_module_desc[icnt].register_fn_name[0])), + &(g_nstack_module_desc[icnt].modName[0])); + ret_val = + STRCAT_S (&(g_nstack_module_desc[icnt].register_fn_name[0]), + sizeof (& + (g_nstack_module_desc[icnt].register_fn_name + [0])), "_stack_register"); + if (EOK != ret_val) + { + NSFW_LOGERR ("register_fn_name STRCAT_S failed]ret_val=%d", + ret_val); + return -1; + } NSTACK_JSON_PARSE_STRING (module_obj, "libname", MODULE_NAME_MAX, &(g_nstack_module_desc[icnt].libPath[0]), index); @@ -149,14 +167,28 @@ nstack_parse_module_cfg_json (char *param) } else { - NSSOC_LOGERR ("can't get value from loadtype index:%d", index); - goto RETURN_ERROR; + if (strcmp (g_nstack_module_desc[icnt].modName, "kernel") == 0) + { + g_nstack_module_desc[icnt].libtype = NSTACK_LIB_LOAD_STATIC; + } + else + { + g_nstack_module_desc[icnt].libtype = NSTACK_LIB_LOAD_DYN; + } + NSSOC_LOGWAR ("can't get the value of loadtype for module:%s", + g_nstack_module_desc[icnt].modName); } + NSSBR_LOGINF ("load type of %d has been chosen", + g_nstack_module_desc[icnt].libtype); NSTACK_JSON_PARSE_INT (module_obj, "deploytype", MODULE_NAME_MAX, g_nstack_module_desc[icnt].deploytype, index); NSTACK_JSON_PARSE_INT (module_obj, "maxfd", MODULE_NAME_MAX, g_nstack_module_desc[icnt].maxfdid, index); + if (g_nstack_module_desc[icnt].maxfdid == 0) + { + g_nstack_module_desc[icnt].maxfdid = 1024; + } NSTACK_JSON_PARSE_INT (module_obj, "minfd", MODULE_NAME_MAX, g_nstack_module_desc[icnt].minfdid, index); NSTACK_JSON_PARSE_INT (module_obj, "priorty", MODULE_NAME_MAX, diff --git a/src/nSocket/nstack/nstack_module.h b/src/nSocket/nstack/nstack_module.h index ec81ac1..40a2ef8 100644 --- a/src/nSocket/nstack/nstack_module.h +++ b/src/nSocket/nstack/nstack_module.h @@ -38,11 +38,6 @@ extern "C"{ #define NSTACK_MAX_MODULE_NUM 8 #define NSTACK_PRO_MODULE 1 -#define MIN_SOCK_FOR_STACKX 0 - -#define MOD_PRI_FOR_STACKX 1 -#define REG_FUN_FOR_STACKX "nstack_stack_register" - #define NSTACK_EP_FREE_NEED_REF 1 /*when epoll information free, need to wait that stack would not notify event */ #define NSTACK_EP_FREE_NONEED_REF 0 diff --git a/src/nSocket/nstack/nstack_socket.c b/src/nSocket/nstack/nstack_socket.c index c967d64..210e29d 100644 --- a/src/nSocket/nstack/nstack_socket.c +++ b/src/nSocket/nstack/nstack_socket.c @@ -141,12 +141,10 @@ int nstack_socket (int domain, int itype, int protocol) { int ret = -1; //tmp ret of a Single proctol mode. - int rdret = -1; //the final Return judge vale. int modInx; nstack_socket_ops *ops; int ret_fd = -1; int protoFD[NSTACK_MAX_MODULE_NUM]; - nstack_rd_key rdkey = { 0 }; int selectmod = -1; /*check whether module init finish or not */ @@ -183,22 +181,6 @@ nstack_socket (int domain, int itype, int protocol) nstack_fd_local_lock_info_t *lock_info = get_fd_local_lock_info (ret_fd); LOCK_FOR_EP (lock_info); - - /*check wether select stack create success, if no return fail */ - rdkey.type = RD_DATA_TYPE_PROTO; - rdkey.proto_type = itype; - rdret = nstack_rd_get_stackid (&rdkey, &selectmod); - if ((0 != rdret) || (selectmod < 0) || (selectmod >= nstack_get_modNum ())) - { - NSSOC_LOGERR ("protocol:%d select stack fail", protocol); - selectmod = -1; - } - else - { - NSSOC_LOGINF ("Create socket of]select modName=%s", - nstack_get_module_name_by_idx (selectmod)); - } - /*create socket by calling select module or all module */ nstack_each_modOps (modInx, ops) { @@ -389,6 +371,26 @@ nstack_bind (int fd, const struct sockaddr *addr, socklen_t addrlen) nstack_get_module_name_by_idx (selectmod)); } + if (selectmod == -1) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGWAR + ("fd Can't select any module for]fd=%d,IP==%s using proto route", + fd, inet_ntoa ((iaddr->sin_addr))); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Bind socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } + retval = -1; nstack_each_modInx (modIdx) { @@ -902,6 +904,25 @@ nstack_connect (int fd, const struct sockaddr *addr, socklen_t addrlen) rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Connect socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if (ns_success == retval && selectmod >= 0) { NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", @@ -1385,6 +1406,25 @@ nstack_sendto (int fd, const void *buf, size_t len, int flags, rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("sendto socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if ((ns_success == retval) && (selectmod >= 0)) { NSSOC_LOGINF ("fd=%d,addr=%s,select_module=%s", @@ -1472,6 +1512,25 @@ nstack_sendmsg (int fd, const struct msghdr * msg, int flags) rdkey.type = RD_DATA_TYPE_IP; rdkey.ip_addr = iaddr->sin_addr.s_addr; retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod == -1)) + { + rdkey.type = RD_DATA_TYPE_PROTO; + rdkey.proto_type = fdInf->type; + retval = nstack_rd_get_stackid (&rdkey, &selectmod); + if ((0 != retval) || (selectmod < 0) + || (selectmod >= nstack_get_modNum ())) + { + NSSOC_LOGINF ("fd=%d addr=%s Select module=%s", + fd, inet_ntoa (iaddr->sin_addr), + nstack_get_module_name_by_idx (selectmod)); + selectmod = -1; + } + else + { + NSSOC_LOGINF ("Connect socket of]select modName=%s", + nstack_get_module_name_by_idx (selectmod)); + } + } if (ns_success == retval) { NSSOC_LOGINF ("fd=%d,addr=%s,select_module=%s", |