コード例 #1
0
ファイル: main.c プロジェクト: F35X70/feng
int main(int argc, char **argv)
{
    if (!g_thread_supported ()) g_thread_init (NULL);

#ifdef HAVE_AVFORMAT
    ffmpeg_init();
#endif

    /* parses the command line and initializes the log*/
    command_environment(argc, argv);

    /* This goes before feng_bind_ports */
    feng_loop = ev_default_loop(0);

    feng_handle_signals();

    g_list_foreach(configured_sockets, feng_bind_socket, NULL);
    accesslog_init(feng_default_vhost, NULL);

    stats_init();

    feng_drop_privs();

    http_tunnel_initialise();

    clients_init();

    ev_loop (feng_loop, 0);

    /* This is explicit to send disconnections! */
    clients_cleanup();

#ifdef CLEANUP_DESTRUCTOR
    ev_loop_destroy(feng_loop);
#endif

    return 0;
}
コード例 #2
0
ファイル: server.c プロジェクト: jonsafari/mocp
/* Handle incoming connections */
void server_loop ()
{
	struct sockaddr_un client_name;
	socklen_t name_len = sizeof (client_name);

	logit ("MOC server started, pid: %d", getpid());

	assert (server_sock != -1);

	log_circular_start ();

	do {
		int res;
		fd_set fds_write, fds_read;

		FD_ZERO (&fds_read);
		FD_ZERO (&fds_write);
		FD_SET (server_sock, &fds_read);
		FD_SET (wake_up_pipe[0], &fds_read);
		add_clients_fds (&fds_read, &fds_write);

		res = 0;
		if (!server_quit)
			res = select (max_fd(server_sock)+1, &fds_read,
					&fds_write, NULL, NULL);

		if (res == -1 && errno != EINTR && !server_quit)
			fatal ("select() failed: %s", xstrerror (errno));

		if (!server_quit && res >= 0) {
			if (FD_ISSET(server_sock, &fds_read)) {
				int client_sock;

				debug ("accept()ing connection...");
				client_sock = accept (server_sock,
					(struct sockaddr *)&client_name,
					&name_len);

				if (client_sock == -1)
					fatal ("accept() failed: %s", xstrerror (errno));
				logit ("Incoming connection");
				if (!add_client(client_sock))
					busy (client_sock);
			}

			if (FD_ISSET(wake_up_pipe[0], &fds_read)) {
				int w;

				logit ("Got 'wake up'");

				if (read(wake_up_pipe[0], &w, sizeof(w)) < 0)
					fatal ("Can't read wake up signal: %s", xstrerror (errno));
			}

			send_events (&fds_write);
			handle_clients (&fds_read);
		}

		if (server_quit)
			logit ("Exiting...");

	} while (!server_quit);

	log_circular_log ();
	log_circular_stop ();

	close_clients ();
	clients_cleanup ();
	close (server_sock);
	server_sock = -1;
	server_shutdown ();
}