Make para_recv use the new scheduler.
[paraslash.git] / recv.c
diff --git a/recv.c b/recv.c
index af15eb0..4b84e8b 100644 (file)
--- a/recv.c
+++ b/recv.c
  */
 #include "para.h"
 
+#include "list.h"
+#include "sched.h"
 #include "recv.h"
 #include "recv.cmdline.h"
 #include "fd.h"
 #include "error.h"
+#include "stdout.h"
 
 struct gengetopt_args_info conf;
 
@@ -55,6 +58,7 @@ static void *parse_config(int argc, char *argv[], int *receiver_num)
        return check_receiver_arg(conf.receiver_arg, receiver_num);
 }
 
+#if 0
 int main(int argc, char *argv[])
 {
        int ret, eof = 0, max, r_opened = 0, receiver_num;
@@ -125,3 +129,77 @@ out:
                PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
        return ret;
 }
+#endif
+
+void rn_event_handler(struct task *t)
+{
+       PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret));
+       unregister_task(t);
+}
+
+void stdout_event_handler(struct task *t)
+{
+       PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret));
+       unregister_task(t);
+}
+
+int main(int argc, char *argv[])
+{
+       int ret, eof = 0, max, r_opened = 0, receiver_num;
+       struct timeval timeout;
+       struct  receiver *r = NULL;
+       fd_set rfds, wfds;
+       struct receiver_node rn;
+       struct stdout_task sot;
+       struct sched s;
+
+       init_sched();
+       s.default_timeout.tv_sec = 1;
+       s.default_timeout.tv_usec = 0;
+
+       memset(&rn, 0, sizeof(struct receiver_node));
+       for (ret = 0; receivers[ret].name; ret++)
+               receivers[ret].init(&receivers[ret]);
+       ret = -E_RECV_SYNTAX;
+       rn.conf = parse_config(argc, argv, &receiver_num);
+       if (!rn.conf) {
+               PARA_EMERG_LOG("%s", "parse failed\n");
+               goto out;
+       }
+       r = &receivers[receiver_num];
+       rn.receiver = r;
+       ret = r->open(&rn);
+       if (ret < 0)
+               goto out;
+       r_opened = 1;
+
+       sot.task.private_data = &sot;
+       sot.task.pre_select = stdout_pre_select;
+       sot.task.post_select = stdout_post_select;
+       sot.task.event_handler = stdout_event_handler;
+       sot.task.flags = 0;
+       sprintf(sot.task.status, "stdout writer");
+       sot.buf = rn.buf;
+       sot.loaded = &rn.loaded;
+       sot.eof = &rn.eof;
+       register_task(&sot.task);
+
+       rn.task.private_data = &rn;
+       rn.task.pre_select = r->pre_select;
+       rn.task.post_select = r->post_select;
+       rn.task.event_handler = rn_event_handler;
+       rn.task.flags = 0;
+       sprintf(rn.task.status, "receiver node");
+       register_task(&rn.task);
+
+
+       ret = sched(&s);
+out:
+       if (r_opened)
+               r->close(&rn);
+       if (r)
+               r->shutdown();
+       if (ret < 0)
+               PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
+       return ret;
+}