Revision: 14341
Author: adrian.chadd
Date: Tue Oct 20 01:35:24 2009
Log: Implement a close command; use it when shutting down the writelog


http://code.google.com/p/lusca-cache/source/detail?r=14341

Modified:
  /branches/LUSCA_HEAD/libloghelper/loghelper.c
  /branches/LUSCA_HEAD/libloghelper/loghelper_commands.h
  /branches/LUSCA_HEAD/libloghelper/writelog-daemon.c

=======================================
--- /branches/LUSCA_HEAD/libloghelper/loghelper.c       Mon Oct 19 21:56:41 2009
+++ /branches/LUSCA_HEAD/libloghelper/loghelper.c       Tue Oct 20 01:35:24 2009
@@ -210,34 +210,6 @@
        }
        return lh;
  }
-
-/*
- * Close down a loghelper instance.
- *
- * This queues a close and quit message, then marks the loghelper  
as "going away."
- *
- * The loghelper is not freed here - it will wait for some response (or  
error) from
- * the loghelper process before finalising the current state.
- *
- * Any pending messages will be flushed and sent out before the close is  
queued.
- *
- * The "lh" pointer should be viewed as invalid after this call.
- */
-void
-loghelper_close(loghelper_instance_t *lh)
-{
-       /* Mark the connection as closing */
-       lh->flags.closing = 1;
-
-       /* Are there pending messages? If so, leave it for now and queue a 
write  
if needed */
-       if (loghelper_has_bufs(lh)) {
-               loghelper_kick_write(lh);
-               return;
-       }
-
-       /* No pending messages? Wrap up. */
-       loghelper_destroy(lh);
-}

  /*
   * Queue a command to be sent to the loghelper.
@@ -284,3 +256,29 @@

        return 1;
  }
+
+/*
+ * Close down a loghelper instance.
+ *
+ * This queues a close and quit message, then marks the loghelper  
as "going away."
+ *
+ * The loghelper is not freed here - it will wait for some response (or  
error) from
+ * the loghelper process before finalising the current state.
+ *
+ * Any pending messages will be flushed and sent out before the close is  
queued.
+ *
+ * The "lh" pointer should be viewed as invalid after this call.
+ */
+void
+loghelper_close(loghelper_instance_t *lh)
+{
+       /* Mark the connection as closing */
+       lh->flags.closing = 1;
+
+       /* Queue close message */
+       (void) loghelper_queue_command(lh, LH_CMD_CLOSE, 4, NULL);
+
+       /* queue a write */
+       loghelper_kick_write(lh);
+}
+
=======================================
--- /branches/LUSCA_HEAD/libloghelper/loghelper_commands.h      Mon Oct 19  
22:06:39 2009
+++ /branches/LUSCA_HEAD/libloghelper/loghelper_commands.h      Tue Oct 20  
01:35:24 2009
@@ -11,6 +11,7 @@
        LH_CMD_WRITE,
        LH_CMD_ENABLE_BUFFERING,
        LH_CMD_DISABLE_BUFFERING,
+       LH_CMD_CLOSE,
        LH_CMD_LAST
  } loghelper_command_t;

=======================================
--- /branches/LUSCA_HEAD/libloghelper/writelog-daemon.c Mon Oct 19 22:11:48  
2009
+++ /branches/LUSCA_HEAD/libloghelper/writelog-daemon.c Tue Oct 20 01:35:24  
2009
@@ -171,6 +171,11 @@
                        inbuf_consume(len);
                        ret = 1;
                        break;
+               case LH_CMD_CLOSE:
+                       logfile_close();
+                       inbuf_consume(len);
+                       ret = 0;                        /* EOF! */
+                       break;
                default:
                        fprintf(stderr, "read invalid command: %d: 
skipping!\n", cmd);
                        inbuf_consume(len);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to