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
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));
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");
}
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;
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);
exit(EXIT_FAILURE);
}
}
- command_post_select(&rfds);
+ command_post_select(&rfds, &server_command_task_struct.dummy);
goto repeat;
}