Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src add rumpuser_sp_fini, which surpringly is the opposite of ru...



details:   https://anonhg.NetBSD.org/src/rev/bebb8433fa8a
branches:  trunk
changeset: 759543:bebb8433fa8a
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Dec 12 17:10:36 2010 +0000

description:
add rumpuser_sp_fini, which surpringly is the opposite of rumpuser_sp_init

diffstat:

 lib/librumpuser/rumpuser_sp.c    |  43 +++++++++++++++++++++++++++++++++++++--
 sys/rump/include/rump/rumpuser.h |   3 +-
 2 files changed, 42 insertions(+), 4 deletions(-)

diffs (113 lines):

diff -r 68cf68edb456 -r bebb8433fa8a lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c     Sun Dec 12 16:27:24 2010 +0000
+++ b/lib/librumpuser/rumpuser_sp.c     Sun Dec 12 17:10:36 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpuser_sp.c,v 1.23 2010/12/12 13:48:55 pooka Exp $  */
+/*      $NetBSD: rumpuser_sp.c,v 1.24 2010/12/12 17:10:36 pooka Exp $  */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.23 2010/12/12 13:48:55 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.24 2010/12/12 17:10:36 pooka Exp $");
 
 #include <sys/types.h>
 #include <sys/atomic.h>
@@ -77,6 +77,7 @@
 static struct pollfd pfdlist[MAXCLI];
 static struct spclient spclist[MAXCLI];
 static unsigned int disco;
+static volatile int spfini;
 
 static struct rumpuser_sp_ops spops;
 
@@ -378,6 +379,24 @@
        spcrelease(spc);
 }
 
+static void
+serv_shutdown(void)
+{
+       struct spclient *spc;
+       unsigned int i;
+
+       for (i = 1; i < MAXCLI; i++) {
+               spc = &spclist[i];
+               if (spc->spc_fd == -1)
+                       continue;
+
+               shutdown(spc->spc_fd, SHUT_RDWR);
+               serv_handledisco(i);
+
+               spcrelease(spc);
+       }
+}
+
 static unsigned
 serv_handleconn(int fd, connecthook_fn connhook, int busy)
 {
@@ -680,8 +699,9 @@
                spc = &spclist[idx];
                pthread_mutex_init(&spc->spc_mtx, NULL);
                pthread_cond_init(&spc->spc_cv, NULL);
+               spc->spc_fd = -1;
        }
-       pfdlist[0].fd = sarg->sps_sock;
+       pfdlist[0].fd = spclist[0].spc_fd = sarg->sps_sock;
        pfdlist[0].events = POLLIN;
        nfds = 1;
        maxidx = 0;
@@ -765,6 +785,12 @@
                        } else {
                                DPRINTF(("rump_sp: mainloop new connection\n"));
 
+                               if (__predict_false(spfini)) {
+                                       close(spclist[0].spc_fd);
+                                       serv_shutdown();
+                                       goto out;
+                               }
+
                                idx = serv_handleconn(pfdlist[0].fd,
                                    sarg->sps_connhook, nfds == MAXCLI);
                                if (idx)
@@ -776,6 +802,7 @@
                }
        }
 
+ out:
        return NULL;
 }
 
@@ -831,3 +858,13 @@
 
        return 0;
 }
+
+void
+rumpuser_sp_fini()
+{
+
+       if (spclist[0].spc_fd) {
+               shutdown(spclist[0].spc_fd, SHUT_RDWR);
+               spfini = 1;
+       }
+}
diff -r 68cf68edb456 -r bebb8433fa8a sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h  Sun Dec 12 16:27:24 2010 +0000
+++ b/sys/rump/include/rump/rumpuser.h  Sun Dec 12 17:10:36 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.h,v 1.57 2010/12/01 17:22:51 pooka Exp $      */
+/*     $NetBSD: rumpuser.h,v 1.58 2010/12/12 17:10:36 pooka Exp $      */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -226,5 +226,6 @@
 int    rumpuser_sp_copyout(void *, const void *, void *, size_t);
 int    rumpuser_sp_copyoutstr(void *, const void *, void *, size_t *);
 int    rumpuser_sp_anonmmap(void *, size_t, void **);
+void   rumpuser_sp_fini(void);
 
 #endif /* _RUMP_RUMPUSER_H_ */



Home | Main Index | Thread Index | Old Index