scheduler_impl_t::scheduler_impl_t() { ev_loop_ = ev_loop_new(0); ev_set_userdata(ev_loop_, this); ev_async_init(&activate_, activate_cb); ev_async_start(ev_loop_, &activate_); ev_async_init(&break_loop_, break_loop_cb); ev_async_start(ev_loop_, &break_loop_); }
void *worker_function(void *arg) { struct sThreadData *tdata = (struct sThreadData *)arg; int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(tdata->args.port); addr.sin_addr.s_addr = inet_addr(tdata->args.ip); bind(sock, (struct sockaddr *) &addr, sizeof(addr)); listen(sock, SOMAXCONN); struct ev_loop *loop = tdata->loop;//ev_loop_new(EVFLAG_NOSIGMASK); struct ev_io w_accept; ev_io_init(&w_accept, accept_cb, sock, EV_READ); ev_io_start(loop, &w_accept); //struct ev_async w_exit; ev_async_init(tdata->async_watcher, exit_cb); ev_async_start(loop, tdata->async_watcher); ev_loop(loop, 0); if (!tdata->args.daemon) printf("ev_loop finished\n"); //ev_loop_destroy(loop); return NULL; }
/* * Internal generic eredis runner for the event loop (write) */ static void _eredis_run( eredis_t *e ) { if (! e->loop) { ev_timer *levt; ev_async *leva; e->loop = ev_loop_new( EVFLAG_AUTO ); /* Connect timer */ levt = &e->connect_timer; ev_timer_init( levt, _eredis_ev_connect_cb, 0., 1. ); levt->data = e; ev_timer_start( e->loop, levt ); /* Async send */ leva = &e->send_async; ev_async_init( leva, _eredis_ev_send_cb ); leva->data = e; ev_async_start( e->loop, leva ); } SET_INRUN(e); if (IS_INTHR(e)) /* Thread mode - release the thread creator */ pthread_mutex_unlock( &(e->async_lock) ); ev_run( e->loop, 0 ); UNSET_INRUN(e); }
spx_private void Sender(EV_P_ ev_async *watcher, int revents){/*{{{*/ ev_async_stop(loop, watcher); struct server_context * ctx = (struct server_context *) watcher->data; if(NULL == ctx){ SpxLog1(g_log, SpxLogError, "Sender ctx is NULL"); return; } err_t err = Sender_WriteResponse(ctx->fd, ctx->response, &ctx->resp_len, &ctx->split_size); if((0 == err)&&(0 == ctx->split_size)){ if(ctx->resp_size == ctx->resp_len){ RequestFinish(ctx); }else{ int remain_size = ctx->resp_size - ctx->resp_len; if(remain_size >= SPLIT_SIZE){ ctx->split_size = SPLIT_SIZE; }else{ ctx->split_size = remain_size; } RegisterAayncWatcher(&ctx->async_watcher, Sender, ctx); ev_async_start(loop, &ctx->async_watcher); ev_async_send(loop, &ctx->async_watcher); return; } }else{ if((EAGAIN == err || EWOULDBLOCK == err || EINTR == err)||(ctx->resp_size > 0)) { ev_once(main_socket_loop, ctx->fd, EV_READ, ctx->timeout, Sender_ReWriteResponse, ctx); return; }else{ SpxLog2(g_log, SpxLogError, err,"Sender Failed"); RequestException(ctx, bad_request); } } }/*}}}*/
shared_ptr<event_async_watcher> events::onAsync(function<void(event_async_watcher*)> callback) { auto e_spec = new_watcher<event_async_watcher>(callback); ev_async_init(&e_spec->watcher, events::async_callback); ev_async_start(this->loop, &e_spec->watcher); async_watchers.push_back(e_spec); return e_spec; }
void ZipFile::Initialize(Handle<Object> target) { constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(ZipFile::New)); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(String::NewSymbol("ZipFile")); // functions NODE_SET_PROTOTYPE_METHOD(constructor, "open", Open); NODE_SET_PROTOTYPE_METHOD(constructor, "read", Read); NODE_SET_PROTOTYPE_METHOD(constructor, "readFileSync", readFileSync); NODE_SET_PROTOTYPE_METHOD(constructor, "close", Close); NODE_SET_PROTOTYPE_METHOD(constructor, "addFile", Add_File); NODE_SET_PROTOTYPE_METHOD(constructor, "replaceFile", Replace_File); NODE_SET_PROTOTYPE_METHOD(constructor, "addDirectory", Add_Directory); NODE_SET_PROTOTYPE_METHOD(constructor, "save", Save); // properties constructor->InstanceTemplate()->SetAccessor(String::NewSymbol("count"), get_prop); constructor->InstanceTemplate()->SetAccessor(String::NewSymbol("names"), get_prop); // Initiate async handler ev_async_init(¬ifier, Save_Callback); ev_async_start(EV_DEFAULT_UC_ ¬ifier); target->Set(String::NewSymbol("ZipFile"),constructor->GetFunction()); }
void request_complete(ebb_request *request) { ebb_connection *connection = (ebb_connection *)request->data; AsyncConnection *connection_data = (AsyncConnection *)connection->data; connection_data->connection = connection; connection_data->request = request; gettimeofday(&connection_data->starttime, nullptr); connection_data->keep_alive_flag = ebb_request_should_keep_alive(request); ev_async_init(&connection_data->ev_write, write_cb); ev_async_start(connection_data->ev_loop, &connection_data->ev_write); // Try to route to appropriate handler based on path const AbstractRequestHandlerFactory *handler_factory; try { handler_factory = Router::route(connection_data->path); } catch (const RouterException &exc) { std::string exception_message(exc.what()); connection_data->respond("Could not route request, std::exception was: \n" + exception_message); return; } std::shared_ptr<Task> task = handler_factory->create(connection_data); task->setPriority(Task::HIGH_PRIORITY); // give RequestParseTask high priority SharedScheduler::getInstance().getScheduler()->schedule(task); connection_data->waiting_for_response = true; }
spx_private void ReciveRequest(EV_P_ ev_async *watcher, int revents){/*{{{*/ ev_async_stop(loop, watcher); struct server_context * ctx = (struct server_context *) watcher->data; if(NULL == ctx){ SpxLog1(g_log, SpxLogError, "ReciveRequest ctx is NULL"); return; } err_t err = ReciveRequest_GetRequest_ReadRequest(ctx->fd, ctx->request, &ctx->req_len); if(0 == err){ RegisterAayncWatcher(&ctx->async_watcher, ParserRequest, ctx); ev_async_start(loop, &ctx->async_watcher); ev_async_send(loop, &ctx->async_watcher); printf("buf:%s\n",ctx->request); return; }else{ if(EAGAIN == err || EWOULDBLOCK == err || EINTR == err) { ev_once(loop, ctx->fd, EV_READ, ctx->timeout, ReciveRequest_GetRequest, ctx); return; }else{ SpxLog2(g_log, SpxLogError, err,"ReciveRequest_GetRequest_ReadRequest Failed"); if( -1 == err) CloseCTX(ctx); else RequestException(ctx, bad_request); return; } } }/*}}}*/
spx_private void ParserRequest(EV_P_ ev_async *watcher, int revents){/*{{{*/ ev_async_stop(loop, watcher); err_t err = 0; struct server_context * ctx = (struct server_context *) watcher->data; if(NULL == ctx){ SpxLog1(g_log, SpxLogError, "ParserRequest ctx is NULL"); return; } printf("\n----------------CLIENT:%d xxxxxxxxxxxxxxxxxx CTX:%d-----------------------\n", ctx->fd, GetCTXCount()); if(NULL != ctx->request){ //msg_print(ctx->request, ctx->req_size); long handle_size = ctx->ServerHandler(ctx->req_size, ctx->request, &ctx->response); if (-1 == handle_size){ RequestException(ctx, bad_request); } else{ ctx->resp_size = handle_size; ctx->life_cycle = SEND_RESPONSE; RegisterAayncWatcher(&ctx->async_watcher,SendResponse, ctx); ev_async_start(loop, &ctx->async_watcher); ev_async_send(loop, &ctx->async_watcher); } } else{ RequestException(ctx, bad_request); } }/*}}}*/
spx_private void SendResponse(EV_P_ ev_async *watcher, int revents){/*{{{*/ ev_async_stop(loop, watcher); err_t err = 0; struct server_context * ctx = (struct server_context *) watcher->data; if(NULL == ctx){ SpxLog1(g_log, SpxLogError, "SendResponse ctx is NULL"); return; } if(NULL != ctx->response){ //headers(ctx->fd, ctx->resp_size); int remain_size = ctx->resp_size - ctx->resp_len; if(remain_size >= SPLIT_SIZE){ ctx->split_size = SPLIT_SIZE; }else{ ctx->split_size = remain_size; } RegisterAayncWatcher(&ctx->async_watcher, Sender, ctx); ev_async_start(loop, &ctx->async_watcher); ev_async_send(loop, &ctx->async_watcher); }else{ RequestException(ctx, bad_request); } }/*}}}*/
int emc_init_server(struct emc_server_context *ctx) { int result; int max_workers; char *emc_data_file; g_thread_init(NULL); max_workers = emc_config_table_get_or_default_int("emc_max_workers", EMC_DEFAULT_MAX_WORKERS); emc_data_file = emc_config_table_get("emc_data_file"); ctx->nuauth_directory = g_tree_new( emc_netmask_order_func ); result = emc_parse_datafile(ctx, emc_data_file); if (result < 0) { return -1; } loop = ev_default_loop(0); result = emc_setup_servers(loop, ctx); if (result < 0) { return -1; } ev_signal_init(&sigint_watcher, sigint_cb, SIGINT); ev_signal_start(loop, &sigint_watcher); ev_signal_init(&sigterm_watcher, sigint_cb, SIGTERM); ev_signal_start(loop, &sigterm_watcher); ev_signal_init(&sigusr1_watcher, sigusr1_cb, SIGUSR1); ev_signal_start(loop, &sigusr1_watcher); ev_async_init(&client_ready_signal, emc_client_ready_cb); ev_async_start(loop, &client_ready_signal); ctx->continue_processing = 1; sigint_watcher.data = ctx; sigterm_watcher.data = ctx; sigusr1_watcher.data = ctx; client_ready_signal.data = ctx; g_thread_pool_set_max_unused_threads( (int)(max_workers/2) ); ctx->pool_tls_handshake = g_thread_pool_new((GFunc)emc_worker_tls_handshake, NULL, max_workers, FALSE, NULL); ctx->pool_reader = g_thread_pool_new((GFunc)emc_worker_reader, NULL, max_workers, FALSE, NULL); ctx->work_queue = g_async_queue_new(); ctx->tls_client_list_mutex = g_mutex_new(); log_printf(DEBUG_LEVEL_DEBUG, "Max: %d", g_thread_pool_get_max_unused_threads()); return 0; }
spx_private void ReciveRequest(EV_P_ ev_async *watcher, int revents){/*{{{*/ ev_async_stop(loop, watcher); struct server_context * ctx = (struct server_context *) watcher->data; if(NULL == ctx){ SpxLog1(g_log, SpxLogError, "ReciveRequest ctx is NULL"); return; } if(READ_HEADER == ctx->life_cycle){ char buf[LOG_HEADER_SIZE] = {0}; size_t len = 0; err_t err = ReciveRequest_GetRequest_ReadRequest(ctx->fd, buf, &len, LOG_HEADER_SIZE); if(0 == err){ log_header_unpack(buf, ctx->header); char * request = (char *) calloc(1, sizeof(char)*ctx->header->req_size); if(NULL == request){ SpxLog2(g_log, SpxLogError, err,"calloc log_header failed"); return; } ctx->req_size = ctx->header->req_size; ctx->request = request; ctx->life_cycle = READ_REQUEST; } else{ if(EAGAIN == err || EWOULDBLOCK == err || EINTR == err) { ev_once(loop, ctx->fd, EV_READ, ctx->timeout, ReciveRequest_GetRequest, ctx); return; } else{ SpxLog2(g_log, SpxLogError, err,"Read header failed"); CloseCTX(ctx); return; } } } if(READ_REQUEST == ctx->life_cycle){ printf("---------------ReadRequest-------------\n"); printf("req_size:%d\n", (int)ctx->req_size); err_t err = ReciveRequest_GetRequest_ReadRequest(ctx->fd, ctx->request, &ctx->req_len, ctx->req_size); printf("read request complete\n" ); if(0 == err){ ctx->life_cycle = PARSE_REQUEST; RegisterAayncWatcher(&ctx->async_watcher, ParserRequest, ctx); ev_async_start(loop, &ctx->async_watcher); ev_async_send(loop, &ctx->async_watcher); return; }else{ if(EAGAIN == err || EWOULDBLOCK == err || EINTR == err) { ev_once(loop, ctx->fd, EV_READ, ctx->timeout, ReciveRequest_GetRequest, ctx); return; }else{ SpxLog2(g_log, SpxLogError, err,"ReciveRequest_GetRequest_ReadRequest Failed"); CloseCTX(ctx); return; } } } }/*}}}*/
int main (int argc, char**argv) { if ( !argv[1] ) { printf("need dir parameter\n"); exit(1); } char * argvp = NULL; argvp = realpath(argv[1], pwd); dp = opendir(pwd); if ( errno ) { printf("%s, %s is not valid directory\n", strerror(errno), pwd); exit(1); } int dfd = dirfd(dp); loop = ev_loop_new (EVBACKEND_KQUEUE); ev_timer_init (&timeout_watcher, timeout_cb, 1, 0.); ev_timer_start (loop, &timeout_watcher); ev_io_init (&dir_watcher, dir_cb, dfd, EV_LIBUV_KQUEUE_HACK); ev_io_start (loop, &dir_watcher); ev_io_init (&cmd_watcher, cmd_cb, 0, EV_READ); ev_io_start (loop, &cmd_watcher); ev_idle_init (&repeat_watcher, repeat); ev_async_init (&ready_watcher, ready); ev_async_start (loop, &ready_watcher); if (eio_init (want_poll, 0)) { abort (); }; ev_run (loop, 0); if ( root ) { free(root); } printf("count: %d\n", (int)freelist_len); /* free all allocated path */ int i; if ( freelist ) { for (i = 0; i < freelist_len; ++i ) { if (freelist[i]) { free(freelist[i]); } } free(freelist); } if ( dp ) { closedir(dp); } return 0; }
static inline void as_ev_init_loop(as_event_loop* event_loop) { as_queue_init(&event_loop->queue, sizeof(void*), AS_EVENT_QUEUE_INITIAL_CAPACITY); ev_async_init(&event_loop->wakeup, as_ev_wakeup); event_loop->wakeup.data = event_loop; ev_async_start(event_loop->loop, &event_loop->wakeup); }
/** * 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); }
void MatchServerTest::RespondRunnableHandle() { // 开始主循环 ev_io_start(mLoop, &mAccept_watcher); ev_set_userdata(mLoop, this); ev_async_init(&mAsync_send_watcher, async_recv_callback); ev_async_start(mLoop, &mAsync_send_watcher); ev_run(mLoop, 0); }
void fsock_thread_init (struct fsock_thread *self) { self->loop = ev_loop_new (0); if (self->loop == NULL) { return; } fsock_mutex_init (&self->sync); fsock_queue_init (&self->jobs); fsock_task_init (&self->stop, 0, NULL, NULL); ev_async_init (&self->job_async, async_routine); ev_async_start (self->loop, &self->job_async); }
void * work(void *p) { signal(SIGPIPE, SIG_IGN); ev_idle idle_watcher; ev_idle_init (&idle_watcher, idle_cb); ev_idle_start(work_loop, &idle_watcher); ev_async_init(&async_watcher, async_cb); ev_async_start(work_loop, &async_watcher); ev_loop(work_loop, 0); return (void *)0; }
/* * this thread operates the select() etc. via libev. */ void *client_event_thread(void *arg) { struct CitContext libev_client_CC; CtdlFillSystemContext(&libev_client_CC, "LibEv Thread"); pthread_setspecific(evConKey, IOLog); EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n"); event_base = ev_default_loop (EVFLAG_AUTO); ev_async_init(&AddJob, QueueEventAddCallback); ev_async_start(event_base, &AddJob); ev_async_init(&ExitEventLoop, EventExitCallback); ev_async_start(event_base, &ExitEventLoop); ev_async_init(&WakeupCurl, WakeupCurlCallback); ev_async_start(event_base, &WakeupCurl); curl_init_connectionpool(); ev_run (event_base, 0); EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n"); ///what todo here? CtdlClearSystemContext(); pthread_mutex_lock(&EventExitQueueMutex); ev_loop_destroy (EV_DEFAULT_UC); event_base = NULL; DeleteHash(&QueueEvents); InboundEventQueue = NULL; DeleteHash(&InboundEventQueues[0]); DeleteHash(&InboundEventQueues[1]); /* citthread_mutex_destroy(&EventQueueMutex); TODO */ evcurl_shutdown(); CtdlDestroyEVCleanupHooks(); pthread_mutex_unlock(&EventExitQueueMutex); EVQShutDown = 1; return(NULL); }
virtual void Run() { ev_async_init(&s_asEvent, as_cb); ev_async_start(s_loop, &s_asEvent); ev_timer tm; tm_cb(s_loop, &tm, 0); Runtime rt(NULL); ev_run(s_loop, 0); }
spx_private void Sender_ReWriteResponse(int revents, void *arg){/*{{{*/ struct server_context *ctx = (struct server_context *) arg; if(NULL == ctx){ SpxLog1(g_log, SpxLogError, "Sender ctx is NULL"); return; } if(EV_ERROR & revents){ SpxLog1(g_log, SpxLogError, "EV_ERROR"); return; } if(EV_TIMEOUT & revents){ if((ctx->resp_retry++) >= RETRY_TIMES){ RequestException(ctx, bad_request); SpxLog1(g_log, SpxLogError, "EV_TIMEOUT"); return; }else{ ev_once(main_socket_loop, ctx->fd, EV_WRITE, ctx->timeout, Sender_ReWriteResponse, ctx); return; } } if(EV_WRITE & revents){ err_t err = Sender_WriteResponse(ctx->fd, ctx->response, &ctx->resp_len, &ctx->split_size); if((0 == err)&&(0 == ctx->split_size)){ if(ctx->resp_size == ctx->resp_len){ RequestFinish(ctx); }else{ int remain_size = ctx->resp_size - ctx->resp_len; if(remain_size >= SPLIT_SIZE){ ctx->split_size = SPLIT_SIZE; }else{ ctx->split_size = remain_size; } RegisterAayncWatcher(&ctx->async_watcher, Sender, ctx); ev_async_start(main_socket_loop, &ctx->async_watcher); ev_async_send(main_socket_loop, &ctx->async_watcher); return; } }else{ if((EAGAIN == err || EWOULDBLOCK == err || EINTR == err)||(ctx->resp_size > 0)) { ev_once(main_socket_loop, ctx->fd, EV_READ, ctx->timeout, Sender_ReWriteResponse, ctx); return; }else{ SpxLog2(g_log, SpxLogError, err,"Sender Failed"); RequestException(ctx, bad_request); } } } }/*}}}*/
int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb) { uv__handle_init(loop, (uv_handle_t*)async, UV_ASYNC); loop->counters.async_init++; ev_async_init(&async->async_watcher, uv__async); async->async_cb = async_cb; /* Note: This does not have symmetry with the other libev wrappers. */ ev_async_start(loop->ev, &async->async_watcher); ev_unref(loop->ev); return 0; }
static void setup_ev_loop (MilterLibevEventLoop *loop) { MilterLibevEventLoopPrivate *priv; priv = MILTER_LIBEV_EVENT_LOOP_GET_PRIVATE(loop); if (priv->ev_loop) { ev_set_userdata(priv->ev_loop, loop); priv->breaker = g_new0(ev_async, 1); ev_async_init(priv->breaker, cb_break); ev_async_start(priv->ev_loop, priv->breaker); } }
manos_data_t * manos_init (struct ev_loop *loop) { manos_data_t *data = malloc (sizeof (manos_data_t)); memset (data, 0, sizeof (manos_data_t)); data->loop = loop; ev_idle_init (&eio_idle_watcher, eio_on_idle); eio_idle_watcher.data = data; ev_async_init (&eio_want_poll_watcher, eio_on_want_poll); ev_async_start (EV_DEFAULT_UC_ &eio_want_poll_watcher); eio_want_poll_watcher.data = data; ev_async_init (&eio_done_poll_watcher, eio_on_done_poll); ev_async_start (EV_DEFAULT_UC_ &eio_done_poll_watcher); eio_done_poll_watcher.data = data; eio_init (eio_want_poll, eio_done_poll); }
/* * this thread operates writing to the message database via libev. */ void *db_event_thread(void *arg) { ev_loop *tmp; struct CitContext libev_msg_CC; pthread_setspecific(evConKey, DBLog); CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread"); EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n"); tmp = event_db = ev_loop_new (EVFLAG_AUTO); ev_async_init(&DBAddJob, DBQueueEventAddCallback); ev_async_start(event_db, &DBAddJob); ev_async_init(&DBExitEventLoop, DBEventExitCallback); ev_async_start(event_db, &DBExitEventLoop); ev_run (event_db, 0); pthread_mutex_lock(&DBEventExitQueueMutex); event_db = NULL; EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n"); DeleteHash(&DBQueueEvents); DBInboundEventQueue = NULL; DeleteHash(&DBInboundEventQueues[0]); DeleteHash(&DBInboundEventQueues[1]); /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */ ev_loop_destroy (tmp); pthread_mutex_unlock(&DBEventExitQueueMutex); return(NULL); }
int uv_async_init(uv_async_t* async, uv_async_cb async_cb) { uv__handle_init((uv_handle_t*)async, UV_ASYNC); uv_counters()->async_init++; ev_async_init(&async->async_watcher, uv__async); async->async_watcher.data = async; async->async_cb = async_cb; /* Note: This does not have symmetry with the other libev wrappers. */ ev_async_start(EV_DEFAULT_UC_ &async->async_watcher); ev_unref(EV_DEFAULT_UC); return 0; }
int uv_async_init(uv_handle_t* handle, uv_async_cb async_cb, uv_close_cb close_cb, void* data) { uv__handle_init(handle, UV_ASYNC, close_cb, data); ev_async_init(&handle->async_watcher, uv__async); handle->async_watcher.data = handle; handle->async_cb = async_cb; /* Note: This does not have symmetry with the other libev wrappers. */ ev_async_start(EV_DEFAULT_UC_ &handle->async_watcher); ev_unref(EV_DEFAULT_UC); return 0; }
liTaskletPool* li_tasklet_pool_new(struct ev_loop *loop, gint threads) { liTaskletPool *pool = g_slice_new0(liTaskletPool); pool->loop = loop; ev_init(&pool->finished_watcher, finished_watcher_cb); pool->finished_watcher.data = pool; ev_async_start(pool->loop, &pool->finished_watcher); ev_unref(pool->loop); pool->finished = g_async_queue_new(); li_tasklet_pool_set_threads(pool, threads); return pool; }
spx_private void Reciver(struct ev_loop *loop, ev_io *watcher, int revents){/*{{{*/ ev_io_stop(loop, watcher); pthread_attr_t attr; pthread_attr_init(&attr); SpxLogDelegate *log = (SpxLogDelegate *) watcher->data; err_t err = 0; while(true){ struct sockaddr_in client_addr; pthread_t tid = 0; unsigned int socket_len = 0; int client_sock = 0; socket_len = sizeof(struct sockaddr_in); client_sock = accept(watcher->fd, (struct sockaddr *) &client_addr, &socket_len); if (0 > client_sock){ if( EWOULDBLOCK == errno || EAGAIN == errno){ break; } break; } if( 0 == client_sock){ break; } if( 0 != (err = spx_set_nb(client_sock))){ SpxLog2(log, SpxLogError, err, "set main client_socket nonblock is fail."); } printf("\n----------------CLIENT:%d START CTX:%d-----------------------\n", client_sock, GetCTXCount()); struct server_context * ctx = CTXPop(); printf("\n----------------CLIENT:%d POP CTX:%d-----------------------\n", client_sock, GetCTXCount()); if(NULL != ctx){ ctx->fd = client_sock; RegisterAayncWatcher(&ctx->async_watcher, ReciveRequest, ctx); ev_async_start(loop, &ctx->async_watcher); ev_async_send(loop, &ctx->async_watcher); } } ev_io_start(loop, watcher); }/*}}}*/
static int wait_connection(server_generic_t **server, size_t nserver) { unsigned int i; ev_async_init(&ev_trigger, ev_trigger_cb); ev_async_start(manager_event_loop, &ev_trigger); for ( i = 0; i < nserver; i++ ) { ev_io_init(&server[i]->evio, connection_cb, server[i]->sock, EV_READ); ev_io_start(manager_event_loop, &server[i]->evio); } while ( continue_processing ) ev_loop(manager_event_loop, 0); return 0; }