#include <stdlib.h>
#include <stdbool.h>
#include <pthread.h>
#include <unistd.h>
#include <time.h>
#include <ctype.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
#define MAX_THREADS 2
#define MAX_ITER 8
#define MAX_TRIES 1000
#define MIN_SLEEP 1
typedef struct
{
pthread_t thread_id;
int inst_num;
int num_iter;
int sleep_time;
} thread_info_t;
static void * check_connect_task(void *arg)
{
thread_info_t *ti = (thread_info_t *)arg;
char *result = "INCOMPLETE";
int ok_count;
int err_count;
int last_error_rc;
char task_name[64];
int i, j;
int rc;
do
{
if (ti == NULL)
{
printf("\n%s: Input argument is NULL. Exiting.\n", __FUNCTION__);
break;
}
snprintf(task_name, sizeof(task_name), "check-connect-%d", ti->inst_num);
printf ("[%s] Running Check Connect task instance %d (%d iterations, %d second sleep interval)...\n",
task_name, ti->inst_num, ti->num_iter, ti->sleep_time);
{
printf("[%s] Failed to initialize OpEN RPC connection. Exiting (result = %d)\n", task_name, rc);
break;
}
for (i = 0; i < ti->num_iter; i++)
{
ok_count = err_count = last_error_rc = 0;
if (i > 0)
{
sleep(ti->sleep_time);
}
for (j = 0; j < MAX_TRIES; j++)
{
{
ok_count++;
}
else
{
last_error_rc = rc;
err_count++;
}
}
printf ("[%s] OpEN API test iteration %2d -- Attempts=%d: OK=%d Error=%d (Last Error RC = %d)\n",
task_name, i + 1, j, ok_count, err_count, last_error_rc);
}
{
printf("[%s] Failed to cleanup OpEN RPC connection. Exiting (result = %d)\n", task_name, rc);
break;
}
result = "COMPLETE";
} while (0);
sleep(1);
return strdup(result);
}
int main(int argc, char **argv)
{
char switch_os_revision_string[100];
pthread_attr_t attr;
thread_info_t thread_info[MAX_THREADS];
thread_info_t *ti;
int i;
void *res;
memset(thread_info, 0, sizeof(thread_info));
l7proc_crashlog_register();
{
printf("\nFailed to initialize RPC to OpEN. Exiting result = %d\n", result);
return 1;
}
{
sleep(1);
}
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0, "Starting Multi-Threaded App example application");
printf("\n");
switch_os_revision.
pstart = switch_os_revision_string;
switch_os_revision.
size =
sizeof(switch_os_revision_string);
{
printf("Network OS version = %s\n", switch_os_revision_string);
}
else
{
printf("Network OS version retrieve error\n");
}
printf("Starting %d process threads...\n", (int)MAX_THREADS);
pthread_attr_init(&attr);
for (i = 0, ti = &thread_info[i]; i < MAX_THREADS; i++, ti++)
{
ti->inst_num = i + 1;
ti->num_iter = MAX_ITER;
ti->sleep_time = MIN_SLEEP + (i * 2);
pthread_create(&ti->thread_id, &attr, check_connect_task, ti);
}
pthread_attr_destroy(&attr);
for (i = 0, ti = &thread_info[i]; i < MAX_THREADS; i++, ti++)
{
pthread_join(ti->thread_id, &res);
printf("Thread instance %d exited.", ti->inst_num);
if (res != NULL)
{
printf(" Status: %s", (char *)res);
free(res);
}
printf("\n");
}
printf("All process threads have completed. Exiting application.\n\n");
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping Multi-Threaded App example application");
return 0;
}