679eb227e170c1b7f08792f9f5b9700e3ae842e5
2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file dccp_recv.c paraslash's dccp receiver */
22 * based on client.c of dccp-cs-0.01.tar.bz2,
23 * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
33 #include "dccp_recv.cmdline.h"
35 /* needed by getaddrinfo */
36 #include <sys/types.h>
37 #include <sys/socket.h>
40 /** the size of the output buffer */
41 #define DCCP_BUFSIZE 40960
44 * data specific to the dccp receiver
46 * \sa receiver receiver_node
48 struct private_dccp_recv_data
{
49 /** the file descriptor for the dccp socket */
54 static void dccp_recv_close(struct receiver_node
*rn
)
57 struct private_dccp_recv_data
*pdd
= rn
->private_data
;
59 if (pdd
&& pdd
->fd
> 0)
63 free(rn
->private_data
);
64 rn
->private_data
= NULL
;
68 static int dccp_recv_open(struct receiver_node
*rn
)
70 struct private_dccp_recv_data
*pdd
;
71 struct dccp_recv_args_info
*conf
= rn
->conf
;
76 rn
->buf
= para_calloc(DCCP_BUFSIZE
);
77 rn
->private_data
= para_calloc(sizeof(struct private_dccp_recv_data
));
78 pdd
= rn
->private_data
;
79 ret
= dccp_get_socket();
84 tmp
= make_message("%d", conf
->port_arg
);
85 ret
= getaddrinfo(conf
->host_arg
, tmp
, NULL
, &ai
);
91 ret
= dccp_set_socket(pdd
->fd
);
94 PARA_NOTICE_LOG("connecting to %s:%d\n", conf
->host_arg
, conf
->port_arg
);
95 ret
= -E_DCCP_CONNECT
;
96 if (connect(pdd
->fd
, ai
->ai_addr
, ai
->ai_addrlen
) < 0)
104 static void dccp_shutdown(void)
106 ; /* nothing to do */
109 static void *dccp_recv_parse_config(int argc
, char **argv
)
111 struct dccp_recv_args_info
*tmp
= para_calloc(sizeof(struct dccp_recv_args_info
));
113 if (!dccp_recv_cmdline_parser(argc
, argv
, tmp
))
119 static int dccp_recv_pre_select(struct receiver_node
*rn
, fd_set
*rfds
,
120 __unused fd_set
*wfds
, __unused
struct timeval
*timeout
)
122 struct private_dccp_recv_data
*pdd
= rn
->private_data
;
126 FD_SET(pdd
->fd
, rfds
);
130 static int dccp_recv_post_select(struct receiver_node
*rn
, int select_ret
,
131 fd_set
*rfds
, __unused fd_set
*wfds
)
134 struct private_dccp_recv_data
*pdd
= rn
->private_data
;
136 if (!select_ret
|| !pdd
|| !FD_ISSET(pdd
->fd
, rfds
))
137 return 1; /* nothing to do */
138 if (rn
->loaded
>= DCCP_BUFSIZE
)
139 return -E_DCCP_OVERRUN
;
140 ret
= recv_bin_buffer(pdd
->fd
, rn
->buf
+ rn
->loaded
,
141 DCCP_BUFSIZE
- rn
->loaded
);
143 PARA_INFO_LOG("%s\n", ret
? PARA_STRERROR(-ret
) : "eof");
151 * the init function of the dccp receiver
153 * \param r pointer to the receiver struct to initialize
155 * Initialize all function pointers of \a r
157 void dccp_recv_init(struct receiver
*r
)
159 r
->shutdown
= dccp_shutdown
;
160 r
->open
= dccp_recv_open
;
161 r
->close
= dccp_recv_close
;
162 r
->pre_select
= dccp_recv_pre_select
;
163 r
->post_select
= dccp_recv_post_select
;
164 r
->parse_config
= dccp_recv_parse_config
;