Merge commit 'meins/master'
[paraslash.git] / dccp_recv.c
1 /*
2 * Copyright (C) 2006-2008 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file dccp_recv.c paraslash's dccp receiver */
8
9 /*
10 * based on client.c of dccp-cs-0.01.tar.bz2,
11 * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
12 */
13
14 #include <sys/types.h>
15 #include <dirent.h>
16
17 #include "para.h"
18 #include "error.h"
19 #include "list.h"
20 #include "sched.h"
21 #include "ggo.h"
22 #include "recv.h"
23 #include "string.h"
24 #include "net.h"
25 #include "fd.h"
26
27 #include "dccp_recv.cmdline.h"
28
29 /** the size of the output buffer */
30 #define DCCP_BUFSIZE 40960
31
32 /**
33 * data specific to the dccp receiver
34 *
35 * \sa receiver receiver_node
36 */
37 struct private_dccp_recv_data {
38 /** the file descriptor for the dccp socket */
39 int fd;
40 };
41
42
43 static void dccp_recv_close(struct receiver_node *rn)
44 {
45
46 struct private_dccp_recv_data *pdd = rn->private_data;
47
48 if (pdd && pdd->fd > 0)
49 close(pdd->fd);
50 free(rn->buf);
51 rn->buf = NULL;
52 free(rn->private_data);
53 rn->private_data = NULL;
54 }
55
56
57 static int dccp_recv_open(struct receiver_node *rn)
58 {
59 struct private_dccp_recv_data *pdd;
60 struct dccp_recv_args_info *conf = rn->conf;
61 int fd, ret = makesock(AF_UNSPEC, IPPROTO_DCCP, 0, conf->host_arg,
62 conf->port_arg);
63
64 if (ret < 0)
65 return ret;
66 fd = ret;
67 /*
68 * Disable unused CCIDs: the receiver does not send any application
69 * data to the server. By shutting down this unused path we reduce
70 * internal processing costs, as the unused CCIDs (in the kernel) are
71 * then bypassed.
72 */
73 if (shutdown(fd, SHUT_WR) < 0) {
74 ret = -ERRNO_TO_PARA_ERROR(errno);
75 goto err;
76 }
77 ret = mark_fd_nonblocking(fd);
78 if (ret < 0)
79 goto err;
80 rn->buf = para_calloc(DCCP_BUFSIZE);
81 rn->private_data = pdd = para_calloc(sizeof(struct private_dccp_recv_data));
82 pdd->fd = fd;
83 return 1;
84 err:
85 close(fd);
86 return ret;
87 }
88
89 static void dccp_shutdown(void)
90 {
91 ; /* nothing to do */
92 }
93
94 static void *dccp_recv_parse_config(int argc, char **argv)
95 {
96 struct dccp_recv_args_info *tmp = para_calloc(sizeof(struct dccp_recv_args_info));
97
98 if (!dccp_recv_cmdline_parser(argc, argv, tmp))
99 return tmp;
100 free(tmp);
101 return NULL;
102 }
103
104 static void dccp_recv_pre_select(struct sched *s, struct task *t)
105 {
106 struct receiver_node *rn = container_of(t, struct receiver_node, task);
107 struct private_dccp_recv_data *pdd = rn->private_data;
108
109