-#include <stdio.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <signal.h>
#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <signal.h>
#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <stdint.h>
#include "mTaskSymbols.h"
char tasks[MAXTASKS][MAXTASKSIZE] = {0};
bool tasks_used[MAXTASKS] = {0};
+int sock_fd = -1;
+int fd = -1;
void killHandler(int i)
{
}
}
+void open_filedescriptors()
+{
+ struct sockaddr_in sa;
+
+ bzero((char *) &sa, sizeof(sa));
+ sa.sin_family = AF_INET;
+ sa.sin_addr.s_addr = INADDR_ANY;
+ sa.sin_port = htons(8124);
+
+ 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");
+ if(listen(sock_fd, 10) == -1)
+ pdie("bind\n");
+
+ printf("Listinging on 8123\n");
+ fflush(stdout);
+ if((fd = accept(sock_fd, (struct sockaddr*)NULL, NULL)) == -1)
+ pdie("accept");
+}
+
int main(void)
{
- int fd_in, fd_out;
int ct;
- fd_in = fileno(stdin);
- fd_out = fileno(stdout);
-
//Register signal handler
if(signal(SIGINT, killHandler) == SIG_ERR){
die("Couldn't register signal handler...\n");
die("Couldn't register signal handler...\n");
}
+ open_filedescriptors();
+
while(true){
//Check for new tasks
- if(input_available(fd_in)){
- read_message(fd_in, fd_out);
+ if(input_available(fd)){
+ read_message(fd, fd);
}
//Run tasks
for(ct = 0; ct<MAXTASKS; ct++){