void pc_client_destroy(pc_client_t *client) { pc_client_state state; uv_mutex_lock(&client->state_mutex); state = client->state; uv_mutex_unlock(&client->state_mutex); if(PC_ST_INITED == client->state) { goto finally; } if(PC_ST_CLOSED == client->state) { goto finally; } pc_client_disconnect(client); pc_client_join(client); finally: pc__client_clear(client); if(client->uv_loop) { uv_loop_delete(client->uv_loop); client->uv_loop = NULL; } pc_jsonp_free(client); }
void pc_client_destroy(pc_client_t *client) { if(PC_ST_INITED == client->state) { pc__client_clear(client); goto finally; } if(PC_ST_CLOSED == client->state) { pc__client_clear(client); goto finally; } // 1. asyn worker thread // 2. wait work thread exit // 3. free client uv_async_send(client->close_async); pc_client_join(client); if(PC_ST_CLOSED != client->state) { pc_client_stop(client); // wait uv_loop_t stop sleep(1); pc__client_clear(client); } finally: if(client->uv_loop) { uv_loop_delete(client->uv_loop); client->uv_loop = NULL; } free(client); }
static int unload_module(void) { unsigned int i = 0; LNOTICE("unloaded module %s", module_name); for (i = 0; i < profile_size; i++) { close_socket(i); free_profile(i); } #if UV_VERSION_MAJOR == 0 uv_async_send(&async_handle); uv_loop_delete(loop); #else if (uv_loop_alive(loop)) { uv_async_send(&async_handle); } uv_stop(loop); uv_loop_close(loop); free(loop); #endif /* Close socket */ return 0; }
static void do_work(void* arg) { struct getaddrinfo_req getaddrinfo_reqs[16]; struct fs_req fs_reqs[16]; uv_loop_t* loop; size_t i; int r; struct test_thread* thread = arg; loop = uv_loop_new(); ASSERT(loop != NULL); for (i = 0; i < ARRAY_SIZE(getaddrinfo_reqs); i++) { struct getaddrinfo_req* req = getaddrinfo_reqs + i; req->counter = 16; req->loop = loop; getaddrinfo_do(req); } for (i = 0; i < ARRAY_SIZE(fs_reqs); i++) { struct fs_req* req = fs_reqs + i; req->counter = 16; req->loop = loop; fs_do(req); } r = uv_run(loop, UV_RUN_DEFAULT); ASSERT(r == 0); uv_loop_delete(loop); thread->thread_called = 1; }
static void loop_creating_worker(void* context) { (void) context; do { uv_loop_t* loop; uv_signal_t signal; int r; loop = uv_loop_new(); ASSERT(loop != NULL); r = uv_signal_init(loop, &signal); ASSERT(r == 0); r = uv_signal_start(&signal, signal_unexpected_cb, SIGTERM); ASSERT(r == 0); uv_close((uv_handle_t*) &signal, NULL); r = uv_run(loop); ASSERT(r == 0); uv_loop_delete(loop); increment_counter(&loop_creation_counter); } while (!stop); }
void connection_consumer_start(void *arg) { int rc; struct server_ctx *ctx; uv_loop_t* loop; ctx = arg; loop = uv_loop_new(); listener_event_loops[ctx->index] = *loop; http_request_cache_configure_listener(loop, &listener_async_handles[ctx->index]); uv_barrier_wait(listeners_created_barrier); rc = uv_async_init(loop, &ctx->async_handle, connection_consumer_close); uv_unref((uv_handle_t*) &ctx->async_handle); /* Wait until the main thread is ready. */ uv_sem_wait(&ctx->semaphore); get_listen_handle(loop, (uv_stream_t*) &ctx->server_handle); uv_sem_post(&ctx->semaphore); rc = uv_listen((uv_stream_t*)&ctx->server_handle, 128, connection_consumer_new_connection); rc = uv_run(loop, UV_RUN_DEFAULT); uv_loop_delete(loop); }
TSockSys::~TSockSys(){ // TSockSys cannot be uninitialized, if it is something went wrong IAssert(Active); // kill all existing connections int SockKeyId = SockHndToIdH.FFirstKeyId(); while (SockHndToIdH.FNextKeyId(SockKeyId)) { // check if already closed const uint64 SockId = SockHndToIdH[SockKeyId]; if (ClosedSockIdSet.IsKey(SockId)) { continue; } // get handle const uint64 SockHnd = SockHndToIdH.GetKey(SockKeyId); // close the handle without any callback, since TSockSys is getting killed uv_close((uv_handle_t*)SockHnd, NULL); } // kill all existing timer int TimerKeyId = TimerHndToSockIdH.FFirstKeyId(); while (TimerHndToSockIdH.FNextKeyId(TimerKeyId)) { // get timer handle const uint64 TimerHnd = TimerHndToSockIdH.GetKey(TimerKeyId); // close the handle without any callback, since TSockSys is getting killed uv_close((uv_handle_t*)TimerHnd, NULL); } // delete loop uv_loop_delete(Loop); // mark we are off Active = false; }
/* * Class: com_iwebpp_libuvpp_handles_LoopHandle * Method: _destroy * Signature: (J)V */ extern "C" JNIEXPORT void JNICALL Java_com_iwebpp_libuvpp_handles_LoopHandle__1destroy (JNIEnv *env, jobject that, jlong ptr) { assert(ptr); uv_loop_t* handle = reinterpret_cast<uv_loop_t*>(ptr); uv_loop_delete(handle); }
static int rava_thread_free(lua_State* L) { rava_thread_t* self = lua_touserdata(L, 1); TRACE("free thread\n"); uv_loop_delete(self->loop); TRACE("ok\n"); return 1; }
static int onFree(struct Allocator_OnFreeJob* job) { struct EventBase_pvt* ctx = Identity_cast((struct EventBase_pvt*) job->userData); if (ctx->running) { // The job will be completed in EventLoop_beginLoop() ctx->onFree = job; EventBase_endLoop((struct EventBase*) ctx); return Allocator_ONFREE_ASYNC; } else { uv_loop_delete(ctx->loop); return 0; } }
HTTP::~HTTP() { // destroy all open connections! for(std::vector<HTTPConnection*>::iterator it = connections.begin(); it != connections.end(); ++it) { delete *it; } connections.clear(); if(loop) { uv_loop_delete(loop); loop = NULL; } }
ThriftClient::~ThriftClient() { uv_loop_delete(_loop); delete _notifier; delete _stop; delete _contextQueue; while (_transportPool->Count > 0) { FrameTransport^ transport = _transportPool->Dequeue(); transport->Close(); } }
static void iops_lcb_dtor(lcb_io_opt_t iobase) { my_iops_t *io = (my_iops_t *)iobase; if (io->startstop_noop) { decref_iops(iobase); return; } while (io->iops_refcount > 1) { UVC_RUN_ONCE(io->loop); } if (io->external_loop == 0) { uv_loop_delete(io->loop); } decref_iops(iobase); }
Node::~Node() { delete [] nodeData->recvBufferMemoryBlock; SSL_CTX_free(nodeData->clientContext); int indices = NodeData::getMemoryBlockIndex(NodeData::preAllocMaxSize) + 1; for (int i = 0; i < indices; i++) { if (nodeData->preAlloc[i]) { delete [] nodeData->preAlloc[i]; } } delete [] nodeData->preAlloc; delete nodeData; if (loop != uv_default_loop()) { uv_loop_delete(loop); } }
void EventBase_beginLoop(struct EventBase* eventBase) { struct EventBase_pvt* ctx = Identity_cast((struct EventBase_pvt*) eventBase); Assert_always(!ctx->running); // double begin ctx->running = 1; // start the loop. uv_run(ctx->loop, UV_RUN_DEFAULT); ctx->running = 0; if (ctx->onFree) { uv_loop_delete(ctx->loop); Allocator_onFreeComplete(ctx->onFree); return; } }
void TLSConnectionPrivate::TLSConnectionThread(void *udata) { TLSConnectionPrivate *cp = static_cast<TLSConnectionPrivate *>(udata); cp->thread_id_.store(uv_thread_self()); uv_loop_t *loop = cp->loop_; int err; err = uv_run(loop, UV_RUN_DEFAULT); if (err != UV_OK) { cp->state_ = TLS_CONNECTION_STATE_DISCONNECTED_ERROR; cp->err_ = UVUtils::ErrorFromLastUVError(loop); } cp->thread_id_.store(0); uv_loop_delete(loop); uv_mutex_lock(&cp->wqlock_); cp->wq_ = std::queue<ByteArray>(); uv_mutex_unlock(&cp->wqlock_); switch (cp->state_) { case TLS_CONNECTION_STATE_DISCONNECTED_LOCAL: if (cp->disconnect_handler_) { cp->disconnect_handler_(true); } break; case TLS_CONNECTION_STATE_DISCONNECTED_REMOTE: if (cp->disconnect_handler_) { cp->disconnect_handler_(false); } break; case TLS_CONNECTION_STATE_DISCONNECTED_ERROR: if (cp->error_handler_) { cp->error_handler_(cp->err_); } break; default: NotReached(); } }
std::future<response> client::send(const request& req_) { return std::async(std::launch::async, [=]() -> response { response res; struct addrinfo hints; hints.ai_family = PF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = 0; uv_getaddrinfo_t resolver; data_t data; data.req = &req_; data.res = &res; data.loop = uv_loop_new(); resolver.data = &data; int r = uv_getaddrinfo( data.loop, &resolver, onResolved, req_.getUrl().getHost().c_str(), std::to_string(req_.getUrl().getPort()).c_str(), &hints ); if (r) { throw std::runtime_error(uv_err_name(r)); } uv_run(data.loop, UV_RUN_DEFAULT); uv_loop_delete(data.loop); return res; }); }
int main (int argc, char ** argv) { init (argc, argv); elektraIoTestSuite (createBinding, startLoop, stopLoop); // Run loop once to fire handle closed callbacks and free memory // see http://docs.libuv.org/en/v1.x/handle.html#c.uv_close uv_loop_t * loop = uv_default_loop (); uv_run (loop, UV_RUN_ONCE); #ifdef HAVE_LIBUV1 uv_loop_close (loop); #elif HAVE_LIBUV0 uv_loop_delete (loop); #endif print_result ("iowrapper_uv"); return nbError; }
extern "C" void rust_uv_loop_delete(uv_loop_t* loop) { // FIXME: This is a workaround for #1815. libev uses realloc(0) to // free the loop, which valgrind doesn't like. We have suppressions // to make valgrind ignore them. // // Valgrind also has a sanity check when collecting allocation backtraces // that the stack pointer must be at least 512 bytes into the stack (at // least 512 bytes of frames must have come before). When this is not // the case it doesn't collect the backtrace. // // Unfortunately, with our spaghetti stacks that valgrind check triggers // sometimes and we don't get the backtrace for the realloc(0), it // fails to be suppressed, and it gets reported as 0 bytes lost // from a malloc with no backtrace. // // This pads our stack with some extra space before deleting the loop alloca(512); uv_loop_delete(loop); }
int server_run(const server_config *cf, uv_loop_t *loop) { struct addrinfo hints; server_state state; int err; memset(&state, 0, sizeof(state)); state.servers = NULL; state.config = *cf; state.loop = loop; /* Resolve the address of the interface that we should bind to. * The getaddrinfo callback starts the server and everything else. */ memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; err = uv_getaddrinfo(loop, &state.getaddrinfo_req, do_bind, cf->bind_host, NULL, &hints); if (err != 0) { pr_err("getaddrinfo: %s", uv_strerror(err)); return err; } /* Start the event loop. Control continues in do_bind(). */ if (uv_run(loop, UV_RUN_DEFAULT)) { abort(); } /* Please Valgrind. */ uv_loop_delete(loop); free(state.servers); return 0; }
int main(int argc, char **argv) { struct addrinfo hints; int err; uv_getaddrinfo_t getaddrinfo_req; if (argc != 2) { printf("UNKNOWN args\n"); return 1; } memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; err = uv_getaddrinfo(uv_default_loop(), &getaddrinfo_req, address_cb, argv[1], NULL, &hints); if (err != 0) { printf("getaddrinfo: %s", uv_strerror(err)); return err; } /* Start the event loop. Control continues in do_bind(). */ if (uv_run(uv_default_loop(), UV_RUN_DEFAULT)) { abort(); } /* Please Valgrind. */ uv_loop_delete(uv_default_loop()); return 0; }
/* Destroys a given thread context. This will also free the nursery. * This means that it must no longer be in use, at all; this can be * ensured by a GC run at thread exit that forces evacuation of all * objects from this nursery to the second generation. Only after * that is true should this be called. */ void MVM_tc_destroy(MVMThreadContext *tc) { /* We run once again (non-blocking) to eventually close filehandles. */ uv_run(tc->loop, UV_RUN_NOWAIT); /* Free the nursery and finalization queue. */ MVM_free(tc->nursery_fromspace); MVM_free(tc->nursery_tospace); MVM_free(tc->finalizing); /* Destroy the second generation allocator. */ MVM_gc_gen2_destroy(tc->instance, tc->gen2); /* Destroy all callstack regions. */ MVM_callstack_region_destroy_all(tc); /* Free the thread-specific storage */ MVM_free(tc->gc_work); MVM_free(tc->temproots); MVM_free(tc->gen2roots); MVM_free(tc->finalize); /* Free any memory allocated for NFAs and multi-dim indices. */ MVM_free(tc->nfa_done); MVM_free(tc->nfa_curst); MVM_free(tc->nfa_nextst); MVM_free(tc->nfa_fates); MVM_free(tc->nfa_longlit); MVM_free(tc->multi_dim_indices); /* Free per-thread lexotic cache. */ MVM_free(tc->lexotic_cache); /* Destroy the libuv event loop */ uv_loop_delete(tc->loop); /* Free the thread context itself. */ memset(tc, 0, sizeof(MVMThreadContext)); MVM_free(tc); }
int main(int argc, char *argv[]) { ProxyContext proxy_context; uv_loop_t *event_loop = uv_loop_new(); stack_trace_on_crash(); proxy_context_init(&proxy_context, event_loop, argc, argv); app_context.proxy_context = &proxy_context; logger_noformat(&proxy_context, LOG_INFO, "Generating a new key pair"); dnscrypt_client_init_with_new_key_pair(&proxy_context.dnscrypt_client); logger_noformat(&proxy_context, LOG_INFO, "Done"); if (cert_updater_init(&proxy_context) != 0 || tcp_listener_bind(&proxy_context) != 0 || udp_listener_bind(&proxy_context) != 0) { exit(1); } signal(SIGPIPE, SIG_IGN); revoke_privileges(&proxy_context); if (cert_updater_start(&proxy_context) != 0) { exit(1); } uv_run(event_loop); logger_noformat(&proxy_context, LOG_INFO, "Stopping proxy"); cert_updater_stop(&proxy_context); tcp_listener_stop(&proxy_context); udp_listener_stop(&proxy_context); uv_loop_delete(event_loop); proxy_context_free(&proxy_context); alt_arc4random_close(); return 0; }
/* Destroys a given thread context. This will also free the nursery. * This means that it must no longer be in use, at all; this can be * ensured by a GC run at thread exit that forces evacuation of all * objects from this nursery to the second generation. Only after * that is true should this be called. */ void MVM_tc_destroy(MVMThreadContext *tc) { /* We run once again (non-blocking) to eventually close filehandles. */ uv_run(tc->loop, UV_RUN_NOWAIT); /* Free the nursery. */ free(tc->nursery_fromspace); free(tc->nursery_tospace); /* Destroy the second generation allocator. */ MVM_gc_gen2_destroy(tc->instance, tc->gen2); /* Free the thread-specific storage */ MVM_checked_free_null(tc->gc_work); MVM_checked_free_null(tc->temproots); MVM_checked_free_null(tc->gen2roots); MVM_checked_free_null(tc->frame_pool_table); /* destroy the libuv event loop */ uv_loop_delete(tc->loop); /* Free the thread context itself. */ memset(tc, 0, sizeof(MVMThreadContext)); free(tc); }
int main(int argc, char **argv) { int err = 0; wsn_set_prog_name(wsn_path_file_part(argv[0], 0)); wsn_thread_ctx_t thread_ctx; wsn_err_ctx_t err_ctx; wsn_err_ctx_init(&err_ctx); if (wsn_thread_ctx_key_init() != 0) { printf("WSN error: %s!\n", wsn_last_err_str()); return wsn_last_err(); } wsn_thread_ctx_init(&thread_ctx, &err_ctx); wsn_set_thread_ctx(&thread_ctx); wsn_conf_mgr_t *conf_mgr = wsn_get_conf_mgr(); conf_mgr->init(); wsn_all_configs_t *configs = conf_mgr->get_all_configs(); parse_opts_(configs, argc, argv); if (conf_mgr->load() != 0) { printf("WSN error: %s!\n", wsn_last_err_str()); err = wsn_last_err(); } if (!err) { wsn_server_ctx_t *servers = NULL; wsn_client_ctx_t *clients = NULL; uv_loop_t *loop = uv_default_loop(); if (configs->server_count) { servers = (wsn_server_ctx_t*)malloc(sizeof(*servers) * configs->server_count); if (servers == NULL) { printf("WSN error: Malloc servers failed!\n"); err = WSN_ERR_MALLOC; } else { for (int i = 0; i < configs->server_count; i++) { err = wsn_server_init(&servers[i], &configs->servers_conf[i], loop); if (err) { printf("WSN error: %s!\n", wsn_last_err_str()); break; } err = wsn_server_start(&servers[i]); if (err) { printf("WSN error: %s!\n", wsn_last_err_str()); break; } } } } if (configs->client_count) { clients = (wsn_client_ctx_t*)malloc(sizeof(*clients) * configs->client_count); if (clients == NULL) { printf("WSN error: Malloc clients failed!\n"); err = WSN_ERR_MALLOC; } else { for (int i = 0; i < configs->client_count; i++) { err = wsn_client_init(&clients[i], &configs->clients_conf[i], loop); if (err) { printf("WSN error: %s!\n", wsn_last_err_str()); break; } err = wsn_client_start(&clients[i]); if (err) { printf("WSN error: %s!\n", wsn_last_err_str()); break; } } } } if (!err) { if (uv_run(loop, UV_RUN_DEFAULT) != 0) { err = wsn_last_err(); printf("WSN error: %s!\n", wsn_last_err_str()); } } if (servers) { for (int i = 0; i < configs->server_count; i++) { wsn_server_cleanup(&servers[i]); } free(servers); } if (clients) { for (int i = 0; i < configs->client_count; i++) { wsn_client_cleanup(&clients[i]); } free(clients); } uv_loop_delete(loop); } conf_mgr->cleanup(); wsn_thread_ctx_cleanup(&thread_ctx); free(wsn_prog_name()); return err; }
~rust_uvtmp_thread() { uv_loop_delete(loop); }
static void(loop_free)() { uv_loop_delete(loop); loop = NULL; }
inline ~loop() { uv_loop_delete(l); }
///! /// Destructor /// ~loop() { if(uv_loop_) { uv_loop_delete(uv_loop_); uv_loop_ = nullptr; } }
static void signal_handling_worker(void* context) { uintptr_t mask = (uintptr_t) context; uv_loop_t* loop; uv_signal_t signal1a; uv_signal_t signal1b; uv_signal_t signal2; int r; loop = uv_loop_new(); ASSERT(loop != NULL); /* Setup the signal watchers and start them. */ if (mask & SIGUSR1) { r = uv_signal_init(loop, &signal1a); ASSERT(r == 0); r = uv_signal_start(&signal1a, signal1_cb, SIGUSR1); ASSERT(r == 0); r = uv_signal_init(loop, &signal1b); ASSERT(r == 0); r = uv_signal_start(&signal1b, signal1_cb, SIGUSR1); ASSERT(r == 0); } if (mask & SIGUSR2) { r = uv_signal_init(loop, &signal2); ASSERT(r == 0); r = uv_signal_start(&signal2, signal2_cb, SIGUSR2); ASSERT(r == 0); } /* Signal watchers are now set up. */ uv_sem_post(&sem); /* Wait for all signals. The signal callbacks stop the watcher, so uv_run * will return when all signal watchers caught a signal. */ r = uv_run(loop); ASSERT(r == 0); /* Restart the signal watchers. */ if (mask & SIGUSR1) { r = uv_signal_start(&signal1a, signal1_cb, SIGUSR1); ASSERT(r == 0); r = uv_signal_start(&signal1b, signal1_cb, SIGUSR1); ASSERT(r == 0); } if (mask & SIGUSR2) { r = uv_signal_start(&signal2, signal2_cb, SIGUSR2); ASSERT(r == 0); } /* Wait for signals once more. */ uv_sem_post(&sem); r = uv_run(loop); ASSERT(r == 0); /* Close the watchers. */ if (mask & SIGUSR1) { uv_close((uv_handle_t*) &signal1a, NULL); uv_close((uv_handle_t*) &signal1b, NULL); } if (mask & SIGUSR2) { uv_close((uv_handle_t*) &signal2, NULL); } /* Wait for the signal watchers to close. */ r = uv_run(loop); ASSERT(r == 0); uv_loop_delete(loop); }