+#define _BSD_SOURCE
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
void killHandler(int i)
{
- printf("%s caught, Bye...\n", strsignal(i));
+ printf("%i caught, Bye...\n", i);
exit(1);
}
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\n", c);
}
}
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);
}
//Command line arguments
- int opt;
- while((opt = getopt(argc, argv, "hp:")) != -1){
- switch(opt){
- case 'p':
- port = atoi(optarg);
- if(port < 1)
- die("Port numbers are > 1\n");
- break;
- case 'h':
- usage(stdout, argv[0]);
- exit(EXIT_SUCCESS);
- default:
- usage(stderr, argv[0]);
- exit(EXIT_FAILURE);
+ int opti = 1;
+ while(opti < argc){
+ if(strcmp(argv[opti], "-h") == 0){
+ usage(stdout, argv[0]);
+ exit(EXIT_SUCCESS);
+ } else if(strcmp(argv[opti], "-p") == 0 && opti+1<argc){
+ port = atoi(argv[++opti]);
+ if(port < 1)
+ die("Port numbers are > 1\n");
+ } else {
+ usage(stderr, argv[0]);
+ exit(EXIT_FAILURE);
}
-
+ opti++;
}
open_filedescriptors();
+ write(fd, "\n", 1);
long cyclestart;
struct task *curtask;
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");
+ write(fd, "\n", 1);
}
return 0;
}