next_buffer:
t->error = 0;
- ret = btr_node_status(btrn, fn->min_iqs);
+ ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
if (ret < 0)
goto err;
if (ret == 0)
if (!pad->handle)
return 1;
if (wn->btrn) {
- int ret = btr_node_status(wn->btrn, wn->min_iqs);
+ int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret == 0)
return 1;
if (ret < 0) {
again:
t->error = 0;
- ret = btr_node_status(btrn, wn->min_iqs);
+ ret = btr_node_status(btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret == 0)
return;
btr_merge(btrn, wn->min_iqs);
return;
}
next_buffer:
- ret = btr_node_status(btrn, fn->min_iqs);
+ ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
if (ret < 0)
goto err;
if (ret == 0)
/** 640K ought to be enough for everybody ;) */
#define BTRN_MAX_PENDING (640 * 1024)
-int btr_node_status(struct btr_node *btrn, size_t min_iqs)
+int btr_node_status(struct btr_node *btrn, size_t min_iqs,
+ enum btr_node_type type)
{
size_t iqs;
- if (btr_eof(btrn))
- return -E_BTR_EOF;
- if (btr_bytes_pending(btrn) > BTRN_MAX_PENDING)
- return 0;
- iqs = btr_get_input_queue_size(btrn);
- if (iqs == 0) /* we have a parent, because not eof */
- return 0;
- if (iqs < min_iqs && !btr_no_parent(btrn))
- return 0;
+ if (type != BTR_NT_LEAF) {
+ if (btr_no_children(btrn))
+ return -E_BTR_NO_CHILD;
+ if (btr_bytes_pending(btrn) > BTRN_MAX_PENDING)
+ return 0;
+ }
+ if (type != BTR_NT_ROOT) {
+ if (btr_eof(btrn))
+ return -E_BTR_EOF;
+ iqs = btr_get_input_queue_size(btrn);
+ if (iqs == 0) /* we have a parent, because not eof */
+ return 0;
+ if (iqs < min_iqs && !btr_no_parent(btrn))
+ return 0;
+ }
return 1;
}
typedef int (*btr_command_handler)(struct btr_node *btrn,
const char *command, char **result);
+enum btr_node_type {
+ BTR_NT_ROOT,
+ BTR_NT_INTERNAL,
+ BTR_NT_LEAF,
+};
+
struct btr_node *btr_new_node(const char *name, struct btr_node *parent,
btr_command_handler handler, void *context);
void btr_remove_node(struct btr_node *btrn);
void btr_log_tree(struct btr_node *btrn, int loglevel);
int btr_pushdown_one(struct btr_node *btrn);
bool btr_inplace_ok(struct btr_node *btrn);
-int btr_node_status(struct btr_node *btrn, size_t min_iqs);
+int btr_node_status(struct btr_node *btrn, size_t min_iqs,
+ enum btr_node_type type);
//inplace = false;
next_buffer:
t->error = 0;
- ret = btr_node_status(btrn, fn->min_iqs);
+ ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
if (ret < 0)
goto err;
if (ret == 0)
#define BUFFER_TREE_ERRORS \
PARA_ERROR(BTR_EOF, "buffer tree: end of file"), \
+ PARA_ERROR(BTR_NO_CHILD, "btr node has no children"), \
#define STDOUT_ERRORS \
PARA_ERROR(STDOUT_EOF, "stdout: end of file"), \
#define STDIN_ERRORS \
PARA_ERROR(STDIN_EOF, "end of file"), \
- PARA_ERROR(STDIN_NO_CHILD, "stdin btr node has no children"), \
#define HTTP_RECV_ERRORS \
PARA_ERROR(HTTP_RECV_OVERRUN, "http_recv: output buffer overrun"), \
- PARA_ERROR(HTTP_RECV_NO_CHILD, "http_recv btr node has no children"), \
#define RECV_COMMON_ERRORS \
t->error = 0;
pfwd->check_fd = 0;
- ret = btr_node_status(wn->btrn, wn->min_iqs);
+ ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret > 0) {
para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
pfwd->check_fd = 1;
size_t bytes;
t->error = 0;
- ret = btr_node_status(btrn, wn->min_iqs);
+ ret = btr_node_status(btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret == 0)
return;
if (ret < 0)
struct filter_node *fn = container_of(t, struct filter_node, task);
t->error = 0;
- if (btr_node_status(fn->btrn, fn->min_iqs) != 0) {
+ if (btr_node_status(fn->btrn, fn->min_iqs, BTR_NT_INTERNAL) != 0) {
s->timeout.tv_sec = 0;
s->timeout.tv_usec = 1;
}
para_fd_set(phd->fd, &s->rfds, &s->max_fileno);
}
-#define HTTP_RECV_MAX_PENDING (1024 * 1024)
#define HTTP_RECV_READ_BUF_SIZE 4096
static void http_recv_post_select(struct sched *s, struct task *t)
{
struct receiver_node *rn = container_of(t, struct receiver_node, task);
struct private_http_recv_data *phd = rn->private_data;
- struct http_recv_args_info *conf = rn->conf;
+ struct btr_node *btrn = rn->btrn;
+ int ret;
- if (rn->output_error && *rn->output_error < 0) {
- t->error = *rn->output_error;
- goto err;
+ t->error = 0;
+ if (btrn) {
+ ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
+ return;
+ } else {
+ if (rn->output_error && *rn->output_error < 0) {
+ ret = *rn->output_error;
+ goto err;
+ }
}
if (phd->status == HTTP_CONNECTED) {
char *rq;
return;
rq = make_request_msg();
PARA_INFO_LOG("sending http request\n");
- t->error = send_va_buffer(phd->fd, "%s", rq);
+ ret = send_va_buffer(phd->fd, "%s", rq);
free(rq);
- if (t->error < 0)
+ if (ret < 0)
goto err;
phd->status = HTTP_SENT_GET_REQUEST;
return;
if (!FD_ISSET(phd->fd, &s->rfds))
return;
if (phd->status == HTTP_SENT_GET_REQUEST) {
- t->error = recv_pattern(phd->fd, HTTP_OK_MSG, strlen(HTTP_OK_MSG));
- if (t->error < 0)
+ ret = recv_pattern(phd->fd, HTTP_OK_MSG, strlen(HTTP_OK_MSG));
+ if (ret < 0)
goto err;
PARA_INFO_LOG("received ok msg, streaming\n");
phd->status = HTTP_STREAMING;
return;
}
- if (conf->buffer_tree_given) {
+ if (btrn) {
char *buf;
- if (btr_no_children(rn->btrn)) {
- t->error = -E_HTTP_RECV_NO_CHILD;
- goto err;
- }
- if (btr_bytes_pending(rn->btrn) > HTTP_RECV_MAX_PENDING) {
- t->error = -E_HTTP_RECV_OVERRUN;
- goto err;
- }
buf = para_malloc(HTTP_RECV_READ_BUF_SIZE);
- t->error = recv_bin_buffer(phd->fd, buf, HTTP_RECV_READ_BUF_SIZE);
- if (t->error == 0)
- t->error = -E_RECV_EOF;
- if (t->error < 0) {
+ ret = recv_bin_buffer(phd->fd, buf, HTTP_RECV_READ_BUF_SIZE);
+ if (ret == 0)
+ ret = -E_RECV_EOF;
+ if (ret < 0) {
free(buf);
goto err;
}
- btr_add_output(buf, t->error, rn->btrn);
+ btr_add_output(buf, ret, btrn);
return;
}
- t->error = -E_HTTP_RECV_OVERRUN;
+ ret = -E_HTTP_RECV_OVERRUN;
if (rn->loaded >= BUFSIZE)
goto err;
- t->error = recv_bin_buffer(phd->fd, rn->buf + rn->loaded,
+ ret = recv_bin_buffer(phd->fd, rn->buf + rn->loaded,
BUFSIZE - rn->loaded);
- if (t->error == 0)
- t->error = -E_RECV_EOF;
- if (t->error < 0)
+ if (ret == 0)
+ ret = -E_RECV_EOF;
+ if (ret < 0)
goto err;
- rn->loaded += t->error;
+ rn->loaded += ret;
return;
err:
- if (conf->buffer_tree_given) {
+ if (btrn)
btr_remove_node(rn->btrn);
- rn->btrn = NULL;
- }
+ t->error = ret;
}
static void http_recv_close(struct receiver_node *rn)
iqs = btr_get_input_queue_size(btrn);
if (need_bad_data_delay(pmd, iqs))
return;
- ret = btr_node_status(btrn, fn->min_iqs);
+ ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
if (ret < 0)
goto err;
if (ret == 0)
char *in;
t->error = 0;
- ret = btr_node_status(btrn, fn->min_iqs);
+ ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
if (ret < 0)
goto err;
if (ret == 0)
{
struct writer_node *wn = container_of(t, struct writer_node, task);
struct private_oss_write_data *powd = wn->private_data;
- int ret = btr_node_status(wn->btrn, wn->min_iqs);
+ int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
t->error = 0;
if (ret < 0)
struct private_oss_write_data *powd = wn->private_data;
struct btr_node *btrn = wn->btrn;
size_t frames, bytes;
- int ret = btr_node_status(btrn, wn->min_iqs);
+ int ret = btr_node_status(btrn, wn->min_iqs, BTR_NT_LEAF);
char *data;
if (ret < 0)
para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno);
}
-#define STDIN_MAX_PENDING (100 * 1024)
-
static void stdin_pre_select_btr(struct sched *s, struct task *t)
{
struct stdin_task *sit = container_of(t, struct stdin_task, task);
+ int ret;
t->error = 0;
- if (btr_bytes_pending(sit->btrn) > STDIN_MAX_PENDING)
- sit->check_fd = 0;
- else {
- sit->check_fd = 1;
+ ret = btr_node_status(sit->btrn, 0, BTR_NT_ROOT);
+ if (ret > 0)
para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno);
+ else if (ret < 0) {
+ s->timeout.tv_sec = 0;
+ s->timeout.tv_usec = 1;
}
}
ssize_t ret;
char *buf = NULL;
- t->error = -E_STDIN_NO_CHILD;
- if (btr_no_children(sit->btrn))
- goto err;
-
t->error = 0;
- if (!sit->check_fd)
+ ret = btr_node_status(sit->btrn, 0, BTR_NT_ROOT);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
return;
if (!FD_ISSET(STDIN_FILENO, &s->rfds))
return;
-
buf = para_malloc(STDIN_INPUT_BUFFER_SIZE);
ret = read(STDIN_FILENO, buf, STDIN_INPUT_BUFFER_SIZE);
//PARA_CRIT_LOG("read ret: %d\n", ret);
err:
free(buf);
btr_remove_node(sit->btrn);
+ t->error = ret;
}
/**
static void stdout_pre_select_btr(struct sched *s, struct task *t)
{
struct stdout_task *sot = container_of(t, struct stdout_task, task);
- size_t sz = btr_get_input_queue_size(sot->btrn);
+ int ret;
t->error = 0;
sot->check_fd = 0;
- if (sz == 0) {
- if (btr_no_parent(sot->btrn)) {
- s->timeout.tv_sec = 0;
- s->timeout.tv_usec = 1;
- }
- return;
+ ret = btr_node_status(sot->btrn, 0, BTR_NT_LEAF);
+ if (ret > 0)
+ para_fd_set(STDOUT_FILENO, &s->wfds, &s->max_fileno);
+ else if (ret < 0) {
+ s->timeout.tv_sec = 0;
+ s->timeout.tv_usec = 1;
}
- sot->check_fd = 1;
- para_fd_set(STDOUT_FILENO, &s->wfds, &s->max_fileno);
}
/**
static void stdout_post_select_btr(struct sched *s, struct task *t)
{
struct stdout_task *sot = container_of(t, struct stdout_task, task);
- ssize_t ret;
- size_t sz = btr_get_input_queue_size(sot->btrn);
+ struct btr_node *btrn = sot->btrn;
+ int ret;
char *buf;
+ size_t sz;
t->error = 0;
- if (!sot->check_fd) {
- if (sz == 0 && btr_no_parent(sot->btrn)) {
- t->error = -E_STDOUT_EOF;
- goto err;
- }
+ ret = btr_node_status(btrn, 0, BTR_NT_LEAF);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
return;
- }
if (!FD_ISSET(STDOUT_FILENO, &s->wfds))
return;
- sz = btr_next_buffer(sot->btrn, &buf);
- if (sz == 0)
- return;
+ sz = btr_next_buffer(btrn, &buf);
+ assert(sz > 0);
ret = write_nonblock(STDOUT_FILENO, buf, sz, 0);
- if (ret < 0) {
- t->error = -ERRNO_TO_PARA_ERROR(errno);
+ if (ret < 0)
goto err;
- }
- btr_consume(sot->btrn, ret);
+ btr_consume(btrn, ret);
return;
err:
- btr_remove_node(sot->btrn);
+ btr_remove_node(btrn);
+ t->error = ret;
}
/**
* Initialize a stdout task structure with default values.
next_buffer:
converted = 0;
t->error = 0;
- ret = btr_node_status(btrn, fn->min_iqs);
+ ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
if (ret < 0)
goto err;
if (ret == 0)