• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ev_loop函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ev_loop函数的典型用法代码示例。如果您正苦于以下问题:C++ ev_loop函数的具体用法?C++ ev_loop怎么用?C++ ev_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ev_loop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main() {
    signal(SIGPIPE, SIG_IGN);

    redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
    if (c->err) {
        /* Let *c leak for now... */
        printf("Error: %s\n", c->errstr);
        return 1;
    }

    redisLibevAttach(EV_DEFAULT_ c);
    redisAsyncSetConnectCallback(c,connectCallback);
    redisAsyncSetDisconnectCallback(c,disconnectCallback);

    // redisAsyncCommand(c, getCallback, (char*)"sub", "SUBSCRIBE name");
    new ChatRoom(c, {"79153060652", "79030072726", "79853672651"});
    ev_loop(EV_DEFAULT_ 0);
    return 0;
}
开发者ID:xni,项目名称:LocationStream,代码行数:19,代码来源:chat_manager.cpp


示例2: main

int main(int argc, char* argv[])
{
  int c;

  while( (c = getopt(argc, argv, "hs:r:dp:")) != -1 )
    switch( c ) {
    case 'h':
      usage_msg(stdout);
      exit(0);
      break;
    case 'd':
      cfg_delegated = 1;
      break;
    case 's':
      cfg_tx_size = atoi(optarg);
      break;
    case 'r':
      cfg_rx_size = atoi(optarg);
      break;
    case 'p':
      cfg_port = optarg;
      break;
    case '?':
      usage_err();
      break;
    default:
      TEST(0);
      break;
    }
  argc -= optind;
  argv += optind;
  if( argc != 2 )
    usage_err();
  const char* interface = argv[0];
  const char* server = argv[1];

  struct client_state* cs = calloc(1, sizeof(*cs));
  init(cs, interface, server, cfg_port);
  pthread_t tid;
  TEST( pthread_create(&tid, NULL, alarm_thread, cs) == 0 );
  ev_loop(cs);
  return 0;
}
开发者ID:majek,项目名称:openonload,代码行数:43,代码来源:trader_tcpdirect_ds_efvi.c


示例3: main

int main(int argc, char** argv)
{
    enum uprobe_log_level loglevel = UPROBE_LOG_LEVEL;
    bool upipe_ts = false;
    int opt;
    // parse options
    while ((opt = getopt(argc, argv, "dt")) != -1) {
        switch (opt) {
            case 'd':
                loglevel--;
                break;
            case 't':
                upipe_ts = true;
                break;
            default:
                break;
        }
    }
    if (optind >= argc) {
        printf("Usage: %s [-d] [-t] filename\n", argv[0]);
        exit(-1);
    }

    const char *uri = argv[optind++];

    // upipe env
    struct ev_loop *loop = ev_default_loop(0);
    struct upump_mgr *upump_mgr =
        upump_ev_mgr_alloc(loop, UPUMP_POOL, UPUMP_BLOCKER_POOL);
    assert(upump_mgr != NULL);
    struct upipe_glxplayer *glxplayer = upipe_glxplayer_alloc(loglevel);
    assert(glxplayer != NULL);

    upipe_glxplayer_play(glxplayer, upump_mgr, uri, upipe_ts);
    upump_mgr_release(upump_mgr);

    ev_loop(loop, 0);

    upipe_glxplayer_free(glxplayer);
    ev_default_destroy();

    return 0; 
}
开发者ID:digideskio,项目名称:upipe,代码行数:43,代码来源:glxplay.c


示例4: pthread_mutex_lock

/*
 * Worker thread: main event loop
 */
static void *worker_libev(void *arg) {
    WORK_THREAD *me = arg;


    /* Any per-thread setup can happen here; thread_init() will block until
     * all threads have finished initializing.
     */


    pthread_mutex_lock(&init_lock);
    init_count++;
    pthread_cond_signal(&init_cond);
    pthread_mutex_unlock(&init_lock);


me->thread_id = pthread_self();
    ev_loop(me->loop, 0);
    return NULL;
}
开发者ID:liruiqiu,项目名称:tlpi,代码行数:22,代码来源:server_multi.c


示例5: TRACE

void HttpWorker::run()
{
	state_ = Running;

	// XXX invoke onWorkerSpawned-hook here because we want to ensure this hook is 
	// XXX being invoked from *within* the worker-thread.
	server_.onWorkerSpawn(this);

	TRACE("enter loop");
	ev_loop(loop_, 0);

	TRACE("event loop left. killing remaining connections (%ld).", connections_.size());
	if (!connections_.empty())
		_kill();

	server_.onWorkerUnspawn(this);

	state_ = Inactive;
}
开发者ID:liveck,项目名称:x0,代码行数:19,代码来源:HttpWorker.cpp


示例6: server_run

void server_run(const char* hostaddr, const int port)
{
  struct ev_loop* mainloop = ev_default_loop(0);

  ev_io accept_watcher;
  ev_io_init(&accept_watcher, ev_io_on_request, sockfd, EV_READ);
  ev_io_start(mainloop, &accept_watcher);

#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

  /* This is the program main loop */
  Py_BEGIN_ALLOW_THREADS
  ev_loop(mainloop, 0);
  Py_END_ALLOW_THREADS
}
开发者ID:geekbuntu,项目名称:bjoern,代码行数:19,代码来源:server.c


示例7: main

    int
main(int argc, char **argv)
{
    struct rdns_resolver *resolver_ev;
    struct ev_loop *loop;

    loop = ev_default_loop (0);
    resolver_ev = rdns_resolver_new ();
    rdns_bind_libev (resolver_ev, loop);

    rdns_resolver_add_server (resolver_ev, argv[1], strtoul (argv[2], NULL, 10), 0, 8);

    rdns_resolver_init (resolver_ev);

    rdns_test_a (resolver_ev);
    ev_loop (loop, 0);

    return 0;
}
开发者ID:mengxiang0811,项目名称:librdns,代码行数:19,代码来源:spamhaus.c


示例8: tls_user_main_loop

/**
 * Event loop for a client context.
 *
 * Usage of the loop is the following:
 * - client_injector_signal: send new client socket to the loop. Callback is
 *   client_injector_cb().
 * - client_writer_signal: if a write is needed, ask for removal of client socket.
 *   from the loop and process to write by poping write event from a per-client
 *   message queue. Callback is client_writer_cb().
 * - client_destructor_signal: ask for removal a client socket from the loop. This
 *   is used by the command_mode to trigger disconnection. Callback is
 *   client_destructor_cb().
 * - client_accept_cb(): treat new client. This call back is called by watcher
 *   other server socket.
 * - loop_fini_signal: async signal used to trigger loop end
 *
 */
void tls_user_main_loop(struct tls_user_context_t *context, GMutex * mutex)
{
    ev_io client_watcher;
    ev_timer timer;

    context->loop = ev_loop_new(0);
    /* register injector cb */
    ev_async_init(&context->client_injector_signal, client_injector_cb);
    ev_async_start(context->loop, &context->client_injector_signal);
    context->client_injector_signal.data = context;

    /* register writer cb */
    ev_async_init(&context->client_writer_signal, client_writer_cb);
    ev_async_start(context->loop, &context->client_writer_signal);
    context->client_writer_signal.data = context;

    ev_timer_init (&timer, client_timeout_cb, 0, 0.200);
    ev_timer_start (context->loop, &timer);

    /* register destructor cb */
    ev_async_init(&context->client_destructor_signal, client_destructor_cb);
    ev_async_start(context->loop, &context->client_destructor_signal);
    context->client_destructor_signal.data = context;

    /* register destructor cb */
    ev_async_init(&context->loop_fini_signal, loop_destructor_cb);
    ev_async_start(context->loop, &context->loop_fini_signal);
    context->loop_fini_signal.data = context;

    /* register accept cb */
    fcntl(context->sck_inet,F_SETFL,(fcntl(context->sck_inet,F_GETFL)|O_NONBLOCK));
    ev_io_init(&client_watcher, client_accept_cb, context->sck_inet, EV_READ);
    ev_io_start(context->loop, &client_watcher);
    client_watcher.data = context;

    log_message(INFO, DEBUG_AREA_USER,
                "[+] NuAuth is waiting for client connections.");
    ev_loop(context->loop, 0);

    ev_loop_destroy(context->loop);

    close(context->sck_inet);
}
开发者ID:regit,项目名称:nufw,代码行数:60,代码来源:tls_user.c


示例9: slave_run_cb

const char*
slave_run_cb(void)
{
    struct ev_loop *loop;
    ev_io           io_listen;
    ev_signal       sigint_listen;
    ev_signal       sigterm_listen;

    pthread_mutex_init(&srv.pending_lk, 0);
    pthread_mutex_init(&srv.clients_lk, 0);
    if (!(loop = ev_default_loop(EVFLAG_AUTO)))
        return 1;

    syslog(LOG_INFO, "listening on %s:%hd", inet_ntoa(srv.addr.sin_addr), ntohs(srv.addr.sin_port));
    ev_signal_init(&sigint_listen, &nol_s_ev_sigint, SIGINT);
    ev_signal_init(&sigterm_listen, &nol_s_ev_sigint, SIGTERM);
    ev_io_init(&io_listen, &nol_s_ev_conn_accept, srv.listen_sock, EV_READ);
    ev_io_init(&srv.master_io, &nol_s_ev_master, srv.master_sock, EV_READ);
    ev_async_init(&srv.client_status, &nol_s_ev_client_status);

    /* catch SIGINT so we can close connections and clean up properly */
    ev_signal_start(loop, &sigint_listen);
    ev_signal_start(loop, &sigterm_listen);
    ev_io_start(loop, &io_listen);
    ev_io_start(loop, &srv.master_io);
    ev_async_start(loop, &srv.client_status);

    /** 
     * This loop will listen for new connections and data from
     * the master.
     **/
    ev_loop(loop, 0);
    close(srv.listen_sock);

    ev_default_destroy();
    closelog();
    pthread_mutex_destroy(&srv.pending_lk);
    pthread_mutex_destroy(&srv.clients_lk);

    nol_s_hook_invoke(HOOK_CLEANUP);
    return 0;
}
开发者ID:nicholaides,项目名称:Methanol-Web-Crawler,代码行数:42,代码来源:main.c


示例10: zero_stream

int
zero_stream (struct sockaddr *address, size_t to_write)
{
  int r;

  assert(to_write >= 1024); // should be kind of big at least.
  zero_to_write = to_write;
  got_server_close = 0;
  zero_written = 0;
  zero_read = 0;
  zero_client_closed = 0;

  evcom_server_init(&server);
  server.on_connection = make_echo_connection;
  server.on_close      = common_on_server_close;

  evcom_server_listen(&server, address, 1000);
  evcom_server_attach(EV_DEFAULT_ &server);

  evcom_stream client;
  evcom_stream_init(&client);
  client.on_read    = zero_recv;
  client.on_connect = zero_start;
  client.on_close   = zero_close;
  client.on_timeout = error_out;
  evcom_stream_reset_timeout(&client, ZERO_TIMEOUT);
#if EVCOM_HAVE_GNUTLS
  if (use_tls) anon_tls_client(&client);
#endif
  r = evcom_stream_connect(&client, address);
  assert(r == 0 && "problem connecting");
  evcom_stream_attach(EV_DEFAULT_ &client);

  ev_loop(EV_DEFAULT_ 0);

  assert(got_server_close);
  assert(zero_written == zero_to_write);
  assert(zero_read == zero_to_write);
  assert(zero_client_closed) ;

  return 0;
}
开发者ID:jcaose,项目名称:evcom,代码行数:42,代码来源:test.c


示例11: main

int main() {
  int sd;
  struct sockaddr_in addr;
  int addr_len = sizeof(addr);

  // Create server socket
  if((sd = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) {
    perror("socket error");
    return -1;
  }

  bzero(&addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(PORT_NO);
  addr.sin_addr.s_addr = INADDR_ANY;

  // Bind socket to address
  if (bind(sd, (struct sockaddr*) &addr, sizeof(addr)) != 0) {
    perror("bind error");
  }

  // Start listing on the socket
  if (listen(sd, 2) < 0) {
    perror("listen error");
    return -1;
  }

  // Part inilah yang membedakan socket programming biasa dengan event-based programming
  // Initialize and start a watcher to accepts client requests
  struct ev_loop *loop = ev_default_loop(0);
  struct ev_io w_accept;

  ev_io_init(&w_accept, accept_cb, sd, EV_READ);
  ev_io_start(loop, &w_accept);

  // Start infinite loop
  while (1) {
    ev_loop(loop, 0);
  }

  return 0;
}
开发者ID:willy2706,项目名称:webserver-cpp,代码行数:42,代码来源:server.cpp


示例12: fdevent_libev_poll

static int fdevent_libev_poll(fdevents *ev, int timeout_ms) {
	union {
		struct ev_watcher w;
		struct ev_timer timer;
	} timeout_watcher;

	if (!timeout_ms) timeout_ms = 1;

	ev_init(&timeout_watcher.w, NULL);
	ev_set_cb(&timeout_watcher.timer, timeout_watcher_cb);
	timeout_watcher.timer.repeat = ((ev_tstamp) timeout_ms)/1000.0;
	assert(timeout_watcher.timer.repeat);
	ev_timer_again(ev->libev_loop, &timeout_watcher.timer);

	ev_loop(ev->libev_loop, EVLOOP_ONESHOT);

	ev_timer_stop(ev->libev_loop, &timeout_watcher.timer);

	return 0;
}
开发者ID:Difrex,项目名称:OpenSAN2,代码行数:20,代码来源:fdevent_libev.c


示例13: wait_for_event

static void wait_for_event(void)
{
        size_t i;
        int udp_event_fd;
        ev_io events[config.udp_nserver];

        ev_async_init(&ev_interrupt, libev_interrupt_cb);
        ev_async_start(&ev_interrupt);

        for ( i = 0; i < config.udp_nserver; i++ ) {
                udp_event_fd = udp_server_get_event_fd(config.udp_server[i]);

                ev_io_init(&events[i], libev_udp_cb, udp_event_fd, EV_READ);
                events[i].data = config.udp_server[i];

                ev_io_start(&events[i]);
        }

        ev_loop(0);
}
开发者ID:requiem-forasiem,项目名称:requiem-logeater,代码行数:20,代码来源:requiem-logeater.c


示例14: main

int main(int argc, char **argv) {
    struct ev_loop *loop = ev_default_loop(0);

    int sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    struct sockaddr_in addr;
    bzero(&addr, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(6666);
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    bind(sd, (struct sockaddr *)&addr, sizeof(addr));

    listen(sd, SOMAXCONN);

    struct ev_io w_accept;
    ev_io_init(&w_accept, accept_cb, sd, EV_READ);
    ev_io_start(loop, &w_accept);

    while(1) ev_loop(loop, 0);
}
开发者ID:movb,项目名称:stepic,代码行数:20,代码来源:server_libev.cpp


示例15: ev_loop_new

/** @This starts the source thread.
 *
 * @param _glxplayer pointer to glxplayer structure
 * @return always NULL
 */
static void *upipe_glxplayer_source_thread(void *_glxplayer)
{
    struct upipe_glxplayer *glxplayer = (struct upipe_glxplayer *)_glxplayer;

    struct ev_loop *loop = ev_loop_new(0);
    struct upump_mgr *upump_mgr =
        upump_ev_mgr_alloc(loop, UPUMP_POOL, UPUMP_BLOCKER_POOL);
    upipe_xfer_mgr_attach(glxplayer->src_xfer, upump_mgr);
    uprobe_pthread_upump_mgr_set(glxplayer->uprobe_logger, upump_mgr);
    upump_mgr_release(upump_mgr);

    ev_loop(loop, 0);

    ev_loop_destroy(loop);
    printf("end of source thread\n");
    upipe_mgr_release(glxplayer->dec_xfer);
    pthread_join(glxplayer->dec_thread_id, NULL);

    return NULL;
}
开发者ID:digideskio,项目名称:upipe,代码行数:25,代码来源:glxplay.c


示例16: main

int main(int argc, char **argv)
{
    long flags;
    loop = ev_default_loop(0);
    mgr = upump_ev_mgr_alloc(loop, UPUMP_POOL, UPUMP_BLOCKER_POOL);
    assert(mgr != NULL);

    /* Create a pipe with non-blocking write */
    assert(pipe(pipefd) != -1);
    flags = fcntl(pipefd[1], F_GETFL);
    assert(flags != -1);
    flags |= O_NONBLOCK;
    assert(fcntl(pipefd[1], F_SETFL, flags) != -1);

    /* Create watchers */
    write_idler = upump_alloc_idler(mgr, write_idler_cb, NULL);
    assert(write_idler != NULL);
    write_watcher = upump_alloc_fd_write(mgr, write_watcher_cb, NULL,
                                         pipefd[1]);
    assert(write_watcher != NULL);
    read_timer = upump_alloc_timer(mgr, read_timer_cb, NULL, timeout, 0);
    assert(read_timer != NULL);
    read_watcher = upump_alloc_fd_read(mgr, read_watcher_cb, NULL, pipefd[0]);
    assert(read_watcher != NULL);

    /* Start tests */
    upump_start(write_idler);
    ev_loop(loop, 0);
    assert(bytes_read);
    assert(bytes_read == bytes_written);

    /* Clean up */
    upump_free(write_idler);
    upump_free(write_watcher);
    upump_free(read_timer);
    upump_free(read_watcher);
    upump_mgr_release(mgr);

    ev_default_destroy();
    return 0;
}
开发者ID:marcinklimek,项目名称:upipe,代码行数:41,代码来源:upump_ev_test.c


示例17: server_run

void server_run(ServerInfo* server_info)
{
    struct ev_loop* mainloop = ev_loop_new(0);
    ev_set_userdata(mainloop, server_info);

    ev_io accept_watcher;
    ev_io_init(&accept_watcher, ev_io_on_request, server_info->sockfd, EV_READ);
    ev_io_start(mainloop, &accept_watcher);

#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

    /* This is the program main loop */
    Py_BEGIN_ALLOW_THREADS
    ev_loop(mainloop, 0);
    ev_default_destroy();
    Py_END_ALLOW_THREADS
}
开发者ID:andrewleech,项目名称:bjoern,代码行数:21,代码来源:server.c


示例18: main

int main(void)
{
        int fd = socket(PF_INET, SOCK_STREAM, 0);
        if (fd < 0) {
                printf("socket error. errno:%d\n", errno);
                return -1;
        }

        struct sockaddr_in addr;
        bzero(&addr, sizeof(addr));
        addr.sin_family = AF_INET;
        addr.sin_port = htons(PORT);
        addr.sin_addr.s_addr = INADDR_ANY;

        if (bind(fd, (struct sockaddr*) &addr, sizeof(addr)) != 0) {
                printf("bind error.errno:%d\n",errno);
        }

        if (listen(fd, 10) < 0) {
                printf("listen error\n");
                return -1;
        }

        struct ev_loop *loop = ev_default_loop(0);

        ev_io socket_watcher;
        ev_io_init(&socket_watcher, accept_cb, fd, EV_READ);
        ev_io_start(loop, &socket_watcher);

        ev_timer timeout_watcher;
        ev_timer_init (&timeout_watcher, timeout_cb, 2, 2);
        ev_timer_start (loop, &timeout_watcher);

        while (1) {
                printf("ev_loop...\n") ;
                ev_loop(loop, 0);
        }

        return 0;
}
开发者ID:hurley25,项目名称:Experiment,代码行数:40,代码来源:main.c


示例19: connint

int
connint (struct sockaddr *address)
{
  int r;

  nconnections = 0;
  got_server_close = 0;

  evcom_server_init(&server);
  server.on_connection = connint_on_connection;
  server.on_close = common_on_server_close;

  evcom_server_listen(&server, address, 1000);
  evcom_server_attach(EV_DEFAULT_ &server);

  evcom_stream clients[NCONN];
  int i;
  for (i = 0; i < NCONN; i++) {
    evcom_stream *client = &clients[i];
    evcom_stream_init(client);
    client->on_read    = connint_on_client_read;
    client->on_connect = connint_on_client_connect;
    client->on_close   = connint_on_client_close;
    client->on_timeout = common_on_client_timeout;
    evcom_stream_reset_timeout(client, CONNINT_TIMEOUT);
#if EVCOM_HAVE_GNUTLS
    if (use_tls) anon_tls_client(client);
#endif
    r = evcom_stream_connect(client, address);
    assert(r == 0 && "problem connecting");
    evcom_stream_attach(EV_DEFAULT_ client);
  }

  ev_loop(EV_DEFAULT_ 0);

  assert(nconnections == NCONN);
  assert(got_server_close);

  return 0;
}
开发者ID:jcaose,项目名称:evcom,代码行数:40,代码来源:test.c


示例20: getenv

void *update_ipc(void *data)
{
	char *socket_path = getenv("I3SOCK");
	char *i3_default_sock_path = "/tmp/i3-ipc.sock";

	main_loop = ev_default_loop(0);

	if (socket_path == NULL) {
		ELOG("No Socket Path Specified, default to %s\n", i3_default_sock_path);
		socket_path = i3_default_sock_path;
	}

	if (init_connection(socket_path)) {
		/* We subscribe to the i3-events we need */
		subscribe_events();

		/* Get current workspaces from i3. */
		i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
	}

	ev_loop(main_loop, 0);
}
开发者ID:phnom,项目名称:i3applet,代码行数:22,代码来源:i3_workspace_applet.c



注:本文中的ev_loop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ exp2函数代码示例发布时间:2022-05-30
下一篇:
C++ errno_assert函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap