本文整理汇总了C++中create_worker函数的典型用法代码示例。如果您正苦于以下问题:C++ create_worker函数的具体用法?C++ create_worker怎么用?C++ create_worker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_worker函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_fingerprint
static void test_fingerprint(void *z)
{
struct Worker *server = NULL, *client = NULL;
tt_assert(tls_init() == 0);
/* both server & client with cert */
str_check(create_worker(&server, true, SERVER1, CA2,
"verify-client=1",
"peer-sha1=ssl/ca2_client2.crt.sha1",
"peer-sha256=ssl/ca2_client2.crt.sha256",
NULL), "OK");
str_check(create_worker(&client, false, CLIENT2, CA1,
"host=server1.com",
"peer-sha1=ssl/ca1_server1.crt.sha1",
"peer-sha256=ssl/ca1_server1.crt.sha256",
NULL), "OK");
str_check(run_case(client, server), "OK");
/* client without cert */
str_check(create_worker(&server, true, SERVER1, CA1,
"verify-client=1",
"peer-sha1=ssl/ca2_client2.crt.sha1",
"peer-sha256=ssl/ca2_client2.crt.sha256",
NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
str_any2(run_case(client, server),
"C:sslv3 alert handshake failure - S:peer did not return a certificate",
"C:sslv3 alert handshake failure,C:shutdown while in init - S:peer did not return a certificate");
end:;
}
示例2: test_verify
static void test_verify(void *z)
{
struct Worker *server = NULL, *client = NULL;
tt_assert(tls_init() == 0);
/* default: client checks server cert, succeeds */
str_check(create_worker(&server, true, SERVER1, NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "OK");
/* default: client checks server cert, fails due to bad ca */
str_check(create_worker(&server, true, SERVER1, NULL), "OK");
str_check(create_worker(&client, false, CA2, "host=example.com", NULL), "OK");
str_check(run_case(client, server), "C:certificate verify failed - S:tlsv1 alert unknown ca");
/* default: client checks server cert, fails due to bad hostname */
str_check(create_worker(&server, true, SERVER1, NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=example2.com", NULL), "OK");
str_check(run_case(client, server), "C:name `example2.com' not present in server certificate");
#if 0
/* client: aggressive close */
str_check(create_worker(&server, true, SERVER1, NULL), "OK");
str_check(create_worker(&client, false, CA1, "aggressive-close=1", "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "S:bad pkt: res=-1 err=read failed: EOF,S:close error: res=-1 err=shutdown failed: Broken pipe");
/* server: aggressive close */
str_check(create_worker(&server, true, SERVER1, "aggressive-close=1", NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "C:write failed: Broken pipe,C:close error: res=-1 err=shutdown failed: Success");
#endif
end:;
}
示例3: test_fingerprint
static void test_fingerprint(void *z)
{
struct Worker *server = NULL, *client = NULL;
tt_assert(tls_init() == 0);
/* both server & client with cert */
str_check(create_worker(&server, true, SERVER1, CA2,
"peer-sha1=ssl/ca2_client2.crt.sha1",
"peer-sha256=ssl/ca2_client2.crt.sha256",
NULL), "OK");
str_check(create_worker(&client, false, CLIENT2, CA1,
"host=server1.com",
"peer-sha1=ssl/ca1_server1.crt.sha1",
"peer-sha256=ssl/ca1_server1.crt.sha256",
NULL), "OK");
str_check(run_case(client, server), "OK");
/* client without cert */
str_check(create_worker(&server, true, SERVER1, CA1,
"peer-sha1=ssl/ca2_client2.crt.sha1",
"peer-sha256=ssl/ca2_client2.crt.sha256",
NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "C:write!=3 - S:FP-sha1-fail");
end:;
}
示例4: test_set_mem
static void test_set_mem(void *z)
{
struct Worker *server = NULL, *client = NULL;
tt_assert(tls_init() == 0);
/* both server & client with cert */
str_check(create_worker(&server, true, "mem=1", SERVER1, CA2, NULL), "OK");
str_check(create_worker(&client, false, "mem=1", CLIENT2, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "OK");
end:;
}
示例5: group
/* One group of senders and receivers */
static unsigned int group(pthread_t *pth,
unsigned int num_fds,
int ready_out,
int wakefd)
{
unsigned int i;
struct sender_context *snd_ctx = malloc(sizeof(struct sender_context)
+ num_fds * sizeof(int));
if (!snd_ctx)
barf("malloc()");
for (i = 0; i < num_fds; i++) {
int fds[2];
struct receiver_context *ctx = malloc(sizeof(*ctx));
if (!ctx)
barf("malloc()");
/* Create the pipe between client and server */
fdpair(fds);
ctx->num_packets = num_fds * loops;
ctx->in_fds[0] = fds[0];
ctx->in_fds[1] = fds[1];
ctx->ready_out = ready_out;
ctx->wakefd = wakefd;
pth[i] = create_worker(ctx, (void *)receiver);
snd_ctx->out_fds[i] = fds[1];
if (!thread_mode)
close(fds[0]);
}
/* Now we have all the fds, fork the senders */
for (i = 0; i < num_fds; i++) {
snd_ctx->ready_out = ready_out;
snd_ctx->wakefd = wakefd;
snd_ctx->num_fds = num_fds;
pth[num_fds+i] = create_worker(snd_ctx, (void *)sender);
}
/* Close the fds we have left */
if (!thread_mode)
for (i = 0; i < num_fds; i++)
close(snd_ctx->out_fds[i]);
/* Return number of children to reap */
return num_fds * 2;
}
示例6: test_clientcert
static void test_clientcert(void *z)
{
struct Worker *server = NULL, *client = NULL;
tt_assert(tls_init() == 0);
/* ok: server checks server cert */
str_check(create_worker(&server, true, SERVER1, CA2, NULL), "OK");
str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "OK");
/* fail: server rejects invalid cert */
str_check(create_worker(&server, true, SERVER1, CA1, NULL), "OK");
str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "C:tlsv1 alert unknown ca - S:handshake failure");
/* noverifycert: server allow invalid cert */
str_check(create_worker(&server, true, SERVER1, CA1, "noverifycert=1", NULL), "OK");
str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "OK");
/* allow client without cert */
str_check(create_worker(&server, true, SERVER1, CA2, NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "OK");
end:;
}
示例7: thread_init
void thread_init(int t_num, struct event_base *main_base)
{
dispatch_thread.base = main_base;
dispatch_thread.thread_id = pthread_self();
int i;
threads = calloc(t_num, sizeof(wk_thread));
if (!threads) {
perror("Can't alloc so many thread\n");
exit(1);
}
for (i = 0; i < t_num; i++) {
int fds[2];
if (pipe(fds)) {
perror("can't pipe\n");
exit(1);
}
threads[i].notify_receive_fd = fds[0];
threads[i].notify_send_fd = fds[1];
setup_thread(&threads[i]);
}
for (i = 0; i < t_num; i++) {
create_worker(worker_libevent, &threads[i]);
}
}
示例8: thread_init
static void thread_init(global_conf_st * g_conf)
{
int i;
pthread_mutex_init(&init_lock,NULL);
pthread_cond_init(&init_cond,NULL);
int nthreads = g_conf->max_thread;
threads = calloc(nthreads,sizeof(work_thread));
if(!threads){
fprintf(stderr,"%s:%d :Cant allocate threads info",__FILE__,__LINE__);
exit(-1);
}
for(i = 0 ;i < nthreads;i++){
threads[i].g_conf = g_conf;
threads[i].msg_queue = g_async_queue_new();
}
for(i = 0 ;i < nthreads;i++){
create_worker(worker_thread,&threads[i]);
}
pthread_mutex_lock(&init_lock);
while(init_count < nthreads){
pthread_cond_wait(&init_cond,&init_lock);
}
pthread_mutex_unlock(&init_lock);
}
示例9: thr_pool_queue
int
thr_pool_queue(thr_pool_t *pool, void *(*func)(void *), void *arg)
{
job_t *job;
if ((job = malloc(sizeof (*job))) == NULL) {
errno = ENOMEM;
return (-1);
}
job->job_next = NULL;
job->job_func = func;
job->job_arg = arg;
(void) pthread_mutex_lock(&pool->pool_mutex);
if (pool->pool_head == NULL)
pool->pool_head = job;
else
pool->pool_tail->job_next = job;
pool->pool_tail = job;
if (pool->pool_idle > 0)
(void) pthread_cond_signal(&pool->pool_workcv);
else if (pool->pool_nthreads < pool->pool_maximum &&
create_worker(pool) == 0)
pool->pool_nthreads++;
(void) pthread_mutex_unlock(&pool->pool_mutex);
return (0);
}
示例10: tpool_dispatch
/*
* Dispatch a work request to the thread pool.
* If there are idle workers, awaken one.
* Else, if the maximum number of workers has
* not been reached, spawn a new worker thread.
* Else just return with the job added to the queue.
*/
int
tpool_dispatch(tpool_t *tpool, void (*func)(void *), void *arg)
{
tpool_job_t *job;
if ((job = malloc(sizeof (*job))) == NULL)
return (-1);
bzero(job, sizeof(*job));
job->tpj_next = NULL;
job->tpj_func = func;
job->tpj_arg = arg;
pthread_mutex_lock(&tpool->tp_mutex);
if (tpool->tp_head == NULL)
tpool->tp_head = job;
else
tpool->tp_tail->tpj_next = job;
tpool->tp_tail = job;
tpool->tp_njobs++;
if (!(tpool->tp_flags & TP_SUSPEND)) {
if (tpool->tp_idle > 0)
(void) pthread_cond_signal(&tpool->tp_workcv);
else if (tpool->tp_current < tpool->tp_maximum &&
create_worker(tpool) == 0)
tpool->tp_current++;
}
pthread_mutex_unlock(&tpool->tp_mutex);
return (0);
}
示例11: test_clientcert
static void test_clientcert(void *z)
{
struct Worker *server = NULL, *client = NULL;
tt_assert(tls_init() == 0);
/* ok: server checks client cert */
str_check(create_worker(&server, true, SERVER1, CA2,
"verify-client=1",
NULL), "OK");
str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "OK");
/* fail: server rejects invalid cert */
str_check(create_worker(&server, true, SERVER1, CA1,
"verify-client=1",
NULL), "OK");
str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
str_any3(run_case(client, server),
"C:tlsv1 alert unknown ca - S:no certificate returned",
"C:tlsv1 alert unknown ca,C:shutdown while in init - S:certificate verify failed",
"C:tlsv1 alert unknown ca - S:certificate verify failed");
/* noverifycert: server allow invalid cert */
str_check(create_worker(&server, true, SERVER1, CA1,
"noverifycert=1",
NULL), "OK");
str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "OK");
/* verify-client: don't allow client without cert */
str_check(create_worker(&server, true, SERVER1, CA2,
"verify-client=1",
NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
str_any2(run_case(client, server),
"C:sslv3 alert handshake failure - S:peer did not return a certificate",
"C:sslv3 alert handshake failure,C:shutdown while in init - S:peer did not return a certificate");
/* verify-client-optional: allow client without cert */
str_check(create_worker(&server, true, SERVER1, CA2,
"verify-client-optional=1",
NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
str_check(run_case(client, server), "OK");
end:;
}
示例12: create_modules
void create_modules() {
ok(create_client( mod_gm_opt->server_list, &client ) == GM_OK, "created test client");
ok(create_worker( mod_gm_opt->server_list, &worker ) == GM_OK, "created test worker");
ok(worker_add_function( &worker, GM_DEFAULT_RESULT_QUEUE, get_results ) == GM_OK, "added result worker");
ok(worker_add_function( &worker, "dummy", dummy ) == GM_OK, "added dummy worker");
//gearman_worker_add_options(&worker, GEARMAN_WORKER_NON_BLOCKING);
gearman_worker_set_timeout(&worker, 5000);
return;
}
示例13: test_cipher_nego
static void test_cipher_nego(void *z)
{
struct Worker *server = NULL, *client = NULL;
tt_assert(tls_init() == 0);
/* server key is EC:secp384r1 - ECDHE-ECDSA */
str_check(create_worker(&server, true, "show=ciphers", SERVER1, NULL), "OK");
str_check(create_worker(&client, false, CA1,
"ciphers=AESGCM",
"host=server1.com",
NULL), "OK");
str_any3(run_case(client, server),
"TLSv1.2/ECDHE-ECDSA-AES256-GCM-SHA384/ECDH=secp384r1",
"TLSv1.2/ECDHE-ECDSA-AES256-GCM-SHA384/ECDH=X25519",
"TLSv1.2/ECDHE-ECDSA-AES256-GCM-SHA384");
/* server key is RSA - ECDHE-RSA */
str_check(create_worker(&server, true, "show=ciphers", SERVER2, NULL), "OK");
str_check(create_worker(&client, false, CA2,
"ciphers=AESGCM",
"host=server2.com",
NULL), "OK");
str_any3(run_case(client, server),
"TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=prime256v1",
"TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=X25519",
"TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384");
/* server key is RSA - DHE-RSA */
str_check(create_worker(&server, true, SERVER2,
"show=ciphers",
"dheparams=auto",
NULL), "OK");
str_check(create_worker(&client, false, CA2,
"ciphers=EDH+AESGCM",
"host=server2.com",
NULL), "OK");
str_check(run_case(client, server), "TLSv1.2/DHE-RSA-AES256-GCM-SHA384/DH=2048");
/* server key is RSA - ECDHE-RSA */
str_check(create_worker(&server, true, SERVER2,
"show=ciphers",
NULL), "OK");
str_check(create_worker(&client, false, CA2,
"ciphers=EECDH+AES",
"host=server2.com",
NULL), "OK");
str_any3(run_case(client, server),
"TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=prime256v1",
"TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=X25519",
"TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384");
end:;
}
示例14: test_noverifyname
static void test_noverifyname(void *z)
{
struct Worker *server = NULL, *client = NULL;
tt_assert(tls_init() == 0);
/* noverifyname: client checks server cert, ignore bad hostname */
str_check(create_worker(&server, true, SERVER1, NULL), "OK");
str_check(create_worker(&client, false, CA1, "host=example2.com",
"noverifyname=1",
NULL), "OK");
str_check(run_case(client, server), "OK");
/* noverifyname: client checks server cert, ignore NULL hostname */
str_check(create_worker(&server, true, SERVER1, NULL), "OK");
str_check(create_worker(&client, false, CA1, "noverifyname=1", NULL), "OK");
str_check(run_case(client, server), "OK");
end:;
}
示例15: thread_init
/*
* Initializes the thread subsystem, creating various worker threads.
*
* nthreads Number of worker event handler threads to spawn
* main_base Event base for main thread
*/
void thread_init(int nthreads, struct event_base *main_base) {
int i;
pthread_mutex_init(&cache_lock, NULL);/*Lock for cache operations (item_*, assoc_*)*/
pthread_mutex_init(&stats_lock, NULL);/*Lock for global stats*/
pthread_mutex_init(&init_lock, NULL);
pthread_cond_init(&init_cond, NULL);
pthread_mutex_init(&cqi_freelist_lock, NULL);
cqi_freelist = NULL;
threads = calloc(nthreads, sizeof(LIBEVENT_THREAD));
/* 分配一个数组 ,数据大小为nthreads ,
* 数据的的每个元素的内存空间为 sizeof(LIEVENT_THREAD) 并且,返回一个指针,
* 指向该数组*/
/* Allocate nthreads elements of sizeof(LIBEVENT_THREAD) bytes each, all initialized to 0. */
if (! threads) {//很明显这是是提示说tmd竟然分配内存失败了!
perror("Can't allocate thread descriptors");
exit(1);
}
dispatcher_thread.base = main_base;
/*main_base这个是主线程的libevent句柄,这个在main()方法里面初始化*/
dispatcher_thread.thread_id = pthread_self();/*获取当前线程的id 。*/
for (i = 0; i < nthreads; i++) {
int fds[2];
if (pipe(fds)) {//创建一个管道符,用于两个进程之间的联系
perror("Can't create notify pipe");
exit(1);
}
threads[i].notify_receive_fd = fds[0];
threads[i].notify_send_fd = fds[1];
setup_thread(&threads[i]);//设置一些线程信息
}
/* Create threads after we've done all the libevent setup. */
for (i = 0; i < nthreads; i++) {
//顾名思义,每个线程的信息初始化完毕,开始创建线程
create_worker(worker_libevent, &threads[i]);
}
/*
* 主线程等所有线程创建完毕之后再结束
* Wait for all the threads to set themselves up before returning. */
pthread_mutex_lock(&init_lock);
while (init_count < nthreads) {
pthread_cond_wait(&init_cond, &init_lock);
}
pthread_mutex_unlock(&init_lock);
}