[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3043 - GNUnet/src/util/network
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3043 - GNUnet/src/util/network |
Date: |
Sat, 24 Jun 2006 18:28:23 -0700 (PDT) |
Author: grothoff
Date: 2006-06-24 18:28:21 -0700 (Sat, 24 Jun 2006)
New Revision: 3043
Added:
GNUnet/src/util/network/daemon.c
Log:
forgotten
Added: GNUnet/src/util/network/daemon.c
===================================================================
--- GNUnet/src/util/network/daemon.c 2006-06-25 00:37:02 UTC (rev 3042)
+++ GNUnet/src/util/network/daemon.c 2006-06-25 01:28:21 UTC (rev 3043)
@@ -0,0 +1,103 @@
+/*
+ This file is part of GNUnet.
+ (C) 2005 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/util/network/daemon.c
+ * @brief code for client-gnunetd interaction (stop, check running)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util_network.h"
+#include "gnunet_protocols.h"
+#include "gnunet_util_threads.h"
+
+int connection_test_running(struct GE_Context * ectx,
+ struct GC_Configuration * cfg) {
+ struct ClientServerConnection * sock;
+ MESSAGE_HEADER csHdr;
+ int ret;
+
+ sock = daemon_connection_create(ectx, cfg);
+ if (sock == NULL)
+ return SYSERR;
+ csHdr.size
+ = htons(sizeof(MESSAGE_HEADER));
+ csHdr.type
+ = htons(CS_PROTO_traffic_COUNT);
+ if (SYSERR == connection_write(sock,
+ &csHdr,
+ YES)) {
+ connection_destroy(sock);
+ return SYSERR;
+ }
+ if (SYSERR == connection_read_result(sock,
+ &ret)) {
+ connection_destroy(sock);
+ return SYSERR;
+ }
+ connection_destroy(sock);
+ return OK;
+}
+
+int connection_request_shutdown(struct ClientServerConnection * sock) {
+ MESSAGE_HEADER csHdr;
+ int ret;
+
+ csHdr.size
+ = htons(sizeof(MESSAGE_HEADER));
+ csHdr.type
+ = htons(CS_PROTO_SHUTDOWN_REQUEST);
+ if (SYSERR == connection_write(sock,
+ &csHdr,
+ YES)) {
+ connection_close_temporarily(sock);
+ return SYSERR;
+ }
+ if (SYSERR == connection_read_result(sock,
+ &ret)) {
+ connection_close_temporarily(sock);
+ return SYSERR;
+ }
+ return ret;
+}
+
+/**
+ * Wait until the gnunet daemon is
+ * running.
+ *
+ * @param timeout how long to wait at most
+ * @return OK if gnunetd is now running
+ */
+int connection_wait_for_running(struct GE_Context * ectx,
+ struct GC_Configuration * cfg,
+ cron_t timeout) {
+ timeout += get_time();
+ while (OK != connection_test_running(ectx,
+ cfg)) {
+ PTHREAD_SLEEP(100 * cronMILLIS);
+ if (timeout < get_time())
+ return connection_test_running(ectx,
+ cfg);
+ }
+ return OK;
+}
+
+/* end of daemon.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3043 - GNUnet/src/util/network,
grothoff <=