本文整理汇总了C++中pthread_cancel函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_cancel函数的具体用法?C++ pthread_cancel怎么用?C++ pthread_cancel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_cancel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: do_one_test
static int
do_one_test (void)
{
in_sh_body = 0;
cleanups = 0;
if (pipe (fd) != 0 || pipe (fd + 2) != 0)
{
puts ("pipe failed");
return 1;
}
pthread_t th;
if (pthread_create (&th, NULL, tf, NULL) != 0)
{
puts ("create failed");
return 1;
}
int r = pthread_barrier_wait (&b);
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
{
puts ("parent thread: barrier_wait failed");
return 1;
}
sleep (1);
r = pthread_kill (th, SIGHUP);
if (r)
{
errno = r;
printf ("pthread_kill failed %m\n");
return 1;
}
while (in_sh_body == 0)
sleep (1);
if (pthread_cancel (th) != 0)
{
puts ("cancel failed");
return 1;
}
void *ret;
if (pthread_join (th, &ret) != 0)
{
puts ("join failed");
return 1;
}
if (ret != PTHREAD_CANCELED)
{
puts ("result is wrong");
return 1;
}
if (cleanups != 0x1234L)
{
printf ("called cleanups %lx\n", cleanups);
return 1;
}
/* The pipe closing must be issued after the cancellation handling to avoid
a race condition where the cancellation runs after both pipe ends are
closed. In this case the read syscall returns EOF and the cancellation
must not act. */
close (fd[0]);
close (fd[1]);
close (fd[2]);
close (fd[3]);
return 0;
}
开发者ID:eva-oss,项目名称:glibc-linaro,代码行数:74,代码来源:tst-cancel20.c
示例2: limitMonitorJoin
static void limitMonitorJoin(void)
{
pthread_cancel(limit_monitor.th);
pthread_join(limit_monitor.th, NULL);
pthread_mutex_destroy(&limit_monitor.lock);
}
开发者ID:danfis,项目名称:maplan,代码行数:6,代码来源:search.c
示例3: if
int16 XSERDPort::open(uint16 config)
{
// Don't open NULL name devices
if (device_name == NULL)
return openErr;
// Init variables
io_killed = false;
quitting = false;
// Open port, according to the syntax of the path
if (device_name[0] == '|') {
// Open a process via ptys
if (!open_pty())
goto open_error;
}
else if (!strcmp(device_name, "midi")) {
// MIDI: not yet implemented
return openErr;
}
else {
// Device special file
fd = ::open(device_name, O_RDWR);
if (fd < 0)
goto open_error;
#if defined(__linux__)
// Parallel port?
struct stat st;
if (fstat(fd, &st) == 0)
if (S_ISCHR(st.st_mode))
protocol = ((MAJOR(st.st_rdev) == LP_MAJOR) ? parallel : serial);
#elif defined(__FreeBSD__) || defined(__NetBSD__)
// Parallel port?
struct stat st;
if (fstat(fd, &st) == 0)
if (S_ISCHR(st.st_mode))
protocol = (((st.st_rdev >> 16) == 16) ? parallel : serial);
#endif
}
// Configure port for raw mode
if (protocol == serial || protocol == pty) {
if (tcgetattr(fd, &mode) < 0)
goto open_error;
cfmakeraw(&mode);
mode.c_cflag |= HUPCL;
mode.c_cc[VMIN] = 1;
mode.c_cc[VTIME] = 0;
tcsetattr(fd, TCSAFLUSH, &mode);
}
configure(config);
// Start input/output threads
input_thread_cancel = false;
output_thread_cancel = false;
if (sem_init(&input_signal, 0, 0) < 0)
goto open_error;
if (sem_init(&output_signal, 0, 0) < 0)
goto open_error;
input_thread_active = (pthread_create(&input_thread, &thread_attr, input_func, this) == 0);
output_thread_active = (pthread_create(&output_thread, &thread_attr, output_func, this) == 0);
if (!input_thread_active || !output_thread_active)
goto open_error;
return noErr;
open_error:
if (input_thread_active) {
input_thread_cancel = true;
#ifdef HAVE_PTHREAD_CANCEL
pthread_cancel(input_thread);
#endif
pthread_join(input_thread, NULL);
sem_destroy(&input_signal);
input_thread_active = false;
}
if (output_thread_active) {
output_thread_cancel = true;
#ifdef HAVE_PTHREAD_CANCEL
pthread_cancel(output_thread);
#endif
pthread_join(output_thread, NULL);
sem_destroy(&output_signal);
output_thread_active = false;
}
if (fd > 0) {
::close(fd);
fd = -1;
}
return openErr;
}
开发者ID:habnabit,项目名称:macemu,代码行数:91,代码来源:serial_unix.cpp
示例4: discovery_stop
void discovery_stop(discovery_t* self) {
assert(self);
pthread_cancel(self->thread);
}
开发者ID:TeamElevate,项目名称:network,代码行数:5,代码来源:discovery.c
示例5: spi_console_exit
static void spi_console_exit(int sig)
{
DEBUG_PRINT("Get SIGINT.\n");
pthread_cancel(spi_bridge.read_mcu_tidp);
pthread_cancel(spi_bridge.read_stdin_tidp);
}
开发者ID:SchumyHao,项目名称:openwrt-packages,代码行数:6,代码来源:main.c
示例6: vlc_cancel
/* Marks a thread as cancelled. Next time the target thread reaches a
* cancellation point (while not having disabled cancellation), it will
* run its cancellation cleanup handler, the thread variable destructors, and
* terminate. vlc_join() must be used afterward regardless of a thread being
* cancelled or not. */
void vlc_cancel (vlc_thread_t thread_id)
{
pthread_cancel (thread_id);
}
开发者ID:chucolin,项目名称:vlc,代码行数:9,代码来源:thread.c
示例7: main
//.........这里部分代码省略.........
while (1) {
/* Reset buffer */
memset(buf, 0, sizeof(buf));
/* Receive DNS UDP request */
recv_size = dns_udp_recv_query(udp_client_sock, buf, sizeof(buf),
(struct sockaddr *) &saddr);
if (recv_size < 0) {
/* At this point... better clean exit */
goto error;
}
/* Change buf to fit DNS TCP request */
forge_tcp_request(buf, &recv_size);
/*
* Make the DNS query on the TCP transport layer either using inprocess
* SSH or using an already created TCP tunnel (Ex: ssh -L ... on the
* command line).
*/
if (ssh_host != NULL) {
/*
* Round robin option. We must create the ssh tunnel and close it
* at each DNS query.
*/
if (opt_rr_dns) {
if ((open_dns_count - dns_index) == 0) {
dns_index = 0;
}
/*
* We don't create a new SSH channel for the first run since it
* was created before the main loop hence the reason for
* dns_index being -1.
*/
if (dns_index != -1) {
dns_ip = open_dns_list[dns_index];
/*
* Create new SSH direct tcp channel. We don't care about
* the return value because on error, the next call will
* handle it.
*/
libssh2_channel_free(ssh_info->channel);
ret = ssh_setup_tunnel(ssh_info, dns_ip);
if (ret < 0) {
continue;
}
DBG("Round robin DNS %s", dns_ip);
}
dns_index++;
}
recv_size = dig_ssh_request(ssh_info, buf, sizeof(buf),
recv_size);
if (ret < 0) {
do {
sleep(DEFAULT_RECONNECT_TIME);
ret = ssh_setup_tunnel(ssh_info, dns_ip);
} while (ret < 0);
continue;
}
} else {
recv_size = dig_tcp_request(tcp_dns_sock, buf, sizeof(buf),
recv_size);
if (recv_size < 0) {
/* Connect to forward TCP server */
do {
/* Retry every DEFAULT_RECONNECT_TIME sec */
sleep(DEFAULT_RECONNECT_TIME);
tcp_dns_sock = setup_forward_tcp(forward_port, forward_ip);
} while (tcp_dns_sock < 0);
continue;
}
}
/* Change buf to fit DNS UDP request */
forge_udp_request(buf, &recv_size);
ret = dns_udp_send_reply(udp_client_sock, buf, recv_size,
(struct sockaddr *) &saddr, sizeof(saddr));
if (ret < 0) {
/* UDP client disconnected, continue serving */
continue;
}
}
/* Not suppose to get here */
error:
ret = pthread_cancel(log_thread);
if (ret == 0) {
pthread_join(log_thread, &status);
}
close(tcp_dns_sock);
close(udp_client_sock);
cleanup(ret);
return 0;
}
开发者ID:dgoulet,项目名称:debind,代码行数:101,代码来源:main.c
示例8: msg_thread_stop
/* this stops the logger thread. hard. */
int msg_thread_stop(void)
{
return(pthread_cancel(log_thread));
}
开发者ID:BackupTheBerlios,项目名称:vermont-svn,代码行数:5,代码来源:msg.c
示例9: myhtml_thread_cancel
myhtml_status_t myhtml_thread_cancel(mythread_t *mythread, mythread_list_t *thr)
{
pthread_cancel(thr->pth);
return MyHTML_STATUS_OK;
}
开发者ID:adrianhust,项目名称:myhtml,代码行数:5,代码来源:thread.c
示例10: fullscrape_deinit
void fullscrape_deinit( ) {
pthread_cancel( thread_id );
}
开发者ID:Gastlag,项目名称:Opentracker,代码行数:3,代码来源:ot_fullscrape.c
示例11: TRACE_BEGIN
void Thread::OnStop()
{
TRACE_BEGIN( LOG_LVL_INFO );
pthread_cancel( mThread );
}
开发者ID:benpayne,项目名称:jhcommon,代码行数:5,代码来源:Thread.cpp
示例12: test_cleanup1
int
test_cleanup1(void)
#endif
{
int failed = 0;
int i;
pthread_t t[NUMTHREADS + 1];
memset(&pop_count, 0, sizeof(sharedInt_t));
InitializeCriticalSection(&pop_count.cs);
assert((t[0] = pthread_self()).p != NULL);
for (i = 1; i <= NUMTHREADS; i++)
{
threadbag[i].started = 0;
threadbag[i].threadnum = i;
assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
}
/*
* Code to control or manipulate child threads should probably go here.
*/
Sleep(500);
for (i = 1; i <= NUMTHREADS; i++)
{
assert(pthread_cancel(t[i]) == 0);
}
/*
* Give threads time to run.
*/
Sleep(NUMTHREADS * 100);
/*
* Standard check that all threads started.
*/
for (i = 1; i <= NUMTHREADS; i++)
{
if (!threadbag[i].started)
{
failed |= !threadbag[i].started;
fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
}
}
assert(!failed);
/*
* Check any results here. Set "failed" and only print output on failure.
*/
failed = 0;
for (i = 1; i <= NUMTHREADS; i++)
{
int fail = 0;
void* result = (void*)0;
assert(pthread_join(t[i], &result) == 0);
fail = (result != PTHREAD_CANCELED);
if (fail)
{
fprintf(stderr, "Thread %d: started %d: result %d\n",
i,
threadbag[i].started,
(int)(size_t)result);
}
failed = (failed || fail);
}
assert(!failed);
assert(pop_count.i == NUMTHREADS);
DeleteCriticalSection(&pop_count.cs);
/*
* Success.
*/
return 0;
}
开发者ID:wbminera1,项目名称:pthread-win32,代码行数:84,代码来源:cleanup1.c
示例13: main
int main()
{
int num,i = 0;
char tmp[MAX_TH_NUM];
times = 1;
num = 2;
printf("Usage:\n"
"\tgo: start test\n"
"\tabort: cancel thread\n"
"\tstatus: show test status\n"
"\texit: exit the program\n"
"\tthread n: create n threads to test\n"
"\ttimes n: each mem unit tests n times\n"
"Default: 1 times and 2 threads\n"
);
fflush(stdout);
while(1)
{
printf(">>>");
fflush(stdout);
scanf(" %s",tmp);
if(strcmp(tmp,"times") == 0)
{
scanf(" %d",×);
continue;
}
if(strcmp(tmp,"thread") == 0)
{
scanf(" %d",&num);
continue;
}
if(strcmp(tmp,"exit") == 0)
{
exit(0);
}
if(strcmp(tmp,"go") == 0)
{
for(i=0;i<num;i++)
{
test_addr[i] = (unsigned long) malloc(MEM_SIZE*sizeof(unsigned char));
pthread_create(&tid[i],memtest,test_addr[i]);
}
continue;
}
if(strcmp(tmp,"status") == 0)
{
for(i=0;i<num;i++)
{
printf("Thread %d : ",tid[i]);
switch(pthread_status(tid[i]))
{
case -1:
printf("is to be created\n");
break;
case 0:
printf("is running\n");
break;
case 1:
printf("is waiting\n");
break;
case 2:
printf("is waiting\n");
break;
case 4:
printf("is stopped\n");
pthread_join(tid[i],&result[i]);
printf("\tTest Addr: %X Result: %d/%d(OK)\n",test_addr[i],result[i],MEM_SIZE);
break;
case 5:
printf("is canceled\n");
break;
default:
printf("no such thread\n");
break;
}
}
continue;
}
if(strcmp(tmp,"abort") == 0)
{
for(i=0;i<num;i++)
{
if(tid[i])
{
pthread_cancel(tid[i]);
}
}
continue;
}
}
}
开发者ID:guker,项目名称:HIT-OSLab,代码行数:92,代码来源:memtest.c
示例14: cancel_all_threads
static void cancel_all_threads()
{
int i = 0;
int wait_listener_time = 10000;
int wait_for_workers = CHILD_SHUTDOWN_TIMEOUT>5?CHILD_SHUTDOWN_TIMEOUT:5;
int servers_running;
/*Cancel listener thread .... */
/*we are going to wait maximum about 10 ms */
while (wait_listener_time > 0 && listener_running != 0) {
/*Interrupt listener if it is waiting for threads or
waiting to accept new connections */
#ifdef SINGLE_ACCEPT
pthread_cancel(listener_thread_id); /*..... */
#else
pthread_kill(listener_thread_id, SIGHUP);
#endif
ci_thread_cond_signal(&free_server_cond);
ci_usleep(1000);
wait_listener_time -= 10;
}
if (listener_running == 0) {
ci_debug_printf(5,
"Going to wait for the listener thread (pid: %d) to exit!\n",
threads_list[0]->srv_id);
ci_thread_join(listener_thread_id);
ci_debug_printf(5, "OK, cancelling the listener thread (pid: %d)!\n",
threads_list[0]->srv_id);
}
else {
/*fuck the listener! going down ..... */
}
/*We are going to interupt the waiting for queue childs.
We are going to wait threads which serve a request. */
ci_thread_cond_broadcast(&(con_queue->queue_cond));
/*wait for a milisecond*/
ci_usleep(1000);
servers_running = CI_CONF.THREADS_PER_CHILD;
while (servers_running && wait_for_workers >= 0) {
/*child_data->to_be_killed, may change while we are inside this loop*/
if (child_data->to_be_killed == IMMEDIATELY) {
CHILD_HALT = 1;
}
for (i=0; i<CI_CONF.THREADS_PER_CHILD; i++) {
if (threads_list[i] != NULL) { /* if the i thread is still alive*/
if (!threads_list[i]->running) { /*if the i thread is not running any more*/
ci_debug_printf(5, "Cancel server %d, thread_id %lu (%d)\n",
threads_list[i]->srv_id, threads_list[i]->srv_pthread,
i);
ci_thread_join(threads_list[i]->srv_pthread);
release_thread_i(i);
servers_running --;
}
else if (child_data->to_be_killed == IMMEDIATELY){
/*The thread is still running, and we have a timeout for waiting
the thread to exit. */
if (wait_for_workers <= 2) {
ci_debug_printf(5, "Thread %ld still running near the timeout. Try to kill it\n", threads_list[i]->srv_pthread);
pthread_kill( threads_list[i]->srv_pthread, SIGTERM);
}
}
}/*the i thread is still alive*/
} /* for(i=0;i< CI_CONF.THREADS_PER_CHILD;i++)*/
/*wait for 1 second for the next round*/
ci_usleep(999999);
/*
The child_data->to_be_killed may change while we are running this function.
In the case it has/got the value IMMEDIATELY decrease wait_for_workers:
*/
if (child_data->to_be_killed == IMMEDIATELY)
wait_for_workers --;
} /* while(servers_running)*/
if (servers_running) {
ci_debug_printf(5, "Not all the servers canceled. Anyway exiting....\n");
}
else {
ci_debug_printf(5, "All servers canceled\n");
free(threads_list);
}
}
开发者ID:Shield-Firewall,项目名称:c-icap,代码行数:84,代码来源:mpmt_server.c
示例15: sigemptyset
void *restore_thrd(void *arg) {
sigset_t sigmask, old_mask;
int i, sig;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT);
sigaddset(&sigmask, SIGTERM);
sigaddset(&sigmask, SIGUSR1);
pthread_sigmask(SIG_BLOCK, &sigmask, &old_mask);
while (1) {
sigwait(&sigmask, &sig);
if ((sig == SIGINT || sig == SIGTERM) && !interrupted) {
ERROR("Interrupting will restore original " "filesystem!\n");
ERROR("Interrupt again to quit\n");
interrupted = TRUE;
continue;
}
/* kill main thread/worker threads and restore */
set_progressbar_state(FALSE);
disable_info();
/* first kill the reader thread */
pthread_cancel(reader_thread);
pthread_join(reader_thread, NULL);
/*
* then flush the reader to deflator thread(s) output queue.
* The deflator thread(s) will idle
*/
queue_flush(to_deflate);
/* now kill the deflator thread(s) */
for (i = 0; i < processors; i++)
pthread_cancel(deflator_thread[i]);
for (i = 0; i < processors; i++)
pthread_join(deflator_thread[i], NULL);
/*
* then flush the reader to process fragment thread(s) output
* queue. The process fragment thread(s) will idle
*/
queue_flush(to_process_frag);
/* now kill the process fragment thread(s) */
for (i = 0; i < processors; i++)
pthread_cancel(frag_thread[i]);
for (i = 0; i < processors; i++)
pthread_join(frag_thread[i], NULL);
/*
* then flush the reader/deflator/process fragment to main
* thread output queue. The main thread will idle
*/
seq_queue_flush(to_main);
/* now kill the main thread */
pthread_cancel(main_thread);
pthread_join(main_thread, NULL);
/* then flush the main thread to fragment deflator thread(s)
* queue. The fragment deflator thread(s) will idle
*/
queue_flush(to_frag);
/* now kill the fragment deflator thread(s) */
for (i = 0; i < processors; i++)
pthread_cancel(frag_deflator_thread[i]);
for (i = 0; i < processors; i++)
pthread_join(frag_deflator_thread[i], NULL);
/*
* then flush the main thread/fragment deflator thread(s)
* to writer thread queue. The writer thread will idle
*/
queue_flush(to_writer);
/* now kill the writer thread */
pthread_cancel(writer_thread);
pthread_join(writer_thread, NULL);
TRACE("All threads cancelled\n");
restorefs();
}
}
开发者ID:OliverGesch,项目名称:epk2extract,代码行数:88,代码来源:restore.c
示例16: ssh_aes_ctr_init
static int
ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
int enc)
{
struct ssh_aes_ctr_ctx *c;
int i;
if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) {
c = xmalloc(sizeof(*c));
c->state = HAVE_NONE;
for (i = 0; i < NUMKQ; i++) {
pthread_mutex_init(&c->q[i].lock, NULL);
pthread_cond_init(&c->q[i].cond, NULL);
}
STATS_INIT(c->stats);
EVP_CIPHER_CTX_set_app_data(ctx, c);
}
if (c->state == (HAVE_KEY | HAVE_IV)) {
/* Cancel pregen threads */
for (i = 0; i < CIPHER_THREADS; i++)
pthread_cancel(c->tid[i]);
for (i = 0; i < CIPHER_THREADS; i++)
pthread_join(c->tid[i], NULL);
/* Start over getting key & iv */
c->state = HAVE_NONE;
}
if (key != NULL) {
AES_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8,
&c->aes_ctx);
c->state |= HAVE_KEY;
}
if (iv != NULL) {
memcpy(ctx->iv, iv, AES_BLOCK_SIZE);
c->state |= HAVE_IV;
}
if (c->state == (HAVE_KEY | HAVE_IV)) {
/* Clear queues */
memcpy(c->q[0].ctr, ctx->iv, AES_BLOCK_SIZE);
c->q[0].qstate = KQINIT;
for (i = 1; i < NUMKQ; i++) {
memcpy(c->q[i].ctr, ctx->iv, AES_BLOCK_SIZE);
ssh_ctr_add(c->q[i].ctr, i * KQLEN, AES_BLOCK_SIZE);
c->q[i].qstate = KQEMPTY;
}
c->qidx = 0;
c->ridx = 0;
/* Start threads */
for (i = 0; i < CIPHER_THREADS; i++) {
pthread_create(&c->tid[i], NULL, thread_loop, c);
}
pthread_mutex_lock(&c->q[0].lock);
while (c->q[0].qstate != KQDRAINING)
pthread_cond_wait(&c->q[0].cond, &c->q[0].lock);
pthread_mutex_unlock(&c->q[0].lock);
}
return (1);
}
开发者ID:knakahara,项目名称:netbsd-src,代码行数:66,代码来源:cipher-ctr-mt.c
示例17: sandbox_execute
result_t *
sandbox_execute(sandbox_t * psbox)
{
FUNC_BEGIN("sandbox_execute(%p)", psbox);
assert(psbox);
if (psbox == NULL)
{
WARNING("psbox: bad pointer");
FUNC_RET(NULL, "sandbox_execute()");
}
if (!sandbox_check(psbox))
{
WARNING("sandbox pre-execution state check failed");
FUNC_RET(&psbox->result, "sandbox_execute()");
}
#ifdef WITH_CUSTOM_MONITOR
pthread_t tid;
if (pthread_create(&tid, NULL, psbox->ctrl.monitor, (void *)psbox) != 0)
{
WARNING("failed creating the monitor thread");
FUNC_RET(&psbox->result, "sandbox_execute()");
}
DBG("created the monitor thread");
#endif /* WITH_CUSTOM_MONITOR */
/* Fork the prisoner process */
psbox->ctrl.pid = fork();
/* Execute the prisoner program */
if (psbox->ctrl.pid == 0)
{
DBG("entering: the prisoner program");
/* Start executing the prisoner program */
_exit(__sandbox_task_execute(&psbox->task));
}
else
{
DBG("target program forked as pid %d", psbox->ctrl.pid);
/* Start executing the tracing thread */
psbox->ctrl.tracer(psbox);
}
#ifdef WITH_CUSTOM_MONITOR
if (pthread_join(tid, NULL) != 0)
{
WARNING("failed joining the monitor thread");
if (pthread_cancel(tid) != 0)
{
WARNING("failed canceling the monitor thread");
FUNC_RET(NULL, "sandbox_execute()");
}
}
DBG("joined the monitor thread");
#endif /* WITH_CUSTOM_MONITOR */
FUNC_RET(&psbox->result, "sandbox_execute()");
}
开发者ID:LiuCihang,项目名称:OJ,代码行数:62,代码来源:sandbox.c
示例18: ipsec_process_prefs
// ----------------------------------------------------------------------------
// process_prefs
// ----------------------------------------------------------------------------
int ipsec_process_prefs(struct vpn_params *params)
{
char *errstr, c;
CFStringRef string;
if (ipsec_conf) {
CFRelease(ipsec_conf);
ipsec_conf = NULL;
}
ipsec_conf = (CFMutableDictionaryRef)CFDictionaryGetValue(params->serverRef, kRASEntIPSec);
if (ipsec_conf == NULL) {
vpnlog(LOG_ERR, "IPSec plugin: IPSec dictionary not present\n");
goto fail;
}
ipsec_conf = CFDictionaryCreateMutableCopy(NULL, 0, ipsec_conf);
remoteaddress[0] = 0;
string = CFDictionaryGetValue(ipsec_conf, kRASPropIPSecRemoteAddress);
if (isString(string))
CFStringGetCString(string, remoteaddress, sizeof(remoteaddress), kCFStringEncodingUTF8);
if (inet_aton(remoteaddress, &peer_address) == 0) {
if (pipe(resolverfds) < 0) {
vpnlog(LOG_ERR, "IPSec plugin: failed to create pipe for gethostbyname\n");
goto fail;
}
if (pthread_create(&resolverthread, NULL, ipsec_resolver_thread, NULL)) {
vpnlog(LOG_ERR, "IPSec plugin: failed to create thread for gethostbyname...\n");
close(resolverfds[0]);
close(resolverfds[1]);
goto fail;
}
while (read(resolverfds[0], &c, 1) != 1) {
if (got_terminate()) {
pthread_cancel(resolverthread);
break;
}
}
close(resolverfds[0]);
close(resolverfds[1]);
if (got_terminate())
goto fail;
if (c) {
vpnlog(LOG_ERR, "IPSec plugin: Host '%s' not found...\n", remoteaddress);
goto fail;
}
string = CFStringCreateWithCString(0, addr2ascii(AF_INET, &peer_address, sizeof(peer_address), 0), kCFStringEncodingASCII);
CFDictionarySetValue(ipsec_conf, kRASPropIPSecRemoteAddress, string);
CFRelease(string);
}
// verify the dictionary
if (IPSecValidateConfiguration(ipsec_conf, &errstr)) {
vpnlog(LOG_ERR, "IPSec plugin: Incorrect preferences (%s)\n", errstr);
goto fail;
}
return 0;
fail:
if (ipsec_conf) {
CFRelease(ipsec_conf);
ipsec_conf = NULL;
}
return -1;
}
开发者ID:TARRANUM,项目名称:ppp,代码行数:79,代码来源:ipsecoptions.c
示例19: gg_debug
//.........这里部分代码省略.........
* - h - struktura opisuj±ca po³±czenie
*
* je¶li wszystko posz³o dobrze to 0, inaczej -1. po³±czenie bêdzie
* zakoñczone, je¶li h->state == GG_STATE_PARSING. je¶li wyst±pi jaki¶
* b³±d, to bêdzie tam GG_STATE_ERROR i odpowiedni kod b³êdu w h->error.
*/
int gg_http_watch_fd(struct gg_http *h)
{
gg_debug(GG_DEBUG_FUNCTION, "** gg_http_watch_fd(%p);\n", h);
if (!h) {
gg_debug(GG_DEBUG_MISC, "// gg_http_watch_fd() invalid arguments\n");
errno = EINVAL;
return -1;
}
if (h->state == GG_STATE_RESOLVING) {
struct in_addr a;
gg_debug(GG_DEBUG_MISC, "=> http, resolving done\n");
if (read(h->fd, &a, sizeof(a)) < (signed)sizeof(a) || a.s_addr == INADDR_NONE) {
gg_debug(GG_DEBUG_MISC, "=> http, resolver thread failed\n");
gg_http_error(GG_ERROR_RESOLVING);
}
close(h->fd);
h->fd = -1;
#ifndef __GG_LIBGADU_HAVE_PTHREAD
waitpid(h->pid, NULL, 0);
#else
if (h->resolver) {
pthread_cancel(*((pthread_t *) h->resolver));
free(h->resolver);
h->resolver = NULL;
}
#endif
gg_debug(GG_DEBUG_MISC, "=> http, connecting to %s:%d\n", inet_ntoa(a), h->port);
if ((h->fd = gg_connect(&a, h->port, h->async)) == -1) {
gg_debug(GG_DEBUG_MISC, "=> http, connection failed (errno=%d, %s)\n", errno, strerror(errno));
gg_http_error(GG_ERROR_CONNECTING);
}
h->state = GG_STATE_CONNECTING;
h->check = GG_CHECK_WRITE;
h->timeout = GG_DEFAULT_TIMEOUT;
return 0;
}
if (h->state == GG_STATE_CONNECTING) {
int res = 0;
unsigned int res_size = sizeof(res);
if (h->async && (getsockopt(h->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) {
gg_debug(GG_DEBUG_MISC, "=> http, async connection failed (errno=%d, %s)\n", (res) ? res : errno , strerror((res) ? res : errno));
close(h->fd);
h->fd = -1;
h->state = GG_STATE_ERROR;
h->error = GG_ERROR_CONNECTING;
if (res)
errno = res;
return 0;
开发者ID:HaikuArchives,项目名称:BeGadu,代码行数:67,代码来源:http.c
示例20: pthread_cancel
/* This method is used to kill the stdin_loop before exiting from factor.
A Nvidia driver bug on Linux is the reason this has to be done, see:
http://www.nvnews.net/vbulletin/showthread.php?t=164619 */
void factor_vm::close_console() {
if (stdin_thread_initialized_p) {
pthread_cancel(stdin_thread);
pthread_join(stdin_thread, 0);
}
}
开发者ID:pombreda,项目名称:factor,代码行数:9,代码来源:os-unix.cpp
注:本文中的pthread_cancel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论