2 * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file dccp_recv.c paraslash's dccp receiver */
10 * based on client.c of dccp-cs-0.01.tar.bz2,
11 * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
15 #include <sys/types.h>
27 #include "buffer_tree.h"
29 #include "dccp_recv.cmdline.h"
32 * data specific to the dccp receiver
34 * \sa receiver receiver_node
36 struct private_dccp_recv_data {
37 /** the file descriptor for the dccp socket */
39 struct btr_pool *btrp;
43 static void dccp_recv_close(struct receiver_node *rn)
46 struct private_dccp_recv_data *pdd = rn->private_data;
48 if (pdd && pdd->fd > 0)
50 free(rn->private_data);
51 rn->private_data = NULL;
55 static int dccp_recv_open(struct receiver_node *rn)
57 struct private_dccp_recv_data *pdd;
58 struct dccp_recv_args_info *conf = rn->conf;
59 int fd, ret = makesock(AF_UNSPEC, IPPROTO_DCCP, 0, conf->host_arg,
66 * Disable unused CCIDs: the receiver does not send any application
67 * data to the server. By shutting down this unused path we reduce
68 * internal processing costs, as the unused CCIDs (in the kernel) are
71 if (shutdown(fd, SHUT_WR) < 0) {
72 ret = -ERRNO_TO_PARA_ERROR(errno);
75 ret = mark_fd_nonblocking(fd);
78 rn->private_data = pdd = para_calloc(sizeof(struct private_dccp_recv_data));
79 pdd->btrp = btr_pool_new("dccp_recv", 320 * 1024);
87 static void *dccp_recv_parse_config(int argc, char **argv)
89 struct dccp_recv_args_info *tmp = para_calloc(sizeof(struct dccp_recv_args_info));
91 if (!dccp_recv_cmdline_parser(argc, argv, tmp))
97 static void dccp_recv_pre_select(struct sched *s, struct task *t)
99 struct receiver_node *rn = container_of(t, struct receiver_node, task);
100 struct private_dccp_recv_data *pdd = rn->private_data;
103 if (generic_recv_pre_select(s, t) <= 0)
105 para_fd_set(pdd->fd, &s->rfds, &s->max_fileno);
108 static void dccp_recv_post_select(struct sched *s, struct task *t)
110 struct receiver_node *rn = container_of(t, struct receiver_node, task);
111 struct private_dccp_recv_data *pdd = rn->private_data;
112 struct btr_node *btrn = rn->btrn;
117 ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
122 if (!FD_ISSET(pdd->fd, &s->rfds))
123 return; /* nothing to do */
124 ret = -E_DCCP_OVERRUN;
125 sz = btr_pool_get_buffer(pdd->btrp, &buf);
128 ret = recv_bin_buffer(pdd->fd, buf, sz);
133 btr_add_output_pool(pdd->btrp, ret, btrn);
136 btr_remove_node(rn->btrn);
140 static void dccp_recv_free_config(void *conf)
142 dccp_recv_cmdline_parser_free(conf);
146 * The init function of the dccp receiver.
148 * \param r Pointer to the receiver struct to initialize.
150 * Initialize all function pointers of \a r.
152 void dccp_recv_init(struct receiver *r)
154 struct dccp_recv_args_info dummy;
156 dccp_recv_cmdline_parser_init(&dummy);
157 r->open = dccp_recv_open;
158 r->close = dccp_recv_close;
159 r->pre_select = dccp_recv_pre_select;
160 r->post_select = dccp_recv_post_select;
161 r->parse_config = dccp_recv_parse_config;
162 r->free_config = dccp_recv_free_config;
163 r->help = (struct ggo_help) {
164 .short_help = dccp_recv_args_info_help,
165 .detailed_help = dccp_recv_args_info_detailed_help
167 dccp_recv_cmdline_parser_free(&dummy);