本文整理汇总了C++中ev_loop函数的典型用法代码示例。如果您正苦于以下问题:C++ ev_loop函数的具体用法?C++ ev_loop怎么用?C++ ev_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ev_loop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}