update
[mTask.git] / int / main.c
index 78f44bb..43911bc 100644 (file)
@@ -79,8 +79,13 @@ void read_message(int fd_in, int fd_out)
                c = task_register(fd_in);
                write(fd_out, &c, 1);
                break;
+       case '\n':
+               break;
+       case '\0':
+               debug("iTasks server shut down\n");
+               exit(EXIT_SUCCESS);
        default:
-               debug("Unknown message: %X?\n", c);
+               debug("Unknown message: %X %X?\n", c, EOF);
        }
 }
 
@@ -96,9 +101,9 @@ void open_filedescriptors()
        if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
                pdie("socket");
        if(bind(sock_fd, (struct sockaddr*)&sa, sizeof(sa)) == -1)
-               pdie("bind\n");
+               pdie("bind");
        if(listen(sock_fd, 10) == -1)
-               pdie("bind\n");
+               pdie("listen");
 
        printf("Listening on %d\n", port);
        fflush(stdout);
@@ -147,6 +152,7 @@ int main(int argc, char *argv[])
        }
 
        open_filedescriptors();
+       write(fd, "\n", 1);
 
        long cyclestart;
        struct task *curtask;
@@ -159,21 +165,23 @@ int main(int argc, char *argv[])
                for(ct = 0; ct<MAXTASKS; ct++){
                        //See whether the task is even in use
                        if((curtask = task_get(ct)) == NULL){
-                               debug("Task %d not implemented\n", ct);
+//                             debug("Task %d not implemented\n", ct);
                                continue;
                        }
                        //See whether the task interval has passed
                        if(cyclestart-curtask->lastrun < curtask->interval){
-                               debug("Task %d not scheduled\n", ct);
+//                             debug("Task %d not scheduled\n", ct);
                                continue;
                        }
 #ifdef DEBUG
                        printf("Current task to run: %d\n", ct);
                        getchar();
 #endif
-                       run_task(curtask);
+                       run_task(curtask, fd);
                }
-               usleep(10);
+               debug("Waiting for 500ms\n");
+               usleep(500000);
+               debug("done waiting\n");
        }
        return 0;
 }