Beispiel #1
0
jl_value_t *jl_load(const char *fname, size_t len)
{
    if (jl_current_module->istopmod) {
        jl_printf(JL_STDOUT, "%s\r\n", fname);
#ifdef _OS_WINDOWS_
        uv_run(uv_default_loop(), (uv_run_mode)1);
#endif
    }
    char *fpath = (char*)fname;
    uv_stat_t stbuf;
    if (jl_stat(fpath, (char*)&stbuf) != 0 || (stbuf.st_mode & S_IFMT) != S_IFREG) {
        jl_errorf("could not open file %s", fpath);
    }
    if (jl_start_parsing_file(fpath) != 0) {
        jl_errorf("could not open file %s", fpath);
    }
    jl_value_t *result = jl_parse_eval_all(fpath, len);
    if (fpath != fname) free(fpath);
    return result;
}
Beispiel #2
0
int main() {
    loop = uv_default_loop();

    char *args[3];
    args[0] = "mkdir";
    args[1] = "test-dir";
    args[2] = NULL;

    options.exit_cb = on_exit;
    options.file = "mkdir";
    options.args = args;

    int r;
    if ((r = uv_spawn(loop, &child_req, &options))) {
        fprintf(stderr, "%s\n", uv_strerror(r));
        return 1;
    }

    return uv_run(loop, UV_RUN_DEFAULT);
}
Beispiel #3
0
int main() {
  thread_comm_t comm;
  int r;

  memset(&comm, 0, sizeof(comm));

  r = uv_mutex_init(&comm.mutex);
  assert(r == 0);

  r = uv_async_init(uv_default_loop(), &comm.async, async_cb);
  assert(r == 0);
  comm.async.data = (void*) &comm;

  r = uv_thread_create(&comm.thread, thread_cb, (void*) &comm);
  assert(r == 0);

  uv_run(uv_default_loop(), UV_RUN_DEFAULT);

  return 0;
}
Beispiel #4
0
int main() {
    /* our reference to the default loop */
    uv_loop_t *loop;

    /* a idler of uv_idle_t struct type */
    uv_idle_t idler;

    /* let uv return the default loop */
    loop = uv_default_loop();

    /* initialize a idle handle with the default loop and the reference of our idle type */
    uv_idle_init(loop, &idler);
    /* start executing the idle handler and call the wait_for_a_while callback */
    uv_idle_start(&idler, wait_for_a_while);

    printf("Idling ...\n");

    /* start runing the loop in default mode */
    uv_run(loop, UV_RUN_DEFAULT);
}
Beispiel #5
0
int main()
{
    loop = uv_default_loop();
    uv_tcp_t* socket = (uv_tcp_t*)malloc(sizeof(uv_tcp_t));
    uv_tcp_init(loop, socket);

    uv_connect_t* connect = (uv_connect_t*)malloc(sizeof(uv_connect_t));
	//
    struct sockaddr_in dest;
    uv_ip4_addr("127.0.0.1", 7000, &dest);
    uv_tcp_connect(connect, socket,(struct sockaddr*)&dest, on_connect);
    uv_run(loop, UV_RUN_DEFAULT);

	uv_loop_close(socket);
	uv_loop_close(connect);
	free(socket);
	free(connect);

	return 0;
}
Beispiel #6
0
//ToDo: Server struct for state info?
int main(int argc, char *argv[])
{
	struct sockaddr_in addr;
	uv_loop_t *loop = uv_default_loop();
	uv_ip4_addr("0.0.0.0", 25565, &addr);
	uv_tcp_t server;
	if (uv_tcp_init(loop, &server)) {
		printf("Something has gone terribly wrong\n");
		return -1;
	}
	if (uv_tcp_bind(&server, (struct sockaddr*)&addr, 0)) {
		printf("Something has gone terribly wrong2\n");
		return -1;
	}
	if (uv_listen((uv_stream_t*)&server, SOMAXCONN, server_connect_cb)) {
		printf("Something has gone terribly wrong3\n");
		return -1;
	}
	return uv_run(loop, UV_RUN_DEFAULT);
}
Beispiel #7
0
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;
}
Beispiel #8
0
static int pound_it(int concurrency,
                    const char* type,
                    setup_fn do_setup,
                    connect_fn do_connect,
                    make_connect_fn make_connect,
                    void* arg) {
  double secs;
  int r;
  uint64_t start_time; /* in ns */
  uint64_t end_time;

  loop = uv_default_loop();

  uv_update_time(loop);
  start = uv_now(loop);

  /* Run benchmark for at least five seconds. */
  start_time = uv_hrtime();

  do_setup(concurrency, arg);

  r = do_connect(concurrency, make_connect, arg);
  ASSERT(!r);

  uv_run(loop, UV_RUN_DEFAULT);

  end_time = uv_hrtime();

  /* Number of fractional seconds it took to run the benchmark. */
  secs = (double)(end_time - start_time) / NANOSEC;

  fprintf(stderr, "%s-conn-pound-%d: %.0f accepts/s (%d failed)\n",
          type,
          concurrency,
          closed_streams / secs,
          conns_failed);
  fflush(stderr);

  MAKE_VALGRIND_HAPPY();
  return 0;
}
Beispiel #9
0
int main (int argc, char *argv[])
{
   UNUSED (argc);
   UNUSED (argv);

   uv_loop_t *loop = uv_default_loop ();

#ifdef HF_BASE_APP
   HF::UID::URI *uid = new HF::UID::URI ("hf://base.example.com");
#endif

#ifdef HF_NODE_APP

   if (argc < 2)
   {
      std::cout << "usage : " << argv[0] << " [number]" << std::endl;
      exit (-1);
   }

   std::stringstream ss;
   ss << "hf://node.example.com/" << argv[1];

   HF::UID::URI *uid = new HF::UID::URI (ss.str ());
#endif

   HF::Application::Initialize (transport);
   transport.uid (uid);

   HF::Application::Handle ("?");

   uv_pipe_init (loop, &stdin_pipe, 0);
   uv_pipe_open (&stdin_pipe, 0);

   uv_read_start ((uv_stream_t *) &stdin_pipe, alloc_buffer, read_stdin);

   uv_run (loop, UV_RUN_DEFAULT);

   HF::Application::Save ();

   return 0;
}
Beispiel #10
0
int main(int argc, char **argv)
{
    uv_loop_t *loop = uv_default_loop();
    uv_tcp_t listener;
    struct sockaddr_in sockaddr;
    h2o_hostconf_t *hostconf;
    h2o_pathconf_t *pathconf;
    int r;

    if ((r = uv_tcp_init(loop, &listener)) != 0) {
        fprintf(stderr, "uv_tcp_init:%s\n", uv_strerror(r));
        goto Error;
    }
    uv_ip4_addr("127.0.0.1", 7890, &sockaddr);
    if ((r = uv_tcp_bind(&listener, (struct sockaddr *)&sockaddr, sizeof(sockaddr))) != 0) {
        fprintf(stderr, "uv_tcp_bind:%s\n", uv_strerror(r));
        goto Error;
    }
    if ((r = uv_listen((uv_stream_t *)&listener, 128, on_connect)) != 0) {
        fprintf(stderr, "uv_listen:%s\n", uv_strerror(r));
        goto Error;
    }

    h2o_config_init(&config);
    hostconf = h2o_config_register_host(&config, "default");
    pathconf = h2o_config_register_path(hostconf, "/");
    h2o_create_handler(pathconf, sizeof(h2o_handler_t))->on_req = on_req;

    h2o_context_init(&ctx, loop, &config);

    /* disabled by default: uncomment the block below to use HTTPS instead of HTTP */
    /*
    if (setup_ssl("server.crt", "server.key") != 0)
        goto Error;
    */

    return uv_run(loop, UV_RUN_DEFAULT);

Error:
    return 1;
}
Beispiel #11
0
static void prepare_events(uv_prepare_t *handle)
{
  log_msg("", "--event--");
  if (mainloop()->running)
    return;

  mainloop()->running = true;
  while (1) {
    queue_process_events(eventq(), TIMEOUT);
    queue_process_events(drawq(),  TIMEOUT);

    if (!mainloop_busy()) {
      uv_prepare_stop(handle);
      break;
    }
    else {
      uv_run(eventloop(), UV_RUN_NOWAIT);
    }
  }
  mainloop()->running = false;
}
Beispiel #12
0
int
tun_start(struct tundev *tun) {
    uv_loop_t *loop = uv_default_loop();

    struct tundev_context *ctx = tun->contexts;

    tcp_client_start(ctx, loop);

    uv_poll_init(loop, &ctx->watcher, ctx->tunfd);
    uv_poll_start(&ctx->watcher, UV_READABLE, poll_cb);

#ifndef ANDROID
        signal_install(loop, signal_cb, tun);
#endif

    uv_run(loop, UV_RUN_DEFAULT);
    loop_close(loop);
 

    return 0;
}
Beispiel #13
0
        void UDPClient::send(std::string address, int port, std::string data) {
            if (data.size() > 65000) {
                //std::cerr << "Data size bigger than 65KB" << std::endl;
                lWarnig("Data size bigger than 65KB. dest addr: " + address + " Port: " + std::to_string(port));
            }
            uv_udp_send_t send_req;

            uv_buf_t *bufw = (uv_buf_t *) malloc(sizeof(uv_buf_t));//alocated memory
            bufw->base = (char *) malloc(data.size());//alocated memory

            bufw->len = data.size();
            memcpy(bufw->base, data.c_str(), data.size());
            struct sockaddr *temp = networkUtility::uv_resolveAddress(&loop, address, std::to_string(port));
            uv_udp_send(&send_req, &client, bufw, 1, temp, on_send);
            uv_run(&loop, UV_RUN_DEFAULT);

            free(bufw->base);
            free(bufw);
            free(temp);

        }
int main()
{
    uv_loop_t* loop = malloc(sizeof(uv_loop_t));
    uv_loop_init(loop);

    uv_signal_t sigInt;
    uv_signal_init(loop, &sigInt);
    uv_signal_start(&sigInt, sigIntClbk, SIGINT);

    uv_signal_t sigTstp;
    uv_signal_init(loop, &sigTstp);
    uv_signal_start(&sigTstp, sigTstpClbk, SIGTSTP);

    uv_run(loop, UV_RUN_DEFAULT);

    uv_loop_close(loop);
    free(loop);

    //printf("Out...");
    return 0;
}
Beispiel #15
0
int main(int argc, char **argv)
{
  uv_loop_t *loop = uv_default_loop();
  uv_tcp_t server;
  int e;
  struct sockaddr_in addr;

  uv_tcp_init(loop, &server);
  addr = uv_ip4_addr("0.0.0.0", 4434);

  uv_tcp_bind(&server, addr);
  e = uv_listen((uv_stream_t *)&server, 5, on_connection);
  if (e < 0) {
    fprintf(stderr, "Listen error: %s\n", 
            uv_strerror(uv_last_error(loop)));
    return 1;
  }

  uv_run(loop, UV_RUN_DEFAULT);
  return 0;
}
Beispiel #16
0
/**
   cs_run : start the cspider
**/
int cs_run(cspider_t *cspider) {
  if (cspider->process == NULL) {
    printf("warn : need to init process function(use cs_setopt_process)\n");
    return 0;
  }
  if (cspider->save == NULL) {
    printf("warn : need to init data persistence function(use cs_setopt_save)\n");
    return 0;
  }
  /*
    set the threadpool's size by setenv()
   */
  char threadpool_size[4] = {0};
  snprintf(threadpool_size, sizeof(threadpool_size), "%d", cspider->threadpool_size);
  setenv("UV_THREADPOOL_SIZE", threadpool_size, 1);
  
  uv_prepare_init(cspider->loop, cspider->idler);
  uv_prepare_start(cspider->idler, watcher);
  
  return uv_run(cspider->loop, UV_RUN_DEFAULT);
}
Beispiel #17
0
jl_value_t *jl_load(const char *fname)
{
    if (jl_current_module == jl_base_module) {
        //This deliberatly uses ios, because stdio initialization has been moved to Julia
        jl_printf(JL_STDOUT, "%s\r\n", fname);
#ifdef _OS_WINDOWS_
        uv_run(uv_default_loop(), (uv_run_mode)1);
#endif
    }
    char *fpath = (char*)fname;
    uv_stat_t stbuf;
    if (jl_stat(fpath, (char*)&stbuf) != 0 || (stbuf.st_mode & S_IFMT) != S_IFREG) {
        jl_errorf("could not open file %s", fpath);
    }
    if (jl_start_parsing_file(fpath) != 0) {
        jl_errorf("could not open file %s", fpath);
    }
    jl_value_t *result = jl_parse_eval_all(fpath);
    if (fpath != fname) free(fpath);
    return result;
}
Beispiel #18
0
static MVMObject * socket_accept(MVMThreadContext *tc, MVMOSHandle *h) {
    MVMIOSyncSocketData *data = (MVMIOSyncSocketData *)h->body.data;

    while (!data->accept_server) {
        if (tc->loop != data->ss.handle->loop) {
            MVM_exception_throw_adhoc(tc, "Tried to accept() on a socket from outside its originating thread");
        }
        uv_ref((uv_handle_t *)data->ss.handle);
        MVM_gc_mark_thread_blocked(tc);
        uv_run(tc->loop, UV_RUN_DEFAULT);
        MVM_gc_mark_thread_unblocked(tc);
    }

    /* Check the accept worked out. */
    if (data->accept_status < 0) {
        MVM_exception_throw_adhoc(tc, "Failed to listen: unknown error");
    }
    else {
        uv_tcp_t *client    = MVM_malloc(sizeof(uv_tcp_t));
        uv_stream_t *server = data->accept_server;
        int r;
        uv_tcp_init(tc->loop, client);
        data->accept_server = NULL;
        if ((r = uv_accept(server, (uv_stream_t *)client)) == 0) {
            MVMOSHandle         * const result = (MVMOSHandle *)MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTIO);
            MVMIOSyncSocketData * const data   = MVM_calloc(1, sizeof(MVMIOSyncSocketData));
            data->ss.handle   = (uv_stream_t *)client;
            data->ss.encoding = MVM_encoding_type_utf8;
            MVM_string_decode_stream_sep_default(tc, &(data->ss.sep_spec));
            result->body.ops  = &op_table;
            result->body.data = data;
            return (MVMObject *)result;
        }
        else {
            uv_close((uv_handle_t*)client, NULL);
            MVM_free(client);
            MVM_exception_throw_adhoc(tc, "Failed to accept: %s", uv_strerror(r));
        }
    }
}
Beispiel #19
0
/**
 * shut down uv and cleanup ... and should be the first thing we do when exitting
 * this closes all current connections to uv. if we have multiple instances of the client, that will close their io
 */
void
UVEventLoop::ForceStopAndClose()
{
	DEBUG_OUT("UVEventLoop::~UVEventLoop()");
	StopUVRunner(true, true); // wait till we are definitely out of harms way
	for (auto it : resolvers) {
		it->disposed = true;
	}
	DEBUG_OUT(readers.size() << " readers");
	for (auto it : readers) {
		uv_handle_t *h = (uv_handle_t*)it->client->socket;
		if (uv_is_active(h)) uv_close(h, nullptr);
		it->disposed = true;
	}
	DEBUG_OUT(readers.size() << " writers");
	for (auto it : writers) {
		uv_handle_t *h = (uv_handle_t*)it->client->socket;
		if (uv_is_active(h)) uv_close(h, nullptr);
		it->disposed = true;
	}
	DEBUG_OUT(readers.size() << " closers ");
	for (auto it : closers) {
		uv_handle_t *h = (uv_handle_t*)it->client->socket;
		if (uv_is_active(h)) uv_close(h, nullptr);
		it->disposed = true;
	}
	for (auto it : scheduledTimers) { // won't have been called
		it->disposed = true;
	}
	DEBUG_OUT(readers.size() << " timers ");
	for (auto it : activeTimers) {
		uv_handle_t *h = (uv_handle_t*)&it->timer;
		if (uv_is_active(h)) uv_close(h, nullptr);
	}
	for (auto it : activeWorkers) { // doesn't get closed
		it->disposed = true;
	}
	uv_run(loop, UV_RUN_DEFAULT);
	HandleRunnerQueues(); // do the actual cleanup
}
Beispiel #20
0
int server_run(const char* hostaddr, const int port)	//运行服务
{
  int r;
  struct sockaddr_in addr;

  loop = uv_default_loop();	
  addr = uv_ip4_addr(hostaddr, port);	//创建套接字地址
  r = uv_tcp_init(loop, &tcpServer);	//初始化服务handler创建套接字
  if (r) {
    /* TODO: Error codes */
    fprintf(stderr, "Socket creation error\n");
    return 1;
  }

  r = uv_tcp_bind(&tcpServer, addr);	//绑定套接字地址
  if (r) {
    /* TODO: Error codes */
    fprintf(stderr, "Bind error\n");
    return 1;
  }

  r = uv_listen((uv_stream_t*)&tcpServer, M_SOMAXCONN, on_connection);	//监听端口
  
  if (r) {
    /* TODO: Error codes */
    fprintf(stderr, "Listen error %s\n",
        uv_err_name(uv_last_error(loop)));
    return 1;
  }
  Py_BEGIN_ALLOW_THREADS
  uv_run(loop);
  Py_END_ALLOW_THREADS

#if WANT_SIGINT_HANDLING
//  ev_signal signal_watcher;
//  ev_signal_init(&signal_watcher, ev_signal_on_sigint, SIGINT);
//  ev_signal_start(mainloop, &signal_watcher);
#endif
  return 0;
}
Beispiel #21
0
int main()
{
    uv_loop_t *loop = uv_default_loop();

    int ng = tls_engine_inhale( "server-cert.pem", "server-key.pem", 0);
    assert(ng == 0);

    uv_tls_t *server = (uv_tls_t*)malloc(sizeof *server);
    if(uv_tls_init(loop, server) < 0) {
        free(server);
        server = 0;
        fprintf( stderr, "TLS setup error\n");
        return  -1;
    }

    const int port = 8000;
    struct sockaddr_in bind_addr;
    int r = uv_ip4_addr("0.0.0.0", port, &bind_addr);
    assert(!r);
    r = uv_tcp_bind(&(server->socket_), (struct sockaddr*)&bind_addr, 0);
    if( r ) {
        fprintf( stderr, "bind: %s\n", uv_strerror(r));
    }

    int rv = uv_tls_listen(server, 128, on_connect_cb);
    if( rv ) {
        fprintf( stderr, "listen: %s\n", uv_strerror(rv));
    }
    printf("Listening on %d\n", port);

    uv_run(loop, UV_RUN_DEFAULT);


    tls_engine_stop();
    
    free (server);
    server = 0;

    return 0;
}
Beispiel #22
0
int main() {
    uv_idle_t idler;
    uv_loop_t *loop = uv_default_loop();

    // 初始化 idle handle
    uv_idle_init(loop, &idler);
    // 启用 idle handle 并传入回调
    uv_idle_start(&idler, wait_for_a_while);

    printf("Idling... \n");

    // ==========================================
    // http://docs.libuv.org/en/v1.x/loop.html
    // ==========================================

    // int uv_run(uv_loop_t* loop, uv_run_mode mode)
    // This function runs the event loop. It will act differently depending on the specified mode:

    // UV_RUN_DEFAULT: Runs the event loop until there are no more active and referenced handles or requests.
    // Returns non-zero if uv_stop() was called and there are still active handles or requests. Returns zero in all other cases.
    //
    // UV_RUN_ONCE: Poll for i/o once. Note that this function blocks if there are no pending callbacks.
    // Returns zero when done (no active handles or requests left), or non-zero if more callbacks
    // are expected (meaning you should run the event loop again sometime in the future).
    //
    // UV_RUN_NOWAIT: Poll for i/o once but don’t block if there are no pending callbacks.
    // Returns zero if done (no active handles or requests left), or non-zero if more callbacks
    // are expected (meaning you should run the event loop again sometime in the future).

    // 开始轮询,直到该loop中没有活动的引用
    // 在此例中,当uv_idle_stop(handle)调用后,所有的活动执行完成
    // 此时将会停止loop
    uv_run(loop, UV_RUN_DEFAULT);

    // 关闭轮询
    // Releases all internal loop resources.
    uv_loop_close(loop);

    return 0;
}
Beispiel #23
0
int main(int argc, char *argv[])
{
    if (argc <= 1) {
        fprintf(stderr, "Usage: %s <file1> [file2 ...]\n", argv[0]);
        return 1;
    }

    //const char *command = argv[1];

    for (int i = 1; i < argc; ++i) {
        fprintf(stderr, "Adding watch on %s\n", argv[i]);

        uv_fs_event_t *fs_event = (uv_fs_event_t*)malloc(sizeof(uv_fs_event_t));
        int r = uv_fs_event_init(uv_default_loop(), fs_event);
        assert(r == 0);
        r = uv_fs_event_start(fs_event, OnChange, argv[i], 0);
        assert(r == 0);
    }

    uv_run(uv_default_loop(), UV_RUN_DEFAULT);
    return 0;
}
Beispiel #24
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;
}
Beispiel #25
0
void h2o_context_dispose(h2o_context_t *ctx)
{
    h2o_globalconf_t *config = ctx->globalconf;
    size_t i, j;

    for (i = 0; i != config->hosts.size; ++i) {
        h2o_hostconf_t *hostconf = config->hosts.entries + i;
        for (j = 0; j != hostconf->paths.size; ++j) {
            h2o_pathconf_t *pathconf = hostconf->paths.entries + i;
            on_context_dispose(ctx, pathconf);
        }
    }
    free(ctx->_module_configs);
    h2o_timeout_dispose(ctx->loop, &ctx->zero_timeout);
    h2o_timeout_dispose(ctx->loop, &ctx->http1.req_timeout);
    h2o_timeout_dispose(ctx->loop, &ctx->http2.idle_timeout);

#if H2O_USE_LIBUV
    /* make sure the handles released by h2o_timeout_dispose get freed */
    uv_run(ctx->loop, UV_RUN_NOWAIT);
#endif
}
Beispiel #26
0
static int luv_run(lua_State* L)
{
    int r = 0;
    int args = lua_gettop(L);
    uv_run_mode mode = UV_RUN_DEFAULT;
    assert(args >= 0 && args <= 1);
    if (args == 1)
    {
        const char* smode = luaL_checkstring(L, 1);
        if (strcmp(smode, "once") == 0)
        {
            mode = UV_RUN_ONCE;
        }
        else if (strcmp(smode, "nowait") == 0)
        {
            mode = UV_RUN_NOWAIT;
        }
    }
    r = uv_run(luv_get_loop(L), mode);
    lua_pushinteger(L, r);
    return 1;
}
Beispiel #27
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);
}
Beispiel #28
0
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;
}
Beispiel #29
0
/* stdin is a duplex channel over which a handle is sent.
 * We receive it and send it back where it came from.
 */
int ipc_send_recv_helper(void) {
  int r;

  memset(&ctx, 0, sizeof(ctx));

  r = uv_pipe_init(uv_default_loop(), &ctx.channel, 1);
  ASSERT(r == 0);

  uv_pipe_open(&ctx.channel, 0);
  ASSERT(1 == uv_is_readable((uv_stream_t*)&ctx.channel));
  ASSERT(1 == uv_is_writable((uv_stream_t*)&ctx.channel));
  ASSERT(0 == uv_is_closing((uv_handle_t*)&ctx.channel));

  r = uv_read2_start((uv_stream_t*)&ctx.channel, alloc_cb, read2_cb);
  ASSERT(r == 0);

  r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
  ASSERT(r == 0);

  MAKE_VALGRIND_HAPPY();
  return 0;
}
Beispiel #30
0
int main() {
    loop = uv_default_loop();

    char* args[3];
    args[0] = "sleep";
    args[1] = "100";
    args[2] = NULL;

    options.exit_cb = NULL;
    options.file = "sleep";
    options.args = args;
    options.flags = UV_PROCESS_DETACHED;

    if (uv_spawn(loop, &child_req, options)) {
        fprintf(stderr, "%s\n", uv_strerror(uv_last_error(loop)));
        return 1;
    }
    fprintf(stderr, "Launched sleep with PID %d\n", child_req.pid);
    uv_unref((uv_handle_t*) &child_req);

    return uv_run(loop, UV_RUN_DEFAULT);
}