X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=http_recv.c;h=53ef8e60d03f6d7afc4d5b9d7e3b7a2e71c97deb;hp=cdb4bc151c4f580803160b80af672cc9d011bfa7;hb=01bd4cba7946f6506f4ca3095104904bf3b2b098;hpb=62342ef50476f58e97cd9bb160fdb74ec4989bff diff --git a/http_recv.c b/http_recv.c index cdb4bc15..53ef8e60 100644 --- a/http_recv.c +++ b/http_recv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2009 Andre Noll + * Copyright (C) 2005-2011 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -23,9 +23,6 @@ #include "fd.h" #include "buffer_tree.h" -/** the output buffer size of the http receiver */ -#define BUFSIZE (32 * 1024) - /** * the possible states of a http receiver node * @@ -52,7 +49,7 @@ struct private_http_recv_data { * The file descriptor used for receiving the http stream. * * The pre_select function of the http receiver adds this file descriptor to - * the set of file decriptors which are checked for reading/writing (depending + * the set of file descriptors which are checked for reading/writing (depending * on the current status) by the select loop of the application (para_audiod or * para_recv). * @@ -98,7 +95,7 @@ static void http_recv_post_select(struct sched *s, struct task *t) struct btr_node *btrn = rn->btrn; int ret; char *buf; - size_t sz; + size_t sz, n; t->error = 0; ret = btr_node_status(btrn, 0, BTR_NT_ROOT); @@ -119,12 +116,12 @@ static void http_recv_post_select(struct sched *s, struct task *t) phd->status = HTTP_SENT_GET_REQUEST; return; } - if (!FD_ISSET(phd->fd, &s->rfds)) - return; if (phd->status == HTTP_SENT_GET_REQUEST) { - ret = recv_pattern(phd->fd, HTTP_OK_MSG, strlen(HTTP_OK_MSG)); + ret = read_pattern(phd->fd, HTTP_OK_MSG, strlen(HTTP_OK_MSG), &s->rfds); if (ret < 0) goto err; + if (ret == 0) + return; PARA_INFO_LOG("received ok msg, streaming\n"); phd->status = HTTP_STREAMING; return; @@ -133,13 +130,11 @@ static void http_recv_post_select(struct sched *s, struct task *t) sz = btr_pool_get_buffer(phd->btrp, &buf); if (sz == 0) goto err; - ret = recv_bin_buffer(phd->fd, buf, sz); - if (ret == 0) - ret = -E_RECV_EOF; - if (ret < 0) - goto err; - btr_add_output_pool(phd->btrp, ret, btrn); - return; + ret = read_nonblock(phd->fd, buf, sz, &s->rfds, &n); + if (n > 0) + btr_add_output_pool(phd->btrp, n, btrn); + if (ret >= 0) + return; err: btr_remove_node(rn->btrn); t->error = ret; @@ -151,7 +146,6 @@ static void http_recv_close(struct receiver_node *rn) close(phd->fd); btr_pool_free(phd->btrp); - free(rn->buf); free(rn->private_data); } @@ -169,8 +163,8 @@ static int http_recv_open(struct receiver_node *rn) { struct private_http_recv_data *phd; struct http_recv_args_info *conf = rn->conf; - int fd, ret = makesock(AF_UNSPEC, IPPROTO_TCP, 0, conf->host_arg, - conf->port_arg); + int fd, ret = para_connect_simple(IPPROTO_TCP, conf->host_arg, + conf->port_arg); if (ret < 0) return ret; @@ -180,7 +174,6 @@ static int http_recv_open(struct receiver_node *rn) close(fd); return ret; } - rn->buf = para_calloc(BUFSIZE); rn->private_data = phd = para_calloc(sizeof(struct private_http_recv_data)); phd->fd = fd; phd->status = HTTP_CONNECTED; @@ -191,6 +184,7 @@ static int http_recv_open(struct receiver_node *rn) static void http_recv_free_config(void *conf) { http_recv_cmdline_parser_free(conf); + free(conf); } /**