X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=dccp_send.c;h=d66b800fb032525b26f02ff8fc5e58e7087f7adb;hp=c68f5777676eff08a4a5a2e5afc59b695ea93ead;hb=2ef1e962280493eee9092da3122760805b793112;hpb=2abba90245f87fab096edfc3faf7df61646b713f diff --git a/dccp_send.c b/dccp_send.c index c68f5777..d66b800f 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -4,7 +4,7 @@ * Licensed under the GPL v2. For licencing details see COPYING. */ -/** \file dccp_send.c paraslash's dccp sender */ +/** \file dccp_send.c Paraslash's dccp sender. */ /* * based on server.c of dccp-cs-0.01.tar.bz2, @@ -28,60 +28,38 @@ #include "close_on_fork.h" #include "chunk_queue.h" #include "server.cmdline.h" - -/** the list of connected clients **/ -static struct list_head clients; -static int listen_fd = -1; - -/** Maximal number of bytes in a chunk queue. */ -#define DCCP_MAX_PENDING_BYTES 40000 +#include "acl.h" /** Do not write more than that many bytes at once. */ #define DCCP_MAX_BYTES_PER_WRITE 1024 +static struct sender_status dccp_sender_status, *dss = &dccp_sender_status; + static void dccp_pre_select(int *max_fileno, fd_set *rfds, __a_unused fd_set *wfds) { - if (listen_fd >= 0) - para_fd_set(listen_fd, rfds, max_fileno); + if (dss->listen_fd >= 0) + para_fd_set(dss->listen_fd, rfds, max_fileno); } static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds) { struct sender_client *sc; - int ret, fd; - if (listen_fd < 0 || !FD_ISSET(listen_fd, rfds)) + if (dss->listen_fd < 0 || !FD_ISSET(dss->listen_fd, rfds)) return; - ret = para_accept(listen_fd, NULL, 0); - if (ret < 0) { - PARA_ERROR_LOG("%s\n", para_strerror(-ret)); + sc = accept_sender_client(dss); + if (!sc) return; - } - fd = ret; /* * Bypass unused CCID paths: the sender does not receive application data * from the client; by shutting down this unused communication path we can * reduce processing costs a bit. See analogous comment in dccp_recv.c. */ - if (shutdown(fd, SHUT_RD) < 0) { - ret = -ERRNO_TO_PARA_ERROR(errno); - goto err; - } - ret = mark_fd_nonblocking(fd); - if (ret < 0) - goto err; - sc = para_calloc(sizeof(*sc)); - sc->fd = fd; - sc->name = make_message("%s", remote_name(sc->fd)); - PARA_NOTICE_LOG("connection from %s\n", sc->name); - para_list_add(&sc->node, &clients); - add_close_on_fork_list(sc->fd); - sc->cq = cq_new(DCCP_MAX_PENDING_BYTES); - return; -err: - PARA_ERROR_LOG("%s\n", para_strerror(-ret)); - close(fd); + if (shutdown(sc->fd, SHUT_RD) >= 0) + return; + PARA_WARNING_LOG("%s\n", strerror(errno)); + shutdown_client(sc, dss); } static void dccp_send(long unsigned current_chunk, @@ -89,35 +67,43 @@ static void dccp_send(long unsigned current_chunk, { struct sender_client *sc, *tmp; - list_for_each_entry_safe(sc, tmp, &clients, node) - send_chunk(sc, DCCP_MAX_BYTES_PER_WRITE, current_chunk, buf, + list_for_each_entry_safe(sc, tmp, &dss->client_list, node) + send_chunk(sc, dss, DCCP_MAX_BYTES_PER_WRITE, current_chunk, buf, len); } static void dccp_shutdown_clients(void) { - struct sender_client *sc, *tmp; + shutdown_clients(dss); +} - list_for_each_entry_safe(sc, tmp, &clients, node) - shutdown_client(sc); +static int dccp_com_on(__a_unused struct sender_command_data *scd) +{ + return generic_com_on(dss, IPPROTO_DCCP); } -static char *dccp_info(void) +static int dccp_com_off(__a_unused struct sender_command_data *scd) { - static char *buf; - int num_clients = 0; - struct sender_client *sc, *tmp; + generic_com_off(dss); + return 1; +} + - free(buf); - list_for_each_entry_safe(sc, tmp, &clients, node) - num_clients++; - buf = make_message("dccp connected clients: %d\n", num_clients); - return buf; +static int dccp_com_deny(struct sender_command_data *scd) +{ + generic_com_deny(scd, dss); + return 1; } -static char *dccp_help(void) +static int dccp_com_allow(struct sender_command_data *scd) { - return make_message("no help available\n"); + generic_com_allow(scd, dss); + return 1; +} + +static char *dccp_info(void) +{ + return get_sender_info(dss, "dccp"); } /** @@ -132,22 +118,23 @@ void dccp_send_init(struct sender *s) { int ret; - INIT_LIST_HEAD(&clients); s->info = dccp_info; s->send = dccp_send; s->pre_select = dccp_pre_select; s->post_select = dccp_post_select; s->shutdown_clients = dccp_shutdown_clients; - s->help = dccp_help; - s->client_cmds[SENDER_ON] = NULL; - s->client_cmds[SENDER_OFF] = NULL; - s->client_cmds[SENDER_DENY] = NULL; - s->client_cmds[SENDER_ALLOW] = NULL; + s->help = generic_sender_help; + s->client_cmds[SENDER_ON] = dccp_com_on; + s->client_cmds[SENDER_OFF] = dccp_com_off; + s->client_cmds[SENDER_DENY] = dccp_com_deny; + s->client_cmds[SENDER_ALLOW] = dccp_com_allow; s->client_cmds[SENDER_ADD] = NULL; s->client_cmds[SENDER_DELETE] = NULL; - ret = open_sender(IPPROTO_DCCP, conf.dccp_port_arg); + + init_sender_status(dss, conf.dccp_access_arg, conf.dccp_access_given, + conf.dccp_port_arg, conf.dccp_max_clients_arg, + conf.dccp_default_deny_given); + ret = generic_com_on(dss, IPPROTO_DCCP); if (ret < 0) PARA_ERROR_LOG("%s\n", para_strerror(-ret)); - else - listen_fd = ret; }