Author: jfrederic.clere(a)jboss.com
Date: 2009-03-19 06:08:11 -0400 (Thu, 19 Mar 2009)
New Revision: 2376
Modified:
trunk/mod_cluster/test/native/Advertise.c
Log:
Add thread to be more similar to httpd.
Modified: trunk/mod_cluster/test/native/Advertise.c
===================================================================
--- trunk/mod_cluster/test/native/Advertise.c 2009-03-18 13:55:18 UTC (rev 2375)
+++ trunk/mod_cluster/test/native/Advertise.c 2009-03-19 10:08:11 UTC (rev 2376)
@@ -27,17 +27,38 @@
#include "apr.h"
#include "apr_network_io.h"
#include "apr_strings.h"
+#include "apr_thread_proc.h"
+static apr_sockaddr_t *ma_mgroup_sa;
+static apr_socket_t *ma_mgroup_socket;
+
+static void * APR_THREAD_FUNC parent_thread(apr_thread_t *thd, void *data) {
+ char buf[20];
+ apr_size_t n;
+ char *s;
+ apr_status_t rv;
+ apr_pool_t *pool = data;
+
+ apr_sleep(APR_TIME_C(100000));
+ s = apr_psprintf(pool, "to %pI", ma_mgroup_sa);
+ printf("apr_socket_sendto %s\n", s);
+
+ n = apr_snprintf(buf, 20, "Advertize !!!\n");
+ rv = apr_socket_sendto(ma_mgroup_socket,
+ ma_mgroup_sa, 0, buf, &n);
+ if (rv != APR_SUCCESS) {
+ printf("apr_socket_sendto failed %d %s\n", n, apr_strerror(rv, buf,
20));
+ return;
+ }
+ return;
+}
int main(int argc, char **argv)
{
apr_pool_t *pool;
apr_status_t rv;
- apr_sockaddr_t *ma_mgroup_sa;
apr_sockaddr_t *ma_listen_sa;
apr_sockaddr_t *ma_niface_sa;
- apr_socket_t *ma_mgroup_socket;
- char buf[20];
- apr_size_t n;
+ apr_thread_t *tp;
apr_initialize();
atexit(apr_terminate);
@@ -70,6 +91,11 @@
printf("apr_socket_bind failed %d\n", rv);
return 1;
}
+ char *s;
+ s = apr_psprintf(pool, "on %pI", ma_listen_sa);
+ printf("apr_socket_bind %s\n", s);
+ s = apr_psprintf(pool, "on %pI", ma_niface_sa);
+ printf("apr_mcast_join %s\n", s);
rv = apr_mcast_join(ma_mgroup_socket, ma_mgroup_sa, ma_niface_sa, NULL);
if (rv != APR_SUCCESS) {
@@ -88,13 +114,12 @@
printf("apr_mcast_hops failed %d\n", rv);
return 1;
}
-
- n = apr_snprintf(buf, 20, "Advertize !!!\n");
- rv = apr_socket_sendto(ma_mgroup_socket,
- ma_mgroup_sa, 0, buf, &n);
- if (rv != APR_SUCCESS) {
- printf("apr_socket_sendto failed %d %s\n", n, apr_strerror(rv, buf,
20));
+ rv = apr_thread_create(&tp, NULL, parent_thread, pool, pool);
+ if (rv != APR_SUCCESS) {
+ printf("apr_thread_create failed %d\n", rv);
return 1;
}
+ apr_thread_detach(tp);
+ apr_sleep(APR_TIME_C(150000));
return 0;
}