aboutsummaryrefslogtreecommitdiffstats
path: root/src/nSocket/nstack/nstack_socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nSocket/nstack/nstack_socket.c')
-rw-r--r--src/nSocket/nstack/nstack_socket.c124
1 files changed, 107 insertions, 17 deletions
diff --git a/src/nSocket/nstack/nstack_socket.c b/src/nSocket/nstack/nstack_socket.c
index 1b7a416..130d08f 100644
--- a/src/nSocket/nstack/nstack_socket.c
+++ b/src/nSocket/nstack/nstack_socket.c
@@ -144,12 +144,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 */
@@ -187,21 +185,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)
{
@@ -392,6 +375,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)
{
@@ -905,6 +908,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",
@@ -1390,6 +1412,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",
@@ -1477,6 +1518,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",
@@ -2812,3 +2872,33 @@ nstack_fork (void)
dmm_write_unlock (get_fork_lock ());
return pid;
}
+
+int
+nstack_run (void *loop)
+{
+ int i;
+
+ nstack_each_modInx (i)
+ {
+ if (nstack_extern_deal (i).run)
+ {
+ nstack_extern_deal (i).run (loop);
+ }
+ }
+ return 0;
+}
+
+int
+nstack_epoll_prewait ()
+{
+ int i;
+
+ nstack_each_modInx (i)
+ {
+ if (nstack_extern_deal (i).ep_prewait)
+ {
+ nstack_extern_deal (i).ep_prewait ();
+ }
+ }
+ return 0;
+}