Alvaro,

Per your request at

<http://article.gmane.org/gmane.comp.web.cherokee.general/972/>

I am including a patch to revision 781 that will allow the Cherokee to
properly terminate when the cherokeeserv service wrapper is stopped. The
patch is also available here:

<http://www.smithii.com/files/cherokee-781-cherokeeserv-0.2.patch>

Per Brian Rosner's comments, I cleaned up and reformatted cherokeeserv
to match Cherokee's style. The update is available here:

<http://www.smithii.com/files/cherokeeserv-0.2.zip>

I would love to get these changes into Subversion. Let me know if
there is anything I can do to assist in this process.

Feedback is appreciated,

Ross


diff -uwrN cherokee.orig/cherokee/macros.h cherokee/cherokee/macros.h
--- cherokee.orig/cherokee/macros.h     2007-06-13 16:03:21.374740000 -0700
+++ cherokee/cherokee/macros.h  2007-06-28 10:05:03.616000000 -0700
@@ -359,4 +359,10 @@
 # define SLASH '/'
 #endif
 
+#ifdef _WIN32
+# define SHUTDOWN_SIGNALED() cherokee_win32_shutdown_signaled()
+#else
+# define SHUTDOWN_SIGNALED() (0)
+#endif
+
 #endif /* CHEROKEE_MACROS_H */
diff -uwrN cherokee.orig/cherokee/server.c cherokee/cherokee/server.c
--- cherokee.orig/cherokee/server.c     2007-06-26 03:16:32.834700000 -0700
+++ cherokee/cherokee/server.c  2007-06-28 10:05:03.897250000 -0700
@@ -1295,6 +1295,10 @@
        if (unlikely (srv->wanna_exit)) 
                return ret_ok;
        
+       if (SHUTDOWN_SIGNALED()) {
+               return ret_ok;
+       }
+
        return ret_eagain;
 }
 
diff -uwrN cherokee.orig/cherokee/thread.c cherokee/cherokee/thread.c
--- cherokee.orig/cherokee/thread.c     2007-06-21 18:53:23.796368000 -0700
+++ cherokee/cherokee/thread.c  2007-06-28 10:06:23.069125000 -0700
@@ -583,6 +583,11 @@
        cherokee_connection_t *conn;
 
        list_for_each_safe (i, tmp, LIST(&thd->polling_list)) {
+               if (SHUTDOWN_SIGNALED()) {
+                       thd->exit = true;
+                       return ret_ok;
+               }
+
                conn = CONN(i);
 
                /* Has it been too much without any work?
@@ -646,6 +652,11 @@
        /* Process active connections
         */
        list_for_each_safe (i, tmp, LIST(&thd->active_list)) {
+               if (SHUTDOWN_SIGNALED()) {
+                       thd->exit = true;
+                       return ret_ok;
+               }
+
                conn = CONN(i);
 
                TRACE (ENTRIES, "thread (%p) processing conn (%p), phase %d\n", 
thd, conn, conn->phase);
@@ -1404,6 +1415,11 @@
        cherokee_sockaddr_t    new_sa;
        cherokee_connection_t *new_conn;
 
+       if (SHUTDOWN_SIGNALED()) {
+               thd->exit = true;
+               return 0;
+       }
+
        /* Return if there're too many or no new connections
         */
        if (thd->conns_num >= thd->conns_max)
diff -uwrN cherokee.781/cherokee/win32_misc.c cherokee/cherokee/win32_misc.c
--- cherokee.781/cherokee/win32_misc.c  2007-06-27 13:15:36.934576000 -0700
+++ cherokee/cherokee/win32_misc.c      2007-06-28 10:37:25.225375000 -0700
@@ -5,6 +5,7 @@
  * Authors:
  *      Alvaro Lopez Ortega <[EMAIL PROTECTED]>
  *      Gisle Vanem <[EMAIL PROTECTED]>
+ *      Ross Smith II <cherokee at smithii.com>
  *
  * Copyright (C) 2001-2007 Alvaro Lopez Ortega
  *
@@ -53,6 +54,22 @@
 # define _ctor
 #endif
 
+#define EXIT_EVENT_NAME "cherokee_exit_1"
+
+/* clear an object */
+#define CLEAR(x) memset(&(x), 0, sizeof(x))
+
+struct security_attributes
+{
+  SECURITY_ATTRIBUTES sa;
+  SECURITY_DESCRIPTOR sd;
+};
+
+/* bool definitions */
+#define bool int
+#define true 1
+#define false 0
+
 static int     win_trace = 0;
 static SOCKET  first_sock_num;
 static WSADATA wsa_data;
@@ -1017,3 +1034,45 @@
        return re;
 }
 
+static bool
+init_security_attributes_allow_all (struct security_attributes *obj)
+{
+       CLEAR (*obj);
+
+       obj->sa.nLength = sizeof (SECURITY_ATTRIBUTES);
+       obj->sa.lpSecurityDescriptor = &obj->sd;
+       obj->sa.bInheritHandle = TRUE;
+       if (!InitializeSecurityDescriptor (&obj->sd, 
SECURITY_DESCRIPTOR_REVISION))
+               return false;
+       if (!SetSecurityDescriptorDacl (&obj->sd, TRUE, NULL, FALSE))
+               return false;
+       return true;
+}
+
+static HANDLE
+create_event (const char *name, bool allow_all, bool initial_state, bool 
manual_reset)
+{
+       if (allow_all)
+       {
+               struct security_attributes sa;
+               if (!init_security_attributes_allow_all (&sa))
+                       return NULL;
+               return CreateEvent (&sa.sa, (BOOL)manual_reset, 
(BOOL)initial_state, name);
+       }
+       else
+               return CreateEvent (NULL, (BOOL)manual_reset, 
(BOOL)initial_state, name);
+}
+
+int
+cherokee_win32_shutdown_signaled()
+{
+       static HANDLE exit_event = NULL;
+
+       if (!exit_event) {
+               exit_event = create_event (EXIT_EVENT_NAME, true, false, false);
+               if (!exit_event)
+                 return 1;
+       }
+
+       return WaitForSingleObject (exit_event, (DWORD) 0) == WAIT_OBJECT_0;
+}
diff -uwrN cherokee.orig/cherokee/win32_misc.h cherokee/cherokee/win32_misc.h
--- cherokee.orig/cherokee/win32_misc.h 2007-01-10 07:28:59.819955000 -0800
+++ cherokee/cherokee/win32_misc.h      2007-06-28 10:05:04.037875000 -0700
@@ -4,6 +4,7 @@
  *
  * Authors:
  *      Alvaro Lopez Ortega <[EMAIL PROTECTED]>
+ *      Ross Smith II <cherokee at smithii.com>
  *
  * Copyright (C) 2001-2007 Alvaro Lopez Ortega
  *
@@ -41,5 +42,6 @@
 unsigned int  sleep               (unsigned int seconds);
 
 int           cherokee_win32_stat (const char *path, struct stat *buf);
+int           cherokee_win32_shutdown_signaled();
 
 #endif /* CHEROKEE_WIN32_MISC_H */
_______________________________________________
Cherokee mailing list
[email protected]
http://cherokee-project.com/cgi-bin/mailman/listinfo/cherokee

Reply via email to