mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 18:26:19 +01:00
gio: Add a count to the resolver test for number of enumerators
This adds the nice stress-test feature of having 5 enumerators running at the same time. Yay!
This commit is contained in:
parent
bd227f5219
commit
ca38bddd6e
@ -41,11 +41,12 @@ static void G_GNUC_NORETURN
|
|||||||
usage (void)
|
usage (void)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Usage: resolver [-t] [-s] [hostname | IP | service/protocol/domain ] ...\n");
|
fprintf (stderr, "Usage: resolver [-t] [-s] [hostname | IP | service/protocol/domain ] ...\n");
|
||||||
fprintf (stderr, " resolver [-t] [-s] -c [hostname | IP | service/protocol/domain ]\n");
|
fprintf (stderr, " resolver [-t] [-s] -c NUMBER [hostname | IP | service/protocol/domain ]\n");
|
||||||
fprintf (stderr, " Use -t to enable threading.\n");
|
fprintf (stderr, " Use -t to enable threading.\n");
|
||||||
fprintf (stderr, " Use -s to do synchronous lookups.\n");
|
fprintf (stderr, " Use -s to do synchronous lookups.\n");
|
||||||
fprintf (stderr, " Both together will result in simultaneous lookups in multiple threads\n");
|
fprintf (stderr, " Both together will result in simultaneous lookups in multiple threads\n");
|
||||||
fprintf (stderr, " Use -c (and only a single resolvable argument) to test GSocketConnectable.\n");
|
fprintf (stderr, " Use -c NUMBER(and only a single resolvable argument) to test GSocketConnectable.\n");
|
||||||
|
fprintf (stderr, " The given NUMBER determines how often the connectable will be enumerated.\n");
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +361,7 @@ do_async_connectable (GSocketAddressEnumerator *enumerator)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_connectable (const char *arg, gboolean synchronous)
|
do_connectable (const char *arg, gboolean synchronous, guint count)
|
||||||
{
|
{
|
||||||
char **parts;
|
char **parts;
|
||||||
GSocketConnectable *connectable;
|
GSocketConnectable *connectable;
|
||||||
@ -400,13 +401,17 @@ do_connectable (const char *arg, gboolean synchronous)
|
|||||||
connectable = g_network_address_new (arg, port);
|
connectable = g_network_address_new (arg, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
enumerator = g_socket_connectable_enumerate (connectable);
|
while (count--)
|
||||||
g_object_unref (connectable);
|
{
|
||||||
|
enumerator = g_socket_connectable_enumerate (connectable);
|
||||||
|
|
||||||
if (synchronous)
|
if (synchronous)
|
||||||
do_sync_connectable (enumerator);
|
do_sync_connectable (enumerator);
|
||||||
else
|
else
|
||||||
do_async_connectable (enumerator);
|
do_async_connectable (enumerator);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (connectable);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
@ -434,7 +439,7 @@ int
|
|||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
gboolean threaded = FALSE, synchronous = FALSE;
|
gboolean threaded = FALSE, synchronous = FALSE;
|
||||||
gboolean use_connectable = FALSE;
|
guint connectable_count = 0;
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
GIOChannel *chan;
|
GIOChannel *chan;
|
||||||
guint watch;
|
guint watch;
|
||||||
@ -453,7 +458,11 @@ main (int argc, char **argv)
|
|||||||
else if (!strcmp (argv[1], "-s"))
|
else if (!strcmp (argv[1], "-s"))
|
||||||
synchronous = TRUE;
|
synchronous = TRUE;
|
||||||
else if (!strcmp (argv[1], "-c"))
|
else if (!strcmp (argv[1], "-c"))
|
||||||
use_connectable = TRUE;
|
{
|
||||||
|
connectable_count = atoi (argv[2]);
|
||||||
|
argv++;
|
||||||
|
argc--;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
usage ();
|
usage ();
|
||||||
|
|
||||||
@ -462,7 +471,7 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
if (argc < 2 || (argc > 2 && use_connectable))
|
if (argc < 2 || (argc > 2 && connectable_count))
|
||||||
usage ();
|
usage ();
|
||||||
|
|
||||||
resolver = g_resolver_get_default ();
|
resolver = g_resolver_get_default ();
|
||||||
@ -488,8 +497,11 @@ main (int argc, char **argv)
|
|||||||
nlookups = argc - 1;
|
nlookups = argc - 1;
|
||||||
loop = g_main_loop_new (NULL, TRUE);
|
loop = g_main_loop_new (NULL, TRUE);
|
||||||
|
|
||||||
if (use_connectable)
|
if (connectable_count)
|
||||||
do_connectable (argv[1], synchronous);
|
{
|
||||||
|
nlookups = connectable_count;
|
||||||
|
do_connectable (argv[1], synchronous, connectable_count);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (threaded && synchronous)
|
if (threaded && synchronous)
|
||||||
|
Loading…
Reference in New Issue
Block a user