コード例 #1
0
ファイル: loopdata.cpp プロジェクト: javaos74/opflex
void Peer::LoopData::down() {

    VLOG(3)
        << this
        << " Down() on Loop"
        << " LoopRefCnt: "
        <<       refCount_
        << " -> "
        <<       refCount_ - 1
    ;

    assert(refCount_);

    --refCount_;

    if (destroying_ && !refCount_) {
        LOG(INFO)
            << this
            << " walking uv_loop before stopping it"
        ;
        uv_walk(prepare_.loop, walkAndDumpHandlesCb< DEBUG >, this);

        CloseHandle closeHandle = { this, NULL };

        uv_walk(prepare_.loop, walkAndCloseHandlesCb, &closeHandle);

    }
}
コード例 #2
0
ファイル: node.hpp プロジェクト: Preetam/libab
	// shutdown shuts down the Node's event loop and cleans up resources.
	void
	shutdown()
	{
		uv_async_init(m_uv_loop.get(), &m_async, [](uv_async_t* handle) {
			auto self = (Node*)(handle->data);
			auto timer = self->m_timer.get();
			uv_timer_stop(timer);

			uv_close((uv_handle_t*)timer, [](uv_handle_t* handle) {
				auto self = (Node*)(handle->data);
				auto tcp = self->m_tcp.get();
				auto loop = self->m_uv_loop.get();

				self->m_peer_registry = nullptr;

				uv_close((uv_handle_t*)tcp, [](uv_handle_t* handle) {
					auto self = (Node*)(handle->data);
					auto loop = self->m_uv_loop.get();

					uv_walk(loop, [](uv_handle_t* handle, void* arg) {
						if (uv_is_closing(handle) == 0) {
							uv_close(handle, [](uv_handle_t* h){});
						}
					}, nullptr);
				});
			});
		});
		m_async.data = this;
		uv_async_send(&m_async);
	}
コード例 #3
0
ファイル: libuv.c プロジェクト: LiquidOffice/libwebsockets
void
lws_libuv_destroyloop(struct lws_context *context, int tsi)
{
	struct lws_context_per_thread *pt = &context->pt[tsi];
	int m;

	if (!(context->options & LWS_SERVER_OPTION_LIBUV))
		return;

	if (!pt->io_loop_uv)
		return;

	if (context->use_ev_sigint)
		uv_signal_stop(&pt->w_sigint.uv_watcher);
	for (m = 0; m < ARRAY_SIZE(sigs); m++)
		uv_signal_stop(&pt->signals[m]);
	if (!pt->ev_loop_foreign) {
		uv_stop(pt->io_loop_uv);
		uv_walk(pt->io_loop_uv, lws_uv_walk_cb, NULL);
		while (uv_run(pt->io_loop_uv, UV_RUN_NOWAIT));
		m = uv_loop_close(pt->io_loop_uv);
		if (m == UV_EBUSY)
			lwsl_debug("%s: uv_loop_close: UV_EBUSY\n", __func__);
		lws_free(pt->io_loop_uv);
	}
}
コード例 #4
0
ファイル: loop.cpp プロジェクト: InstantWebP2P/node-android
/*
 * Class:     com_iwebpp_libuvpp_handles_LoopHandle
 * Method:    _close_all
 * Signature: (J)V
 */
extern "C" JNIEXPORT  void JNICALL Java_com_iwebpp_libuvpp_handles_LoopHandle__1close_1all
  (JNIEnv *env, jobject that, jlong ptr) {

  assert(ptr);
  uv_loop_t* loop = reinterpret_cast<uv_loop_t*>(ptr);
  uv_walk(loop, _close_all_cb, NULL);
}
コード例 #5
0
ファイル: EventBase.c プロジェクト: AdUser/cjdns
int EventBase_eventCount(struct EventBase* eventBase)
{
    int eventCount = 0;
    struct EventBase_pvt* ctx = Identity_cast((struct EventBase_pvt*) eventBase);
    uv_walk(ctx->loop, countCallback, &eventCount);
    return eventCount;
}
コード例 #6
0
void TCPClient::closeinl()
{
    if (isclosed_) {
        return;
    }
    StopReconnect();
    uv_walk(&loop_, CloseWalkCB, this);
   LOG(INFO) << "client(" << this << ")close";
}
コード例 #7
0
ファイル: EventServer.cpp プロジェクト: qiqjiao/webcrawl
void EventServer::stop() {
  add_async([this]() {
    CHECK_EQ(std::this_thread::get_id(), thread_id_);
    uv_walk(&uv_loop_, EventServer::uv_walk_cb, nullptr);

    timer_handles_.clear();
    poll_handles_.clear();
    async_handle_ = nullptr;
  });
}
コード例 #8
0
ファイル: luv.c プロジェクト: czanyou/node.lua
static int loop_gc(lua_State *L) {
  uv_loop_t* loop = luv_loop(L);
  // Call uv_close on every active handle
  uv_walk(loop, walk_cb, NULL);
  // Run the event loop until all handles are successfully closed
  while (uv_loop_close(loop)) {
    uv_run(loop, UV_RUN_DEFAULT);
  }
  return 0;
}
コード例 #9
0
void
lws_libuv_destroyloop(struct lws_context *context, int tsi)
{
	struct lws_context_per_thread *pt = &context->pt[tsi];
//	struct lws_context *ctx;
	int m, budget = 100, ns;

	if (!lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV))
		return;

	if (!pt->io_loop_uv)
		return;

	lwsl_notice("%s: closing signals + timers context %p\n", __func__, context);

	if (context->use_ev_sigint) {
		uv_signal_stop(&pt->w_sigint.uv_watcher);

		ns = ARRAY_SIZE(sigs);
		if (lws_check_opt(context->options, LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN))
			ns = 2;

		for (m = 0; m < ns; m++) {
			uv_signal_stop(&pt->signals[m]);
			uv_close((uv_handle_t *)&pt->signals[m], lws_uv_close_cb);
		}
	}

	uv_timer_stop(&pt->uv_timeout_watcher);
	uv_close((uv_handle_t *)&pt->uv_timeout_watcher, lws_uv_close_cb);

	uv_idle_stop(&pt->uv_idle);
	uv_close((uv_handle_t *)&pt->uv_idle, lws_uv_close_cb);

	if (pt->ev_loop_foreign)
		return;

	while (budget-- && uv_run(pt->io_loop_uv, UV_RUN_NOWAIT))
		;

	lwsl_notice("%s: closing all loop handles context %p\n", __func__, context);

	uv_stop(pt->io_loop_uv);

	uv_walk(pt->io_loop_uv, lws_uv_walk_cb, NULL);

	while (uv_run(pt->io_loop_uv, UV_RUN_NOWAIT))
		;
#if UV_VERSION_MAJOR > 0
	m = uv_loop_close(pt->io_loop_uv);
	if (m == UV_EBUSY)
		lwsl_err("%s: uv_loop_close: UV_EBUSY\n", __func__);
#endif
	lws_free(pt->io_loop_uv);
}
コード例 #10
0
ファイル: init.c プロジェクト: bitli/julia
DLLEXPORT void uv_atexit_hook()
{
    uv_loop_t* loop = jl_global_event_loop();
    struct uv_shutdown_queue queue = {NULL, NULL};
    uv_walk(loop, jl_uv_exitcleanup_walk, &queue);
    struct uv_shutdown_queue_item *item = queue.first;
    while (item) {
        uv_handle_t *handle = item->h;
        switch(handle->type) {
            case UV_TTY:
            case UV_UDP:
//#ifndef __WIN32__ // unix only supports shutdown on TCP and NAMED_PIPE
// but uv_shutdown doesn't seem to be particularly reliable, so we'll avoid it in general
                uv_close(handle,NULL);
                break;
//#endif
            case UV_TCP:
            case UV_NAMED_PIPE:
                if (uv_is_writable((uv_stream_t*)handle)) { // uv_shutdown returns an error if not writable
                    uv_shutdown_t *req = malloc(sizeof(uv_shutdown_t));
                    int err = uv_shutdown(req, (uv_stream_t*)handle, jl_shutdown_uv_cb);
                    if (err != 0) { printf("shutdown err: %s\n", uv_strerror(uv_last_error(jl_global_event_loop())));}
                }
                else {
                    uv_close(handle,NULL);
                }
                break;
            case UV_POLL:
            case UV_TIMER:
            case UV_PREPARE:
            case UV_CHECK:
            case UV_IDLE:
            case UV_ASYNC:
            case UV_SIGNAL:
            case UV_PROCESS:
            case UV_FS_EVENT:
            case UV_FS_POLL:
                uv_close(handle,NULL); //do we want to use jl_close_uv?
                break;
            case UV_HANDLE:
            case UV_STREAM:
            case UV_UNKNOWN_HANDLE:
            case UV_HANDLE_TYPE_MAX:
            case UV_RAW_FD:
            case UV_RAW_HANDLE:
            default:
                assert(0);
        }
        item = item->next;
    }
    uv_run(loop); //let libuv spin until everything has finished closing
}
コード例 #11
0
ファイル: iotjs.cpp プロジェクト: 2bright/iotjs
int Start(int argc, char** argv) {
  // Initialize debug print.
  InitDebugSettings();

  // Create environtment.
  Environment* env = Environment::GetEnv();

  // Parse command line arguemnts.
  if (!env->ParseCommandLineArgument(argc, argv)) {
    DLOG("ParseCommandLineArgument failed");
    return 1;
  }

  // Set event loop.
  env->set_loop(uv_default_loop());

  // Initalize JerryScript engine.
  if (!InitJerry(env)) {
    DLOG("InitJerry failed");
    return 1;
  }

  // Start IoT.js
  if (!StartIoTjs(env)) {
    DLOG("StartIoTJs failed");
    return 1;
  }

  // close uv loop.
  //uv_stop(env->loop());
  uv_walk(env->loop(), UvWalkToCloseCallback, NULL);
  uv_run(env->loop(), UV_RUN_DEFAULT);

  int res = uv_loop_close(env->loop());
  IOTJS_ASSERT(res == 0);

  // Release JerryScript engine.
  ReleaseJerry();

  // Release environment.
  Environment::Release();

  // Release debug print setting.
  ReleaseDebugSettings();

  return 0;
}
コード例 #12
0
ファイル: memory.cpp プロジェクト: xaccc/libsourcey
void GarbageCollector::runAsync()
{
	std::vector<ScopedPointer*> deletable;
	{
		Mutex::ScopedLock lock(_mutex);		
		if (!_tid) { _tid = uv_thread_self(); }	
		if (!_ready.empty() || !_pending.empty()) {
			TraceL << "Deleting: "
				<< "\n\tReady: " << _ready.size() 
				<< "\n\tPending: " << _pending.size()
				<< "\n\tFinalize: " << _finalize
				<< std::endl;

			// Delete waiting pointers
			deletable = _ready;
			_ready.clear();

			// Swap pending pointers to the ready queue
			_ready.swap(_pending);
		}
	}	
	
	// Delete pointers
	util::clearVector(deletable);
	
	// Handle finalization
	if (_finalize) {
		Mutex::ScopedLock lock(_mutex);
		if (_ready.empty() && _pending.empty()) {
			// Stop and close the timer handle.
			// This should cause the loop to return after 
			// uv_close has been called on the timer handle.
			uv_timer_stop(_handle.ptr<uv_timer_t>());
			//_handle.close();
	
			TraceL << "Finalization complete: " << _handle.loop()->active_handles << std::endl;

#ifdef _DEBUG
			// Print active handles, there should only be 1 left
			uv_walk(_handle.loop(), onPrintHandle, nullptr);
			//assert(_handle.loop()->active_handles <= 1); 
#endif
		}
	}
}
コード例 #13
0
ファイル: tty-test.c プロジェクト: ZyX-I/neovim
static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
{
  if (cnt <= 0) {
    uv_read_stop(stream);
    return;
  }

  int *interrupted = stream->data;

  for (int i = 0; i < cnt; i++) {
    if (buf->base[i] == CTRL_C) {
      (*interrupted)++;
    }
  }

  uv_loop_t write_loop;
  uv_loop_init(&write_loop);
  uv_tty_t out;
  uv_tty_init(&write_loop, &out, fileno(stdout), 0);

  uv_write_t req;
  uv_buf_t b = {
    .base = buf->base,
#ifdef WIN32
    .len = (ULONG)cnt
#else
    .len = (size_t)cnt
#endif
  };
  uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL);
  uv_run(&write_loop, UV_RUN_DEFAULT);

  uv_close(STRUCT_CAST(uv_handle_t, &out), NULL);
  uv_run(&write_loop, UV_RUN_DEFAULT);
  if (uv_loop_close(&write_loop)) {
    abort();
  }
  free(buf->base);

  if (*interrupted >= 2) {
    uv_walk(uv_default_loop(), walk_cb, NULL);
  } else if (*interrupted == 1) {
    fprintf(stderr, "interrupt received, press again to exit\n");
  }
}
コード例 #14
0
static int walk_final(void* vparam) {
  walk_param_t* param = (walk_param_t*)vparam;

  TUV_ASSERT(seen_timer_handle == 1);
  /* Loop is finished, walk_cb should not see our timer handle. */
  seen_timer_handle = 0;
  uv_walk(param->loop, walk_cb, magic_cookie);
  TUV_ASSERT(seen_timer_handle == 0);
  TUV_ASSERT(0 == uv_loop_close(param->loop));

  // cleanup tuv param
  free(param);

  // jump to next test
  run_tests_continue();

  return 0;
}
コード例 #15
0
ファイル: loop.cpp プロジェクト: InstantWebP2P/node-android
/*
 * Class:     com_iwebpp_libuvpp_handles_LoopHandle
 * Method:    _list
 * Signature: (J)[Ljava/lang/String
 */
extern "C" JNIEXPORT  jobjectArray JNICALL Java_com_iwebpp_libuvpp_handles_LoopHandle__1list
  (JNIEnv *env, jobject that, jlong ptr) {

  assert(ptr);
  assert(_string_cid);
  uv_loop_t* loop = reinterpret_cast<uv_loop_t*>(ptr);
  std::vector<const char*> bag;
  uv_walk(loop, _list_cb, &bag);
  jsize size = static_cast<jsize>(bag.size());
  jobjectArray handles = env->NewObjectArray(size, _string_cid, 0);
  OOMN(env, handles);
  for (int i=0; i < size; i++) {
    jstring s = env->NewStringUTF(bag[i]);
    OOMN(env, s);
    env->SetObjectArrayElement(handles, i, s);
    env->DeleteLocalRef(s);
  }
  return handles;
}
コード例 #16
0
ファイル: application.cpp プロジェクト: runt18/libsourcey
void Application::finalize() 
{ 
    DebugLS(this) << "Finalizing" << std::endl;

#ifdef _DEBUG
    // Print active handles
    uv_walk(loop, Application::onPrintHandle, nullptr);
#endif
            
    // Shutdown the garbage collector to free memory
    GarbageCollector::destroy();

    // Run until handles are closed
    run();     
    assert(loop->active_handles == 0);
    //assert(loop->active_reqs == 0);

    DebugLS(this) << "Finalization complete" << std::endl;
}        
コード例 #17
0
ファイル: iotjs.cpp プロジェクト: bozzmob/iotjs
int Start(int argc, char** argv) {
  InitDebugSettings();

  // Initalize JerryScript engine.
  if (!InitJerry()) {
    DLOG("InitJerry failed");
    return 1;
  }

  // Create environtment.
  Environment* env = Environment::GetEnv();

  // Init environment with argument and uv loop.
  env->Init(argc, argv, uv_default_loop());

  // Start IoT.js
  if (!StartIoTjs(env)) {
    DLOG("StartIoTJs failed");
    return 1;
  }

  // close uv loop.
  //uv_stop(env->loop());
  uv_walk(env->loop(), UvWalkToCloseCallback, NULL);
  uv_run(env->loop(), UV_RUN_DEFAULT);

  int res = uv_loop_close(env->loop());
  IOTJS_ASSERT(res == 0);

  // Release JerryScript engine.
  ReleaseJerry();

  ReleaseDebugSettings();

  return 0;
}
コード例 #18
0
ファイル: xsocks.c プロジェクト: WisdomKwan/xsocks
void
close_loop(uv_loop_t *loop) {
    uv_walk(loop, close_walk_cb, NULL);
    uv_run(loop, UV_RUN_DEFAULT);
    uv_loop_close(loop);
}
コード例 #19
0
ファイル: init.c プロジェクト: aylusltd/julia
DLLEXPORT void uv_atexit_hook()
{
#if defined(JL_GC_MARKSWEEP) && defined(GC_FINAL_STATS)
    jl_print_gc_stats(JL_STDERR);
#endif
    if (jl_base_module) {
        jl_value_t *f = jl_get_global(jl_base_module, jl_symbol("_atexit"));
        if (f!=NULL && jl_is_function(f)) {
            jl_apply((jl_function_t*)f, NULL, 0);
        }
    }
    uv_loop_t* loop = jl_global_event_loop();
    struct uv_shutdown_queue queue = {NULL, NULL};
    uv_walk(loop, jl_uv_exitcleanup_walk, &queue);
    // close stdout and stderr last, since we like being
    // able to show stuff (incl. printf's)
    jl_uv_exitcleanup_add((uv_handle_t*)jl_uv_stdout, &queue);
    jl_uv_exitcleanup_add((uv_handle_t*)jl_uv_stderr, &queue);
    struct uv_shutdown_queue_item *item = queue.first;
    while (item) {
        uv_handle_t *handle = item->h;
        if (uv_is_closing(handle)) {
            item = item->next;
            continue;
        }
        switch(handle->type) {
        case UV_TTY:
        case UV_UDP:
//#ifndef __WIN32__ // unix only supports shutdown on TCP and NAMED_PIPE
// but uv_shutdown doesn't seem to be particularly reliable, so we'll avoid it in general
            jl_close_uv(handle);
            break;
//#endif
        case UV_TCP:
        case UV_NAMED_PIPE:
            if (uv_is_writable((uv_stream_t*)handle)) { // uv_shutdown returns an error if not writable
                uv_shutdown_t *req = malloc(sizeof(uv_shutdown_t));
                int err = uv_shutdown(req, (uv_stream_t*)handle, jl_shutdown_uv_cb);
                if (err != 0) {
                    printf("shutdown err: %s\n", uv_strerror(uv_last_error(jl_global_event_loop())));
                    jl_close_uv(handle);
                }
            }
            else {
                jl_close_uv(handle);
            }
            break;
        case UV_POLL:
        case UV_TIMER:
        case UV_PREPARE:
        case UV_CHECK:
        case UV_IDLE:
        case UV_ASYNC:
        case UV_SIGNAL:
        case UV_PROCESS:
        case UV_FS_EVENT:
        case UV_FS_POLL:
            jl_close_uv(handle);
            break;
        case UV_HANDLE:
        case UV_STREAM:
        case UV_UNKNOWN_HANDLE:
        case UV_HANDLE_TYPE_MAX:
        case UV_RAW_FD:
        case UV_RAW_HANDLE:
        default:
            assert(0);
        }
        item = item->next;
    }
    uv_run(loop,UV_RUN_DEFAULT); //let libuv spin until everything has finished closing
}
コード例 #20
0
ファイル: tun_client.c プロジェクト: yusitek/xTun
static void
loop_close(uv_loop_t *loop) {
    uv_walk(loop, walk_close_cb, NULL);
    uv_run(loop, UV_RUN_DEFAULT);
    uv_loop_close(loop);
}
コード例 #21
0
ファイル: libuv.c プロジェクト: PKRoma/libwebsockets
LWS_VISIBLE void
lws_close_all_handles_in_loop(uv_loop_t *loop)
{
	uv_walk(loop, lws_uv_walk_cb, NULL);
}
コード例 #22
0
ファイル: rust_uv.cpp プロジェクト: devmario/rust
extern "C" void
rust_uv_walk(uv_loop_t* loop, uv_walk_cb cb, void* arg) {
    uv_walk(loop, cb, arg);
}
コード例 #23
0
ファイル: init.c プロジェクト: GeorgeSalt/julia
DLLEXPORT void uv_atexit_hook()
{
#if defined(JL_GC_MARKSWEEP) && defined(GC_FINAL_STATS)
    jl_print_gc_stats(JL_STDERR);
#endif
    if (jl_base_module) {
        jl_value_t *f = jl_get_global(jl_base_module, jl_symbol("_atexit"));
        if (f!=NULL && jl_is_function(f)) {
            jl_apply((jl_function_t*)f, NULL, 0);
        }
    }
    uv_loop_t* loop = jl_global_event_loop();
    struct uv_shutdown_queue queue = {NULL, NULL};
    uv_walk(loop, jl_uv_exitcleanup_walk, &queue);
    // close stdout and stderr last, since we like being
    // able to show stuff (incl. printf's)
    jl_uv_exitcleanup_add((uv_handle_t*)jl_uv_stdout, &queue);
    jl_uv_exitcleanup_add((uv_handle_t*)jl_uv_stderr, &queue);
    struct uv_shutdown_queue_item *item = queue.first;
    while (item) {
        uv_handle_t *handle = item->h;
        if (uv_is_closing(handle)) {
            item = item->next;
            continue;
        }
        switch(handle->type) {
        case UV_TTY:
        case UV_UDP:
//#ifndef _OS_WINDOWS_ // unix only supports shutdown on TCP and NAMED_PIPE
// but uv_shutdown doesn't seem to be particularly reliable, so we'll avoid it in general
            jl_close_uv(handle);
            break;
//#endif
        case UV_TCP:
        case UV_NAMED_PIPE:
            // These will be shut down in jl_close_uv.
            jl_close_uv(handle);
            break;
        //Don't close these directly, but rather let the GC take care of it
        case UV_POLL:
            uv_poll_stop((uv_poll_t*)handle);
            handle->data = NULL;
            uv_unref(handle);
            break;
        case UV_TIMER:
            uv_timer_stop((uv_timer_t*)handle);
            handle->data = NULL;
            uv_unref(handle);
            break;
        case UV_IDLE:
            uv_idle_stop((uv_idle_t*)handle);
        case UV_ASYNC:
            handle->data = NULL;
            uv_unref(handle);
            break;
        case UV_FS_EVENT:
            handle->data = NULL;
            uv_unref(handle);
            break;
        case UV_FS_POLL:
            uv_fs_poll_stop((uv_fs_poll_t*)handle);
            handle->data = NULL;
            uv_unref(handle);
            break;
        case UV_PREPARE:
        case UV_CHECK:
        case UV_SIGNAL:
        case UV_PROCESS:
            jl_close_uv(handle);
            break;
        case UV_HANDLE:
        case UV_STREAM:
        case UV_UNKNOWN_HANDLE:
        case UV_HANDLE_TYPE_MAX:
        case UV_RAW_FD:
        case UV_RAW_HANDLE:
        default:
            assert(0);
        }
        item = item->next;
    }
    uv_run(loop,UV_RUN_DEFAULT); //let libuv spin until everything has finished closing
}
コード例 #24
0
static void timer_cb(uv_timer_t* handle) {
  TUV_ASSERT(handle == &timer);

  uv_walk(handle->loop, walk_cb, magic_cookie);
  uv_close((uv_handle_t*)handle, NULL);
}
コード例 #25
0
ファイル: gc.c プロジェクト: wlbksy/julia
static void gc_mark_uv_state(uv_loop_t *loop)
{
    uv_walk(loop,gc_mark_uv_handle,0);
}