Skip to content

Commit

Permalink
Merge testclient code.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Sep 14, 2018
1 parent 97252a6 commit 993b82d
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions cups/testclient.c
Expand Up @@ -11,6 +11,7 @@
* Include necessary headers...
*/

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <cups/cups.h>
Expand Down Expand Up @@ -56,6 +57,8 @@ typedef struct _client_data_s
* Local globals...
*/

static int client_count = 0;
static _cups_mutex_t client_mutex = _CUPS_MUTEX_INITIALIZER;
static int verbosity = 0;


Expand All @@ -79,18 +82,16 @@ int /* O - Exit status */
main(int argc, /* I - Number of command-line arguments */
char *argv[]) /* I - Command-line arguments */
{
int i; /* Looping var */
const char *opt; /* Current option */
int num_clients = 0,/* Number of clients to simulate */
total_clients; /* Total number of clients */
_cups_thread_t clients[MAX_CLIENTS];
/* Clients thread IDs */
char scheme[32], /* URI scheme */
userpass[256], /* Username:password */
hostname[256], /* Hostname */
resource[256]; /* Resource path */
int i; /* Looping var */
const char *opt; /* Current option */
int num_clients = 0,/* Number of clients to simulate */
clients_started = 0;
/* Number of clients that have been started */
char scheme[32], /* URI scheme */
userpass[256], /* Username:password */
hostname[256], /* Hostname */
resource[256]; /* Resource path */
_client_data_t data; /* Client data */
int status = 0; /* Exit status */


/*
Expand Down Expand Up @@ -240,28 +241,34 @@ main(int argc, /* I - Number of command-line arguments */
data.hostname = hostname;
data.resource = resource;

for (i = 0, total_clients = 0; i < num_clients; i ++)
while (clients_started < num_clients)
{
clients[i % MAX_CLIENTS] = _cupsThreadCreate((_cups_thread_func_t)run_client, &data);

total_clients ++;
if (total_clients >= MAX_CLIENTS || (i + 1) >= num_clients)
_cupsMutexLock(&client_mutex);
if (client_count < MAX_CLIENTS)
{
/*
* Wait for them to complete...
*/
_cups_thread_t tid; /* New thread */

int j;

for (j = 0; j < total_clients; j ++)
if (_cupsThreadWait(clients[j]))
status = 1;

total_clients = 0;
client_count ++;
_cupsMutexUnlock(&client_mutex);
tid = _cupsThreadCreate((_cups_thread_func_t)run_client, &data);
_cupsThreadDetach(tid);
}
else
{
_cupsMutexUnlock(&client_mutex);
sleep(1);
}
}

return (status);
while (client_count > 0)
{
_cupsMutexLock(&client_mutex);
printf("%d RUNNING CLIENTS\n", client_count);
_cupsMutexUnlock(&client_mutex);
sleep(1);
}

return (0);
}


Expand Down Expand Up @@ -937,6 +944,10 @@ run_client(

_cupsThreadWait(monitor_id);

_cupsMutexLock(&client_mutex);
client_count --;
_cupsMutexUnlock(&client_mutex);

return (NULL);
}

Expand Down

0 comments on commit 993b82d

Please sign in to comment.