Oops, commit this.
authorDan Winship <danw@src.gnome.org>
Wed, 13 Nov 2002 17:06:58 +0000 (17:06 +0000)
committerDan Winship <danw@src.gnome.org>
Wed, 13 Nov 2002 17:06:58 +0000 (17:06 +0000)
* tests/timeserver.c: Oops, commit this.

* tests/Makefile.am (noinst_PROGRAMS): reenable timeserver.

ChangeLog
tests/.cvsignore
tests/Makefile.am
tests/timeserver.c [new file with mode: 0644]

index 85b4e2e..2a7519e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-11-13  Dan Winship  <danw@ximian.com>
+
+       * tests/timeserver.c: Oops, commit this.
+
+       * tests/Makefile.am (noinst_PROGRAMS): reenable timeserver.
+
 2002-12-13  Joe Shaw  <joe@ximian.com>
 
        * libsoup/Makefile.am: Replace the BINDIR define with LIBEXECDIR.
index ee2b3d1..ec574b3 100644 (file)
@@ -1,3 +1,4 @@
 Makefile
 Makefile.in
 get
+timeserver
index 4448287..087cd71 100644 (file)
@@ -2,8 +2,7 @@ INCLUDES =              \
        -I$(top_srcdir) \
        $(GLIB_CFLAGS)
 
-#noinst_PROGRAMS = get timeserver
-noinst_PROGRAMS = get
+noinst_PROGRAMS = get timeserver
 
 get_SOURCES = get.c
 
diff --git a/tests/timeserver.c b/tests/timeserver.c
new file mode 100644 (file)
index 0000000..f8b7222
--- /dev/null
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <libsoup/soup.h>
+
+int
+main (int argc, char **argv)
+{
+       SoupSocket *listener, *client;
+       SoupAddress *addr;
+       guint port;
+       time_t now;
+       char *timebuf;
+       GIOChannel *chan;
+       int wrote;
+
+       if (argc > 2) {
+               fprintf (stderr, "Usage: %s [port]\n", argv[0]);
+               exit (1);
+       }
+
+       if (argc == 2)
+               port = atoi (argv[1]);
+       else
+               port = 0;
+       listener = soup_socket_server_new (soup_address_ipv4_any (), port);
+       if (!listener) {
+               fprintf (stderr, "Could not create listening socket\n");
+               exit (1);
+       }
+       printf ("Listening on port %d\n", soup_socket_get_port (listener));
+
+       while ((client = soup_socket_server_accept (listener))) {
+               addr = soup_socket_get_address (client);
+               printf ("got connection from %s port %d\n",
+                       soup_address_get_name_sync (addr),
+                       soup_socket_get_port (client));
+
+               now = time (NULL);
+               timebuf = ctime (&now);
+
+               chan = soup_socket_get_iochannel (client);
+               g_io_channel_write (chan, timebuf, strlen (timebuf), &wrote);
+               g_io_channel_unref (chan);
+
+               soup_socket_unref (client);
+       }
+
+       return 0;
+}