#include "string.h"
#include "net.h"
#include "fd.h"
+#include "buffer_tree.h"
#include "dccp_recv.cmdline.h"
-/** the size of the output buffer */
-#define DCCP_BUFSIZE 40960
-
/**
* data specific to the dccp receiver
*
struct private_dccp_recv_data {
/** the file descriptor for the dccp socket */
int fd;
+ struct btr_pool *btrp;
};
if (pdd && pdd->fd > 0)
close(pdd->fd);
- free(rn->buf);
- rn->buf = NULL;
+ btr_pool_free(pdd->btrp);
free(rn->private_data);
rn->private_data = NULL;
}
ret = mark_fd_nonblocking(fd);
if (ret < 0)
goto err;
- rn->buf = para_calloc(DCCP_BUFSIZE);
rn->private_data = pdd = para_calloc(sizeof(struct private_dccp_recv_data));
+ pdd->btrp = btr_pool_new("dccp_recv", 320 * 1024);
pdd->fd = fd;
return 1;
err:
return ret;
}
-static void dccp_shutdown(void)
-{
- ; /* nothing to do */
-}
-
static void *dccp_recv_parse_config(int argc, char **argv)
{
struct dccp_recv_args_info *tmp = para_calloc(sizeof(struct dccp_recv_args_info));
struct private_dccp_recv_data *pdd = rn->private_data;
t->error = 0;
+ if (generic_recv_pre_select(s, t) <= 0)
+ return;
para_fd_set(pdd->fd, &s->rfds, &s->max_fileno);
}
{
struct receiver_node *rn = container_of(t, struct receiver_node, task);
struct private_dccp_recv_data *pdd = rn->private_data;
+ struct btr_node *btrn = rn->btrn;
+ struct iovec iov[2];
+ int ret, iovcnt;
- if (rn->output_error && *rn->output_error < 0) {
- t->error = *rn->output_error;
+ ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
return;
- }
if (!FD_ISSET(pdd->fd, &s->rfds))
return; /* nothing to do */
- if (rn->loaded >= DCCP_BUFSIZE) {
- t->error = -E_DCCP_OVERRUN;
- return;
- }
- t->error = recv_bin_buffer(pdd->fd, rn->buf + rn->loaded,
- DCCP_BUFSIZE - rn->loaded);
- if (t->error > 0) {
- rn->loaded += t->error;
- return;
+ iovcnt = btr_pool_get_buffers(pdd->btrp, iov);
+ ret = -E_DCCP_OVERRUN;
+ if (iovcnt == 0)
+ goto err;
+ ret = para_readv(pdd->fd, iov, iovcnt);
+ if (ret == 0)
+ ret = -E_RECV_EOF;
+ if (ret < 0)
+ goto err;
+ if (ret <= iov[0].iov_len) /* only the first buffer was filled */
+ btr_add_output_pool(pdd->btrp, ret, btrn);
+ else { /* both buffers contain data */
+ btr_add_output_pool(pdd->btrp, iov[0].iov_len, btrn);
+ btr_add_output_pool(pdd->btrp, ret - iov[0].iov_len, btrn);
}
- if (!t->error)
- t->error = -E_RECV_EOF;
+ return;
+err:
+ btr_remove_node(rn->btrn);
+ t->error = ret;
+}
+
+static void dccp_recv_free_config(void *conf)
+{
+ dccp_recv_cmdline_parser_free(conf);
+ free(conf);
}
/**
struct dccp_recv_args_info dummy;
dccp_recv_cmdline_parser_init(&dummy);
- r->shutdown = dccp_shutdown;
r->open = dccp_recv_open;
r->close = dccp_recv_close;
r->pre_select = dccp_recv_pre_select;
r->post_select = dccp_recv_post_select;
r->parse_config = dccp_recv_parse_config;
+ r->free_config = dccp_recv_free_config;
r->help = (struct ggo_help) {
.short_help = dccp_recv_args_info_help,
.detailed_help = dccp_recv_args_info_detailed_help