server: Introduce server_command_task.
authorAndre Noll <maan@systemlinux.org>
Sat, 12 Apr 2008 11:26:14 +0000 (13:26 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 12 Apr 2008 11:26:14 +0000 (13:26 +0200)
It's not a real task yet, but this change is a preparation
in order to convert para_server to the paraslash scheduling
system.

server.c

index e793a9a..caeeba4 100644 (file)
--- a/server.c
+++ b/server.c
@@ -114,7 +114,18 @@ char *user_list_file = NULL;
 static FILE *logfile;
 static int mmd_mutex, mmd_shm_id;
 static int signal_pipe;
-static int listen_fd;
+
+struct server_command_task {
+       /** TCP port on which para_server listens for connections. */
+       int listen_fd;
+       /** Copied from para_server's main function. */
+       int argc;
+       /** Argument vector passed to para_server's main function. */
+       char **argv;
+       /** The command task structure for scheduling. */
+       //struct task task;
+       char dummy;
+};
 
 /**
  * para_server's log function
@@ -275,17 +286,19 @@ err:
        exit(EXIT_FAILURE);
 }
 
-static void init_network(void)
+static void init_command_task(struct server_command_task *sct)
 {
-       int ret = para_listen(AF_UNSPEC, IPPROTO_TCP, conf.port_arg);
+       int ret;
 
+       PARA_NOTICE_LOG("initializing tcp command socket\n");
+       ret = para_listen(AF_UNSPEC, IPPROTO_TCP, conf.port_arg);
        if (ret < 0)
                goto err;
-       listen_fd = ret;
-       ret = mark_fd_nonblocking(listen_fd);
+       sct->listen_fd = ret;
+       ret = mark_fd_nonblocking(sct->listen_fd);
        if (ret < 0)
                goto err;
-       add_close_on_fork_list(listen_fd); /* child doesn't need the listener */
+       add_close_on_fork_list(sct->listen_fd); /* child doesn't need the listener */
        return;
 err:
        PARA_EMERG_LOG("%s\n", para_strerror(-ret));
@@ -376,16 +389,13 @@ static void server_init(int argc, char **argv)
                daemon_init();
        PARA_NOTICE_LOG("initializing audio format handlers\n");
        afh_init();
-       PARA_NOTICE_LOG("initializing virtual streaming system\n");
        mmd->server_pid = getpid();
        setup_signal_handling();
        PARA_NOTICE_LOG("initializing the audio file selector\n");
        init_afs();
+       PARA_NOTICE_LOG("initializing virtual streaming system\n");
        vss_init();
        mmd_lock();
-       /* init network socket */
-       PARA_NOTICE_LOG("initializing tcp command socket\n");
-       init_network();
        PARA_NOTICE_LOG("server init complete\n");
 }
 
@@ -438,20 +448,23 @@ static int server_select(int max_fileno, fd_set *readfds, fd_set *writefds,
        return ret;
 }
 
-static void command_pre_select(int *max_fileno, fd_set *rfds)
+static void command_pre_select(int *max_fileno, fd_set *rfds, char *dummy_ptr)
 {
-       para_fd_set(listen_fd, rfds, max_fileno);
+       struct server_command_task *sct = container_of(dummy_ptr, struct server_command_task, dummy);
+       para_fd_set(sct->listen_fd, rfds, max_fileno);
 }
 
-static void command_post_select(fd_set *rfds)
+static void command_post_select(fd_set *rfds, char *dummy_ptr)
 {
+       struct server_command_task *sct = container_of(dummy_ptr, struct server_command_task, dummy);
+
        int new_fd, ret;
        char *peer_name;
        pid_t child_pid;
 
-       if (!FD_ISSET(listen_fd, rfds))
+       if (!FD_ISSET(sct->listen_fd, rfds))
                return;
-       ret = para_accept(listen_fd, NULL, 0);
+       ret = para_accept(sct->listen_fd, NULL, 0);
        if (ret < 0)
                goto out;
        new_fd = ret;
@@ -500,14 +513,17 @@ int main(int argc, char *argv[])
        int max_fileno, ret;
        fd_set rfds, wfds;
        struct timeval *timeout;
+       struct server_command_task server_command_task_struct;
+
 
        valid_fd_012();
        server_init(argc, argv);
+       init_command_task(&server_command_task_struct);
 repeat:
        FD_ZERO(&rfds);
        FD_ZERO(&wfds);
        max_fileno = -1;
-       command_pre_select(&max_fileno, &rfds);
+       command_pre_select(&max_fileno, &rfds, &server_command_task_struct.dummy);
        para_fd_set(signal_pipe, &rfds, &max_fileno);
        timeout = vss_preselect(&rfds, &wfds, &max_fileno);
        server_select(max_fileno + 1, &rfds, &wfds, timeout);
@@ -544,6 +560,6 @@ genocide:
                        exit(EXIT_FAILURE);
                }
        }
-       command_post_select(&rfds);
+       command_post_select(&rfds, &server_command_task_struct.dummy);
        goto repeat;
 }