From: Mart Lubbers Date: Sun, 11 Dec 2016 19:28:18 +0000 (+0100) Subject: tcp toegevoegd X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=8bd3b26a870ee17a687c54e5e7b6d4c1c7bf808a;p=mTask.git tcp toegevoegd --- diff --git a/int/int.c b/int/int.c index fd54153..a2dd745 100644 --- a/int/int.c +++ b/int/int.c @@ -1,10 +1,14 @@ -#include +#include +#include +#include #include +#include +#include #include -#include #include +#include +#include #include -#include #include "mTaskSymbols.h" @@ -25,6 +29,8 @@ char tasks[MAXTASKS][MAXTASKSIZE] = {0}; bool tasks_used[MAXTASKS] = {0}; +int sock_fd = -1; +int fd = -1; void killHandler(int i) { @@ -190,14 +196,32 @@ void run_task(char *program) } } +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"); @@ -206,10 +230,12 @@ int main(void) 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