From: Andre Noll Date: Sat, 19 Jan 2008 11:57:59 +0000 (+0100) Subject: Get rid of sender->status. X-Git-Tag: v0.3.1~84 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=d4171bf0379c24a15df0281c5328c53087e446f4;p=paraslash.git Get rid of sender->status. 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. --- diff --git a/dccp_send.c b/dccp_send.c index fd0cbf12..0410c8bc 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -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; } diff --git a/http_send.c b/http_send.c index 7c1ea344..6a4d24dd 100644 --- a/http_send.c +++ b/http_send.c @@ -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, diff --git a/ortp_send.c b/ortp_send.c index 71544f49..6a9d19c7 100644 --- a/ortp_send.c +++ b/ortp_send.c @@ -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 b0da1652..3436bcea 100644 --- 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 * diff --git a/server.c b/server.c index 8783f8e4..f6bc07d6 100644 --- 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);