Get rid of sender->status.
authorAndre Noll <maan@systemlinux.org>
Sat, 19 Jan 2008 11:57:59 +0000 (12:57 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 19 Jan 2008 11:57:59 +0000 (12:57 +0100)
DRY: For the http and the dccp sender, the status is given by
the value of the listening fd. For the ortp sender, introduce
the new static int sender_status.

dccp_send.c
http_send.c
ortp_send.c
send.h
server.c

index fd0cbf1..0410c8b 100644 (file)
@@ -65,7 +65,7 @@ static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds)
        struct dccp_client *dc;
        int ret;
 
-       if (!FD_ISSET(listen_fd, rfds))
+       if (listen_fd < 0 || !FD_ISSET(listen_fd, rfds))
                return;
        ret = para_accept(listen_fd, NULL, 0);
        if (ret < 0) {
@@ -262,9 +262,6 @@ void dccp_send_init(struct sender *s)
        s->client_cmds[SENDER_DELETE] = NULL;
        self = s;
        ret = dccp_open();
-       if (ret < 0) {
+       if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));
-               s->status = SENDER_OFF;
-       } else
-               s->status = SENDER_ON;
 }
index 7c1ea34..6a4d24d 100644 (file)
@@ -197,6 +197,8 @@ static void http_post_select(fd_set *rfds, fd_set *wfds)
        struct http_client *hc, *tmp;
        const char *err_msg;
 
+       if (server_fd < 0)
+               return;
        list_for_each_entry_safe(hc, tmp, &clients, node) {
                i++;
 //             PARA_DEBUG_LOG("handling client %d: %s\n", i, remote_name(hc->fd));
@@ -314,7 +316,6 @@ static int http_open(int port)
        server_fd = para_listen(AF_UNSPEC, IPPROTO_TCP, port);
        if (server_fd < 0) {
                http_shutdown_clients();
-               self->status = SENDER_OFF;
                return server_fd;
        }
        ret = mark_fd_nonblocking(server_fd);
@@ -322,27 +323,26 @@ static int http_open(int port)
                PARA_EMERG_LOG("%s\n", para_strerror(-ret));
                exit(EXIT_FAILURE);
        }
-       self->status = SENDER_ON;
        add_close_on_fork_list(server_fd);
        return 1;
 }
 
 static int http_com_on(__a_unused struct sender_command_data *scd)
 {
-       if (self->status == SENDER_ON)
+       if (server_fd >= 0)
                return 1;
        return http_open(conf.http_port_arg);
 }
 
 static int http_com_off(__a_unused struct sender_command_data *scd)
 {
-       self->status = SENDER_OFF;
-       if (server_fd > 0) {
-               close(server_fd);
-               del_close_on_fork_list(server_fd);
-               server_fd = -1;
-       }
+       if (server_fd < 0)
+               return 1;
+       PARA_NOTICE_LOG("closing http port %d\n", conf.http_port_arg);
+       close(server_fd);
+       del_close_on_fork_list(server_fd);
        http_shutdown_clients();
+       server_fd = -1;
        return 1;
 }
 
@@ -382,7 +382,7 @@ static char *http_info(void)
                "http maximal number of clients: %d%s\n"
                "http connected clients: %s\n"
                "http access %s list: %s\n",
-               (self->status == SENDER_ON)? "on" : "off",
+               (server_fd >= 0)? "on" : "off",
                conf.http_port_arg,
                numclients,
                conf.http_max_clients_arg,
index 71544f4..6a9d19c 100644 (file)
@@ -46,6 +46,7 @@ struct ortp_target {
 
 static struct list_head targets;
 static struct sender *self;
+static int sender_status;
 
 static void ortp_delete_target(struct ortp_target *ot, const char *msg)
 {
@@ -167,7 +168,7 @@ static void ortp_send(long unsigned current_chunk, long unsigned chunks_sent,
        char *sendbuf, *header_buf = NULL;
        struct timeval *chunk_tv;
 
-       if (self->status != SENDER_ON)
+       if (sender_status != SENDER_ON)
                return;
 
 //     PARA_NOTICE_LOG("sending %lu\n", current_chunk);
@@ -213,14 +214,14 @@ static void ortp_send(long unsigned current_chunk, long unsigned chunks_sent,
 static int ortp_com_on(__a_unused struct sender_command_data *scd)
 {
 
-       self->status = SENDER_ON;
+       sender_status = SENDER_ON;
        return 1;
 }
 
 static int ortp_com_off(__a_unused struct sender_command_data *scd)
 {
        ortp_shutdown_targets();
-       self->status = SENDER_OFF;
+       sender_status = SENDER_OFF;
        return 1;
 }
 
@@ -270,7 +271,7 @@ static char *ortp_info(void)
                "ortp status: %s\n"
                "ortp default port: udp %d\n"
                "ortp targets: %s\n",
-               (self->status == SENDER_ON)? "on" : "off",
+               (sender_status == SENDER_ON)? "on" : "off",
                conf.ortp_default_port_arg,
                tgts? tgts : "(none)"
        );
@@ -341,9 +342,9 @@ void ortp_send_init(struct sender *s)
        s->client_cmds[SENDER_ADD] = ortp_com_add;
        s->client_cmds[SENDER_DELETE] = ortp_com_delete;
        self = s;
-       s->status = SENDER_OFF;
+       sender_status = SENDER_OFF;
        ortp_init_target_list();
        if (!conf.ortp_no_autostart_given)
-               s->status = SENDER_ON;
+               sender_status = SENDER_ON;
        PARA_DEBUG_LOG("%s", "ortp sender init complete\n");
 }
diff --git a/send.h b/send.h
index b0da165..3436bce 100644 (file)
--- a/send.h
+++ b/send.h
@@ -25,8 +25,6 @@ struct sender {
  * this sending facility, for example it could open a tcp port.
  */
        void (*init)(struct sender *s);
-/** \p SENDER_ON or \p SENDER_OFF */
-       int status;
 /**
  * return the help text of this sender
  *
index 8783f8e..f6bc07d 100644 (file)
--- a/server.c
+++ b/server.c
@@ -480,8 +480,6 @@ repeat:
        timeout = vss_preselect(&rfds, &wfds, &max_fileno);
        status_refresh();
        for (i = 0; senders[i].name; i++) {
-               if (senders[i].status != SENDER_ON)
-                       continue;
                if (!senders[i].pre_select)
                        continue;
                senders[i].pre_select(&max_fileno, &rfds, &wfds);
@@ -493,8 +491,6 @@ repeat:
        if (ret < 0)
                goto repeat;
        for (i = 0; senders[i].name; i++) {
-               if (senders[i].status != SENDER_ON)
-                       continue;
                if (!senders[i].post_select)
                        continue;
                senders[i].post_select(&rfds, &wfds);