+char tasks[MAXTASKS][MAXTASKSIZE] = {0};
+bool tasks_used[MAXTASKS] = {0};
+
+void killHandler(int i)
+{
+ printf("%s caught, Bye...\n", strsignal(i));
+ exit(1);
+}
+
+bool input_available(int fd){
+ struct timeval tv;
+ fd_set fds;
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ if(select(fd+1, &fds, NULL, NULL, &tv) == -1){
+ pdie("select");
+ }
+ return FD_ISSET(fd, &fds);
+}
+
+void read_message(int fd_in, int fd_out)
+{
+ //Find next task
+ uint8_t c;
+ uint16_t tasklen;
+ uint8_t ct;
+
+ for(ct = 0; ct<MAXTASKS; ct++)
+ if(!tasks_used[ct])
+ break;
+ if(ct == MAXTASKS)
+ die("Trying to add too much tasks...\n");
+
+ debug("Receiving input for task %d\n", ct);
+ read(fd_in, &c, 1);
+ if((char) c == 's') {
+ debug("Receiving an sds\n");
+ } else if((char) c == 't'){
+ read(fd_in, &c, 1);
+ tasklen = 256*c;
+ read(fd_in, &c, 1);
+ tasklen += c;
+ if(tasklen > MAXTASKSIZE)
+ die("Task is too long: %d\n", tasklen);
+ for(int i = 0; i<tasklen; i++){
+ debug("Read %d\n", i);
+ read(fd_in, tasks[ct]+i, 1);
+ debug("t[][%i]: %d\n", i,
+ tasks[ct][i]);
+ }
+ //Return the task number for later removal
+ write(fd_out, (void *)&ct, 1);
+ debug("Received a task of length %d\n", tasklen);
+ tasks_used[ct] = true;
+ } else {
+ die("Unknown message: %c?\n", c);
+ }
+}
+
+void run_task(char *program)
+{
+
+ (void) program;
+}