X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=dccp_send.c;h=1e62d289538ad52cb2325dfd262bb59687eeb15e;hp=d0f9448e8e048445ce0e0c6a6adf8d0d903449cc;hb=becb57ea3aec697bfe953a0c3608e4c255b6d24b;hpb=8157cf8316ef9b3769933d5b17e169b400d36da8 diff --git a/dccp_send.c b/dccp_send.c index d0f9448e..1e62d289 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -1,10 +1,10 @@ /* - * Copyright (C) 2006-2008 Andre Noll + * Copyright (C) 2006-2009 Andre Noll * * 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, @@ -13,6 +13,7 @@ #include #include +#include #include "para.h" #include "error.h" @@ -30,111 +31,81 @@ #include "server.cmdline.h" #include "acl.h" -/** the list of connected clients **/ -static struct list_head clients; -/** The whitelist/blacklist. */ -static struct list_head dccp_acl; -static int listen_fd = -1; - -/** Maximal number of bytes in a chunk queue. */ -#define DCCP_MAX_PENDING_BYTES 40000 - /** 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; - ret = acl_check_access(fd, &dccp_acl, conf.dccp_default_deny_given); - 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, - __a_unused long unsigned chunks_sent, const char *buf, size_t len) + __a_unused long unsigned chunks_sent, const char *buf, + size_t len, const char *header_buf, size_t header_len) { 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, - len); + list_for_each_entry_safe(sc, tmp, &dss->client_list, node) + send_chunk(sc, dss, DCCP_MAX_BYTES_PER_WRITE, current_chunk, buf, + len, header_buf, header_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 int dccp_com_deny(struct sender_command_data *scd) +static int dccp_com_off(__a_unused struct sender_command_data *scd) { - acl_deny(scd->addr, scd->netmask, &dccp_acl, - conf.dccp_default_deny_given); + generic_com_off(dss); return 1; } -static int dccp_com_allow(struct sender_command_data *scd) + +static int dccp_com_deny(struct sender_command_data *scd) { - acl_allow(scd->addr, scd->netmask, &dccp_acl, - conf.dccp_default_deny_given); + generic_com_deny(scd, dss); return 1; } -static char *dccp_info(void) +static int dccp_com_allow(struct sender_command_data *scd) { - int num_clients = 0; - struct sender_client *sc, *tmp; - - list_for_each_entry_safe(sc, tmp, &clients, node) - num_clients++; - return make_message("dccp connected clients: %d\n", num_clients); + generic_com_allow(scd, dss); + return 1; } -static char *dccp_help(void) +static char *dccp_info(void) { - return make_message("no help available\n"); + return get_sender_info(dss, "dccp"); } /** @@ -149,23 +120,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->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; - acl_init(&dccp_acl, conf.dccp_access_arg, conf.dccp_access_given); - 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; }