commit: r1754 - neon/trunk/test/common

joe at manyfish.co.uk joe at manyfish.co.uk
Mon Dec 14 15:48:41 EST 2009


Author: joe
Date: Mon Dec 14 12:48:40 2009
New Revision: 1754

Modified:
   neon/trunk/test/common/child.c
   neon/trunk/test/common/child.h

Log:
* test/common/child.c, child.h (new_spawn_server): New function.


Modified: neon/trunk/test/common/child.c
==============================================================================
--- neon/trunk/test/common/child.c	(original)
+++ neon/trunk/test/common/child.c	Mon Dec 14 12:48:40 2009
@@ -1,6 +1,6 @@
 /* 
    Framework for testing with a server process
-   Copyright (C) 2001-2008, Joe Orton <joe at manyfish.co.uk>
+   Copyright (C) 2001-2009, Joe Orton <joe at manyfish.co.uk>
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -315,6 +315,53 @@
     return OK;
 }
 
+int new_spawn_server(server_fn fn, void *userdata, unsigned int *port)
+{
+    struct sockaddr_in sa;
+    socklen_t salen = sizeof sa;
+    int ls;
+    
+    ls = do_listen(lh_addr, 0);
+    ONN("could not bind/listen fd for server", ls < 0);
+
+    ONV(getsockname(ls, &sa, &salen) != 0,
+        ("could not get socket name for listening fd: %s",
+         strerror(errno)));
+    
+    *port = ntohs(sa.sin_port);
+
+    NE_DEBUG(NE_DBG_SOCKET, "child using port %u\n", *port);
+    
+    NE_DEBUG(NE_DBG_SOCKET, "child forking now...\n");
+
+    child = fork();
+    ONN("failed to fork server", child == -1);
+
+    if (child == 0) {
+        ne_socket *sock = ne_sock_create();
+        int ret;
+        
+        in_child();
+
+        if (ne_sock_accept(sock, ls)) {
+            t_context("Server child could not accept connection: %s", 
+                      ne_sock_error(sock));
+            exit(FAIL);
+        }
+
+        ret = fn(sock, userdata);
+
+        close_socket(sock);
+
+        NE_DEBUG(NE_DBG_HTTP, "child terminating with %d\n", ret);
+        exit(ret);
+    }
+
+    close(ls);
+
+    return OK;
+}
+
 int dead_server(void)
 {
     int status;

Modified: neon/trunk/test/common/child.h
==============================================================================
--- neon/trunk/test/common/child.h	(original)
+++ neon/trunk/test/common/child.h	Mon Dec 14 12:48:40 2009
@@ -1,6 +1,6 @@
 /* 
    Framework for testing with a server process
-   Copyright (C) 2001-2004, Joe Orton <joe at manyfish.co.uk>
+   Copyright (C) 2001-2004, 2009, Joe Orton <joe at manyfish.co.uk>
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -63,6 +63,11 @@
  * child process exits with a failure status. */
 int spawn_server_repeat(int port, server_fn fn, void *userdata, int n);
 
+/* Forks a server child process running 'fn(userdata)' on an
+ * unspecified port.  Sets test suite error on failure; on success,
+ * sets *port to bound port number. */
+int new_spawn_server(server_fn fn, void *userdata, unsigned int *port);
+
 /* Blocks until child process exits, and gives return code of 'fn'. */
 int await_server(void);
 



More information about the neon-commits mailing list