예제 #1
0
int jsonrpc_io_child_process(int cmd_pipe)
{
	struct event* pipe_ev = NULL;

	global_ev_base = event_base_new();
	global_evdns_base = evdns_base_new(global_ev_base, 1);

	set_non_blocking(cmd_pipe);
	pipe_ev = event_new(global_ev_base, cmd_pipe,
			EV_READ | EV_PERSIST, cmd_pipe_cb, NULL);

	if(!pipe_ev) {
		ERR("Failed to create pipe event\n");
		return -1;
	}

	if(event_add(pipe_ev, NULL)<0) {
		ERR("Failed to start pipe event\n");
		return -1;
	}

	connect_servers(global_server_group);

#if 0
	/* attach shutdown signal handler */
	/* The shutdown handler are intended to clean up the remaining memory
	 * in the IO process. However, catching the signals causes unpreditable
	 * behavior in the Kamailio shutdown process, so this should be disabled
	 * except when doing memory debugging. */
	struct sigaction sa;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	sa.sa_handler = io_shutdown;
	if(sigaction(SIGTERM, &sa, NULL) == -1) {
		ERR("Failed to attach IO shutdown handler to SIGTERM\n");
	} else if(sigaction(SIGINT, NULL, &sa) == -1) {
		ERR("Failed to attach IO shutdown handler to SIGINT\n");
	}
#endif

	if(event_base_dispatch(global_ev_base)<0) {
		ERR("IO couldn't start event loop\n");
		return -1;
	}
	return 0;
}
예제 #2
0
int jsonrpc_io_child_process(int cmd_pipe, char* _servers)
{
	if (parse_servers(_servers, &server_group) != 0)
	{
		LM_ERR("servers parameter could not be parsed\n");
		return -1;
	}

	event_init();
	
	struct event pipe_ev;
	set_non_blocking(cmd_pipe);
	event_set(&pipe_ev, cmd_pipe, EV_READ | EV_PERSIST, cmd_pipe_cb, &pipe_ev);
	event_add(&pipe_ev, NULL);

	if (!connect_servers(server_group))
	{
		LM_WARN("failed to connect to any servers\n");
	}

	event_dispatch();
	return 0;
}