X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=dccp_recv.c;h=0b62529f417352715d14304685565f1efeae581d;hp=4d4ac86db31cb28f1d2d1d9f081f13dc8a139dcc;hb=11ef83c4abb2ccbdf3f99a8adf98749b2b0656c2;hpb=92339599bddb1b1b79b6aa76d645b403081f4835 diff --git a/dccp_recv.c b/dccp_recv.c index 4d4ac86d..0b62529f 100644 --- a/dccp_recv.c +++ b/dccp_recv.c @@ -24,12 +24,10 @@ #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 * @@ -38,6 +36,7 @@ struct private_dccp_recv_data { /** the file descriptor for the dccp socket */ int fd; + struct btr_pool *btrp; }; @@ -48,8 +47,6 @@ static void dccp_recv_close(struct receiver_node *rn) if (pdd && pdd->fd > 0) close(pdd->fd); - free(rn->buf); - rn->buf = NULL; free(rn->private_data); rn->private_data = NULL; } @@ -78,8 +75,8 @@ static int dccp_recv_open(struct receiver_node *rn) 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: @@ -87,11 +84,6 @@ 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)); @@ -108,6 +100,8 @@ static void dccp_recv_pre_select(struct sched *s, struct task *t) 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); } @@ -115,25 +109,37 @@ static void dccp_recv_post_select(struct sched *s, struct task *t) { 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; + int ret; + char *buf; + size_t sz; - 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; - } - if (!t->error) - t->error = -E_RECV_EOF; + ret = -E_DCCP_OVERRUN; + sz = btr_pool_get_buffer(pdd->btrp, &buf); + if (sz == 0) + goto err; + ret = recv_bin_buffer(pdd->fd, buf, sz); + if (ret == 0) + ret = -E_RECV_EOF; + if (ret < 0) + goto err; + btr_add_output_pool(pdd->btrp, ret, btrn); + return; +err: + btr_remove_node(rn->btrn); + t->error = ret; +} + +static void dccp_recv_free_config(void *conf) +{ + dccp_recv_cmdline_parser_free(conf); } /** @@ -148,14 +154,15 @@ void dccp_recv_init(struct receiver *r) 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 }; + dccp_recv_cmdline_parser_free(&dummy); }