Add the mosx Authors to CREDITS
[paraslash.git] / file_writer.c
index 9145ef9..e90647d 100644 (file)
@@ -59,51 +59,40 @@ static int file_writer_open(struct writer_node *wn)
        return -E_FW_OPEN;
 }
 
-static int file_writer_write(char *data, size_t nbytes, struct writer_node *wn)
+static int file_writer_pre_select(struct sched *s, struct writer_node *wn)
 {
-       struct private_file_writer_data *pfwd = wn->private_data;
-       int ret = write(pfwd->fd, data, nbytes);
-       if (ret < 0)
-               ret = -E_FW_WRITE;
-       return ret;
-}
-
-static void file_writer_pre_select(struct sched *s, struct task *t)
-{
-       struct writer_node *wn = t->private_data;
        struct private_file_writer_data *pfwd = wn->private_data;
        struct writer_node_group *wng = wn->wng;
 
-//     PARA_INFO_LOG("task %p check_fd: %d\n", t, pfwd->check_fd);
        pfwd->check_fd = 0;
-       t->ret = -E_FW_NO_FILE;
        if (pfwd->fd <= 0)
-               return;
-       t->ret = 0;
+               return -E_FW_NO_FILE;
        if (!*wng->loaded)
-               return;
-       t->ret = 1;
+               return 1;
        para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
        pfwd->check_fd = 1;
+       return 1;
 }
 
-static void file_writer_post_select(struct sched *s, struct task *t)
+static int file_writer_post_select(struct sched *s, struct writer_node *wn)
 {
-       struct writer_node *wn = t->private_data;
        struct private_file_writer_data *pfwd = wn->private_data;
        struct writer_node_group *wng = wn->wng;
+       int ret;
 
-       t->ret = 0;
        if (!pfwd->check_fd)
-               return;
-       if (!*wng->loaded)
-               return;
+               return 1;
+       if (*wng->loaded <= wn->written)
+               return 1;
        if (!FD_ISSET(pfwd->fd, &s->wfds))
-               return;
+               return 1;
 //     PARA_INFO_LOG("writing %zd\n", *wng->loaded);
-       t->ret = write(pfwd->fd, wng->buf, *wng->loaded);
-       if (t->ret < 0)
-               t->ret = -E_FW_WRITE;
+       ret = write(pfwd->fd, wng->buf + wn->written,
+               *wng->loaded - wn->written);
+       if (ret < 0)
+               return -E_FW_WRITE;
+       wn->written += ret;
+       return 1;
 }
 
 static void file_writer_close(struct writer_node *wn)
@@ -130,7 +119,6 @@ __malloc void *file_writer_parse_config(char *options)
 void file_writer_init(struct writer *w)
 {
        w->open = file_writer_open;
-       w->write = file_writer_write;
        w->pre_select = file_writer_pre_select;
        w->post_select = file_writer_post_select;
        w->parse_config = file_writer_parse_config;