static void tcp_handler(struct ns_connection *nc, enum ns_event ev, void *p) { (void) p; switch (ev) { case NS_ACCEPT: call_handler(nc, "onaccept"); break; case NS_RECV: call_handler(nc, "onmessage"); break; case NS_POLL: call_handler(nc, "onpoll"); break; case NS_CLOSE: call_handler(nc, "onclose"); break; default: break; } }
int32_t super_processpacket(msgdisp_t disp,rpacket_t rpk) { uint16_t cmd = rpk_peek_uint16(rpk); if(cmd >= CMD_C2GAME && cmd <= CMD_C2GAME_END) { if(cmd > CMD_C2BATTLE && cmd < CMD_C2BATTLE_END) { //将消息转发到battleservice uint8_t battleserid = reverse_read_uint8(rpk); battleservice_t battle = get_battle_by_index(battleserid); if(battle && 0 == send_msg(NULL,battle->msgdisp,(msg_t)rpk)) return 0;//不销毁rpk,由battleservice负责销毁*/ }else{ ident _ident= reverse_read_ident(rpk); player_t ply = (player_t)cast_2_refbase(_ident); if(ply && ply->_status == normal){ if(super_cmd_handlers[cmd]){ rpk_read_uint16(rpk);//丢弃cmd call_handler(super_cmd_handlers[cmd],rpk,ply); }else{ SYS_LOG(LOG_INFO,"unknow cmd:%d\n",cmd); } } if(ply) ref_decrease((struct refbase*)ply); } } return 1; }
/* rtnl_receive - receive netlink packets from rtnetlink socket */ int rtnl_receive(struct rtnl_handle *rtnl_handle) { int status; char buf[8192]; struct sockaddr_nl nladdr; struct iovec iov = { buf, sizeof(buf) }; struct nlmsghdr *h; struct msghdr msg = { (void *)&nladdr, sizeof(nladdr), &iov, 1, NULL, 0, 0 }; status = recvmsg(rtnl_handle->rtnl_fd, &msg, 0); if (status < 0) { if (errno == EINTR) return 0; rtnl_log(LOG_NOTICE, "OVERRUN on rtnl socket"); return -1; } if (status == 0) { rtnl_log(LOG_ERROR, "EOF on rtnl socket"); return -1; } if (msg.msg_namelen != sizeof(nladdr)) { rtnl_log(LOG_ERROR, "invalid address size"); return -1; } h = (struct nlmsghdr *) buf; while (NLMSG_OK(h, status)) { #if 0 if (h->nlmsg_pid != rtnl_local.nl_pid || h->nlmsg_seq != rtnl_dump) { goto skip; } #endif if (h->nlmsg_type == NLMSG_DONE) { rtnl_log(LOG_NOTICE, "NLMSG_DONE"); return 0; } if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h); if (h->nlmsg_len>=NLMSG_LENGTH(sizeof(struct nlmsgerr))) errno = -err->error; rtnl_log(LOG_ERROR, "NLMSG_ERROR, errnp=%d", errno); return -1; } if (call_handler(rtnl_handle, h->nlmsg_type, h) == 0) rtnl_log(LOG_NOTICE, "unhandled nlmsg_type %u", h->nlmsg_type); h = NLMSG_NEXT(h, status); } return 1; }
/** * Poll all timers in the current thread * * @param tmrl Timer list */ void tmr_poll(struct list *tmrl) { const uint64_t jfs = tmr_jiffies(); for (;;) { struct tmr *tmr; tmr_h *th; void *th_arg; tmr = list_ledata(tmrl->head); if (!tmr || (tmr->jfs > jfs)) { break; } th = tmr->th; th_arg = tmr->arg; tmr->th = NULL; list_unlink(&tmr->le); if (!th) continue; #if TMR_DEBUG call_handler(th, th_arg); #else th(th_arg); #endif } }
static void work_signals (BProcessManager *o) { // read exit status with waitpid() int status; pid_t pid = waitpid(-1, &status, WNOHANG); if (pid <= 0) { return; } // schedule next waitpid BPending_Set(&o->wait_job); // find process BProcess *p = find_process(o, pid); if (!p) { BLog(BLOG_DEBUG, "unknown child %p"); } if (WIFEXITED(status)) { uint8_t exit_status = WEXITSTATUS(status); BLog(BLOG_INFO, "child %"PRIiMAX" exited with status %"PRIu8, (intmax_t)pid, exit_status); if (p) { call_handler(p, 1, exit_status); return; } } else if (WIFSIGNALED(status)) { int signo = WTERMSIG(status); BLog(BLOG_INFO, "child %"PRIiMAX" exited with signal %d", (intmax_t)pid, signo); if (p) { call_handler(p, 0, 0); return; } } else { BLog(BLOG_ERROR, "unknown wait status type for pid %"PRIiMAX" (%d)", (intmax_t)pid, status); } }
void _fusion_call_process( FusionWorld *world, int call_id, FusionCallMessage *msg ) { FusionCallHandler call_handler; FusionCallReturn call_ret; FusionCallHandlerResult result; D_DEBUG_AT( Fusion_Call, "%s()\n", __FUNCTION__ ); D_MAGIC_ASSERT( world, FusionWorld ); D_ASSERT( msg != NULL ); call_handler = msg->handler; D_ASSERT( call_handler != NULL ); D_DEBUG_AT( Fusion_Call, " -> %s\n", direct_trace_lookup_symbol_at( call_handler ) ); call_ret.val = 0; result = call_handler( msg->caller, msg->call_arg, msg->call_ptr, msg->ctx, msg->serial, &call_ret.val ); switch (result) { case FCHR_RETURN: if (msg->serial) { call_ret.serial = msg->serial; call_ret.call_id = call_id; while (ioctl (world->fusion_fd, FUSION_CALL_RETURN, &call_ret)) { switch (errno) { case EINTR: continue; case EIDRM: D_WARN( "caller withdrawn (signal?)" ); return; case EINVAL: D_ERROR( "Fusion/Call: invalid call\n" ); return; default: D_PERROR( "FUSION_CALL_RETURN" ); return; } } } break; case FCHR_RETAIN: break; default: D_BUG( "unknown result %d from call handler", result ); } }
int new_client(t_tmp **newclt) { TCPsocket newsock; NETDEBUG("Un nouveau client s'est connecté\n"); newsock = SDLNet_TCP_Accept(cnt->server.sock); if (!newsock) fprintf(stderr, "accept: %s\n", SDLNet_GetError()); else { put_in_client(newclt, newsock, STATE_NEW); call_handler((*newclt)->c, NULL); return (1); } return (0); }
void body() { const auto thread_id = so_5::query_current_thread_id(); try { for(;;) { auto d = m_queue.pop(); d->call_handler( thread_id ); } } catch( const typename DEMAND_QUEUE::shutdown_ex_t & ) {} }
void parse_commands(xmlDocPtr doc, xmlNodePtr cur) { int res; cur = cur->xmlChildrenNode; while(cur != NULL) { if(strncmp(cur->name, "text", 4) && strncmp(cur->name, "comment", 7)) { res = has_handler((char *)cur->name); if(res == 1) { call_handler((char *)cur->name, doc, cur); } else { llog(LOG_ERR, "There is no handler for %s", (char *)cur->name); } } cur = cur->next; } return; }
/* * This is the clock interrupt handling routine. * You have to call minithread_clock_init with this * function as parameter in minithread_system_initialize */ void clock_handler(void* arg) { interrupt_level_t old_level = set_interrupt_level(DISABLED); nInterrupts++; // get_next_alarm always runs in O(1) alarm_t *next_alarm = get_next_alarm(); while (next_alarm) { call_handler(next_alarm); // since next_alarm is the first element, deregister also runs in O(1) deregister_alarm(next_alarm); next_alarm = get_next_alarm(); } implement_scheduler(); set_interrupt_level(old_level); }
void _fusion_call_process( FusionWorld *world, int call_id, FusionCallMessage *msg ) { FusionCallHandler call_handler; FusionCallHandlerResult result; FusionCallReturn callret; D_MAGIC_ASSERT( world, FusionWorld ); D_ASSERT( msg != NULL ); call_handler = msg->handler; D_ASSERT( call_handler != NULL ); callret.type = FMT_CALLRET; callret.val = 0; result = call_handler( msg->caller, msg->call_arg, msg->call_ptr, msg->ctx, msg->serial, &callret.val ); switch (result) { case FCHR_RETURN: if (!(msg->flags & FCEF_ONEWAY)) { struct sockaddr_un addr; addr.sun_family = AF_UNIX; snprintf( addr.sun_path, sizeof(addr.sun_path), "/tmp/.fusion-%d/call.%x.%x", fusion_world_index( world ), call_id, msg->serial ); if (_fusion_send_message( world->fusion_fd, &callret, sizeof(callret), &addr )) D_ERROR( "Fusion/Call: Couldn't send call return (serial: 0x%08x)!\n", msg->serial ); } break; case FCHR_RETAIN: break; default: D_BUG( "unknown result %d from call handler", result ); break; } }
void handle_event(Event *event) { if (exiting == 1) { exiting = 2; debug(1, "ltrace about to exit"); ltrace_exiting(); } debug(DEBUG_FUNCTION, "handle_event(pid=%d, type=%d)", event->proc ? event->proc->pid : -1, event->type); /* If the thread group or an individual task define an overriding event handler, give them a chance to kick in. We will end up calling both handlers, if the first one doesn't sink the event. */ if (event->proc != NULL) { event = call_handler(event->proc, event); if (event == NULL) /* It was handled. */ return; /* Note: the previous handler has a chance to alter * the event. */ if (event->proc != NULL && event->proc->leader != NULL && event->proc != event->proc->leader) { event = call_handler(event->proc->leader, event); if (event == NULL) return; } } switch (event->type) { case EVENT_NONE: debug(1, "event: none"); return; case EVENT_SIGNAL: debug(1, "event: signal (%s [%d])", shortsignal(event->proc, event->e_un.signum), event->e_un.signum); handle_signal(event); return; case EVENT_EXIT: debug(1, "event: exit (%d)", event->e_un.ret_val); handle_exit(event); return; case EVENT_EXIT_SIGNAL: debug(1, "event: exit signal (%s [%d])", shortsignal(event->proc, event->e_un.signum), event->e_un.signum); handle_exit_signal(event); return; case EVENT_SYSCALL: debug(1, "event: syscall (%s [%d])", sysname(event->proc, event->e_un.sysnum), event->e_un.sysnum); handle_syscall(event); return; case EVENT_SYSRET: debug(1, "event: sysret (%s [%d])", sysname(event->proc, event->e_un.sysnum), event->e_un.sysnum); handle_sysret(event); return; case EVENT_ARCH_SYSCALL: debug(1, "event: arch_syscall (%s [%d])", arch_sysname(event->proc, event->e_un.sysnum), event->e_un.sysnum); handle_arch_syscall(event); return; case EVENT_ARCH_SYSRET: debug(1, "event: arch_sysret (%s [%d])", arch_sysname(event->proc, event->e_un.sysnum), event->e_un.sysnum); handle_arch_sysret(event); return; case EVENT_CLONE: case EVENT_VFORK: debug(1, "event: clone (%u)", event->e_un.newpid); handle_clone(event); return; case EVENT_EXEC: debug(1, "event: exec()"); handle_exec(event); return; case EVENT_BREAKPOINT: debug(1, "event: breakpoint"); handle_breakpoint(event); return; case EVENT_NEW: debug(1, "event: new process"); handle_new(event); return; default: fprintf(stderr, "Error! unknown event?\n"); exit(1); } }
void _fusion_call_process( FusionWorld *world, int call_id, FusionCallMessage *msg, void *ptr ) { FusionCallHandlerResult result = FCHR_RETURN; FusionCallHandler call_handler; FusionCallReturn call_ret = { .val = 0 }; D_DEBUG_AT( Fusion_Call, "%s( call_id %d, msg %p, ptr %p)\n", __FUNCTION__, call_id, msg, ptr ); D_MAGIC_ASSERT( world, FusionWorld ); D_ASSERT( msg != NULL ); D_ASSERT( msg->handler != NULL ); call_handler = msg->handler; if (direct_log_domain_check( &Fusion_Call )) // avoid call to direct_trace_lookup_symbol_at D_DEBUG_AT( Fusion_Call, " -> %s\n", direct_trace_lookup_symbol_at( call_handler ) ); result = call_handler( msg->caller, msg->call_arg, ptr ? ptr : msg->call_ptr, msg->ctx, msg->serial, &call_ret.val ); switch (result) { case FCHR_RETURN: if (msg->serial) { call_ret.serial = msg->serial; call_ret.call_id = call_id; while (ioctl (world->fusion_fd, FUSION_CALL_RETURN, &call_ret)) { switch (errno) { case EINTR: continue; case EIDRM: D_WARN( "caller withdrawn (signal?)" ); return; case EINVAL: D_ERROR( "Fusion/Call: invalid call\n" ); return; default: D_PERROR( "FUSION_CALL_RETURN" ); return; } } } break; case FCHR_RETAIN: break; default: D_BUG( "unknown result %d from call handler", result ); } } void _fusion_call_process3( FusionWorld *world, int call_id, FusionCallMessage3 *msg, void *ptr ) { FusionCallHandlerResult result = FCHR_RETURN; FusionCallHandler3 call_handler; FusionCallReturn3 call_ret; char *ret_ptr = NULL; unsigned int ret_length = 0; D_DEBUG_AT( Fusion_Call, "%s( call_id %d, msg %p, ptr %p)\n", __FUNCTION__, call_id, msg, ptr ); D_MAGIC_ASSERT( world, FusionWorld ); D_ASSERT( msg != NULL ); D_ASSERT( msg->handler != NULL ); call_handler = msg->handler; if (direct_log_domain_check( &Fusion_Call )) // avoid call to direct_trace_lookup_symbol_at D_DEBUG_AT( Fusion_Call, " -> %s\n", direct_trace_lookup_symbol_at( call_handler ) ); if (msg->ret_length > FUSION_CALL_RETURN_DATA_MAX) { D_ERROR( "Fusion/Call: Maximum return data length (%u) exceeded (%u)!\n", FUSION_CALL_RETURN_DATA_MAX, msg->ret_length ); } else { if (msg->ret_length > FUSION_CALL_RETURN_DATA_MAX_ON_STACK) { ret_ptr = D_MALLOC( msg->ret_length ); if (!ret_ptr) D_OOM(); } else ret_ptr = alloca( msg->ret_length ); } if (ret_ptr) result = call_handler( msg->caller, msg->call_arg, ptr ? ptr : msg->call_ptr, msg->call_length, msg->ctx, msg->serial, ret_ptr, msg->ret_length, &ret_length ); switch (result) { case FCHR_RETURN: if (msg->serial) { call_ret.call_id = call_id; call_ret.serial = msg->serial; call_ret.ptr = ret_ptr; call_ret.length = ret_length; while (ioctl (world->fusion_fd, FUSION_CALL_RETURN3, &call_ret)) { switch (errno) { case EINTR: continue; case EIDRM: D_DEBUG_AT( Fusion_Call, " -> caller withdrawn (signal?)\n" ); goto out; case EINVAL: D_ERROR( "Fusion/Call: invalid call\n" ); goto out; default: D_PERROR( "FUSION_CALL_RETURN3" ); goto out; } } } break; case FCHR_RETAIN: break; default: D_BUG( "unknown result %d from call handler", result ); } out: if (msg->ret_length > FUSION_CALL_RETURN_DATA_MAX_ON_STACK) D_FREE( ret_ptr ); }
/* rtnl_receive - receive netlink packets from rtnetlink socket */ int rtnl_receive(struct rtnl_handle *rtnl_handle) { int status; char buf[8192]; struct sockaddr_nl nladdr; struct iovec iov = { buf, sizeof(buf) }; struct nlmsghdr *h; struct msghdr msg = { .msg_name = &nladdr, .msg_namelen = sizeof(nladdr), .msg_iov = &iov, .msg_iovlen = 1, }; status = recvmsg(rtnl_handle->rtnl_fd, &msg, 0); if (status < 0) { if (errno == EINTR) return 0; rtnl_log(LOG_NOTICE, "OVERRUN on rtnl socket"); return -1; } if (status == 0) { rtnl_log(LOG_ERROR, "EOF on rtnl socket"); return -1; } if (msg.msg_namelen != sizeof(nladdr)) { rtnl_log(LOG_ERROR, "invalid address size"); return -1; } h = (struct nlmsghdr *) buf; while (NLMSG_OK(h, status)) { #if 0 if (h->nlmsg_pid != rtnl_local.nl_pid || h->nlmsg_seq != rtnl_dump) { goto skip; } #endif if (h->nlmsg_type == NLMSG_DONE) { rtnl_log(LOG_NOTICE, "NLMSG_DONE"); return 0; } if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = NLMSG_DATA(h); if (h->nlmsg_len>=NLMSG_LENGTH(sizeof(struct nlmsgerr))) errno = -err->error; rtnl_log(LOG_ERROR, "NLMSG_ERROR, errnp=%d", errno); return -1; } if (call_handler(rtnl_handle, h->nlmsg_type, h) == 0) rtnl_log(LOG_NOTICE, "unhandled nlmsg_type %u", h->nlmsg_type); h = NLMSG_NEXT(h, status); } return 1; } int rtnl_receive_multi(struct rtnl_handle *rtnl_handle) { while (1) { if (rtnl_receive(rtnl_handle) <= 0) break; } return 1; } /* rtnl_open - constructor of rtnetlink module */ struct rtnl_handle *rtnl_open(void) { socklen_t addrlen; struct rtnl_handle *h; h = calloc(1, sizeof(struct rtnl_handle)); if (!h) return NULL; addrlen = sizeof(h->rtnl_local); h->rtnl_local.nl_pid = getpid(); h->rtnl_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (h->rtnl_fd < 0) { rtnl_log(LOG_ERROR, "unable to create rtnetlink socket"); goto err; } memset(&h->rtnl_local, 0, sizeof(h->rtnl_local)); h->rtnl_local.nl_family = AF_NETLINK; h->rtnl_local.nl_groups = RTMGRP_LINK; if (bind(h->rtnl_fd, (struct sockaddr *) &h->rtnl_local, addrlen) < 0) { rtnl_log(LOG_ERROR, "unable to bind rtnetlink socket"); goto err_close; } if (getsockname(h->rtnl_fd, (struct sockaddr *) &h->rtnl_local, &addrlen) < 0) { rtnl_log(LOG_ERROR, "cannot gescockname(rtnl_socket)"); goto err_close; } if (addrlen != sizeof(h->rtnl_local)) { rtnl_log(LOG_ERROR, "invalid address size %u", addr_len); goto err_close; } if (h->rtnl_local.nl_family != AF_NETLINK) { rtnl_log(LOG_ERROR, "invalid AF %u", h->rtnl_local.nl_family); goto err_close; } h->rtnl_seq = time(NULL); return h; err_close: close(h->rtnl_fd); err: free(h); return NULL; }
void Button::on_mouse_up(Sint32 mouse_x, Sint32 mouse_y) { m_current_texture = Button_Graphics::DEFAULT; call_handler(Handler_Type::ON_CLICK); }
void Button::on_mouse_down(Sint32 mouse_x, Sint32 mouse_y) { m_current_texture = Button_Graphics::PRESSED_DOWN; call_handler(Handler_Type::ON_MOUSE_DOWN); }
void Button::on_mouse_exit(Sint32 mouse_x, Sint32 mouse_y) { m_current_texture = Button_Graphics::DEFAULT; call_handler(Handler_Type::ON_MOUSE_EXIT); }
void Button::on_mouse_over(Sint32 mouse_x, Sint32 mouse_y) { m_current_texture = Button_Graphics::HOVER_OVER; call_handler(Handler_Type::ON_MOUSE_OVER); }