| 1 | #include <stdio.h> | 
|---|
| 2 | #include <stdlib.h> | 
|---|
| 3 |  | 
|---|
| 4 | #include "echo.h" | 
|---|
| 5 |  | 
|---|
| 6 | static int niters = 10000; | 
|---|
| 7 | static int nthreads = 8; | 
|---|
| 8 | static char *server_ior; | 
|---|
| 9 | static CORBA_ORB orb; | 
|---|
| 10 |  | 
|---|
| 11 | static gpointer | 
|---|
| 12 | echo_client_thread (gpointer data) | 
|---|
| 13 | { | 
|---|
| 14 | int i; | 
|---|
| 15 | Echo echo_client; | 
|---|
| 16 | CORBA_Environment *ev, real_ev; | 
|---|
| 17 |  | 
|---|
| 18 | CORBA_exception_init ((ev = &real_ev)); | 
|---|
| 19 |  | 
|---|
| 20 | echo_client = CORBA_ORB_string_to_object (orb, server_ior, ev); | 
|---|
| 21 | if (!echo_client) { | 
|---|
| 22 | g_error ("[%p]: Cannot bind to %s\n", | 
|---|
| 23 | g_thread_self (), server_ior); | 
|---|
| 24 | return NULL; | 
|---|
| 25 | } | 
|---|
| 26 |  | 
|---|
| 27 | for (i = 0; i < 4; i++) /* let others get started */ | 
|---|
| 28 | g_thread_yield (); | 
|---|
| 29 |  | 
|---|
| 30 | for (i = 0; i < niters; i++) { | 
|---|
| 31 | char *str; | 
|---|
| 32 | CORBA_double tmp; | 
|---|
| 33 | Echo retval; | 
|---|
| 34 | str = g_strdup_printf ("[%p]: Hello, world [%d]", | 
|---|
| 35 | g_thread_self (), i); | 
|---|
| 36 |  | 
|---|
| 37 | Echo_doOneWay (echo_client, str, ev); | 
|---|
| 38 |  | 
|---|
| 39 | retval = Echo_echoString (echo_client, str, &tmp, ev); | 
|---|
| 40 |  | 
|---|
| 41 | g_free (str); | 
|---|
| 42 |  | 
|---|
| 43 | if (ev->_major != CORBA_NO_EXCEPTION) { | 
|---|
| 44 | g_error ("[%p]: we got exception %s from echoString!\n", | 
|---|
| 45 | g_thread_self (), ev->_id); | 
|---|
| 46 | return NULL; | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | CORBA_Object_release (retval, ev); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | CORBA_Object_release (echo_client, ev); | 
|---|
| 53 |  | 
|---|
| 54 | return data; | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | int | 
|---|
| 58 | main (int argc, char *argv[]) | 
|---|
| 59 | { | 
|---|
| 60 | int i; | 
|---|
| 61 | GError *error = NULL; | 
|---|
| 62 | GThread **threads; | 
|---|
| 63 | CORBA_Environment *ev, real_ev; | 
|---|
| 64 |  | 
|---|
| 65 | CORBA_exception_init ((ev = &real_ev)); | 
|---|
| 66 |  | 
|---|
| 67 | orb = CORBA_ORB_init (&argc, argv, "orbit-local-mt-orb", ev); | 
|---|
| 68 |  | 
|---|
| 69 | if (argc < 2) { | 
|---|
| 70 | g_error ("Syntax: %s <server IOR> [<niters> [<nthreads>] ]\n", | 
|---|
| 71 | argv [0]); | 
|---|
| 72 | return 1; | 
|---|
| 73 | } | 
|---|
| 74 | server_ior = argv [1]; | 
|---|
| 75 |  | 
|---|
| 76 | if (argc >= 3) | 
|---|
| 77 | niters = atoi (argv [2]); | 
|---|
| 78 |  | 
|---|
| 79 | if (argc >= 4) | 
|---|
| 80 | nthreads = atoi (argv [3]); | 
|---|
| 81 |  | 
|---|
| 82 | threads = g_new0 (GThread *, nthreads); | 
|---|
| 83 |  | 
|---|
| 84 | for (i = 0; i < nthreads; i++) { | 
|---|
| 85 | threads [i] = g_thread_create ( | 
|---|
| 86 | echo_client_thread, &threads[i], | 
|---|
| 87 | TRUE, &error); | 
|---|
| 88 | if (error) | 
|---|
| 89 | g_error ("Error spawning threads '%s'", | 
|---|
| 90 | error->message); | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | for (i = 0; i < nthreads; i++) { | 
|---|
| 94 | if (!(g_thread_join (threads [i]) == &threads [i])) | 
|---|
| 95 | g_error ("Wierd thread join problem '%d'", i); | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | CORBA_ORB_destroy (orb, ev); | 
|---|
| 99 | CORBA_Object_release ((CORBA_Object) orb, ev); | 
|---|
| 100 |  | 
|---|
| 101 | return 0; | 
|---|
| 102 | } | 
|---|