[ostree/wip/pull: 2/5] ostree-http-server: Exit when our directory goes away
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/pull: 2/5] ostree-http-server: Exit when our directory goes away
- Date: Sun, 30 Oct 2011 00:14:58 +0000 (UTC)
commit 79cff61ae8bc3451f840472c144992a5de6bd0c6
Author: Colin Walters <walters verbum org>
Date: Fri Oct 28 16:56:50 2011 -0400
ostree-http-server: Exit when our directory goes away
tests/ostree-http-server.c | 28 ++++++++++++++++++++++++++--
1 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/tests/ostree-http-server.c b/tests/ostree-http-server.c
index 097f1b0..63edda5 100644
--- a/tests/ostree-http-server.c
+++ b/tests/ostree-http-server.c
@@ -22,6 +22,7 @@
#include <libsoup/soup-gnome.h>
#include <sys/types.h>
#include <unistd.h>
+#include <stdlib.h>
static void
request_callback (SoupServer *server, SoupMessage *msg,
@@ -48,6 +49,19 @@ request_callback (SoupServer *server, SoupMessage *msg,
}
}
+static void
+on_dir_changed (GFileMonitor *mon,
+ GFile *file,
+ GFile *other,
+ GFileMonitorEvent event,
+ gpointer user_data)
+{
+ GMainLoop *loop = user_data;
+
+ if (event == G_FILE_MONITOR_EVENT_DELETED)
+ g_main_loop_quit (loop);
+}
+
int
main (int argc,
char **argv)
@@ -55,11 +69,21 @@ main (int argc,
SoupAddress *addr;
SoupServer *server;
GMainLoop *loop;
+ GFileMonitor *monitor;
+ GFile *curdir;
+ GError *error = NULL;
g_type_init ();
loop = g_main_loop_new (NULL, TRUE);
-
+
+ curdir = g_file_new_for_path (".");
+ monitor = g_file_monitor_directory (curdir, 0, NULL, &error);
+ if (!monitor)
+ exit (1);
+ g_signal_connect (monitor, "changed",
+ G_CALLBACK (on_dir_changed), loop);
+
addr = soup_address_new ("127.0.0.1", SOUP_ADDRESS_ANY_PORT);
soup_address_resolve_sync (addr, NULL);
@@ -72,7 +96,7 @@ main (int argc,
soup_server_run_async (server);
- g_print ("%ld %ld\n", (long)getpid(), (long)soup_server_get_port (server));
+ g_print ("http://127.0.0.1:%ld\n", (long)soup_server_get_port (server));
g_main_loop_run (loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]