diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-11 21:37:42 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-11 21:37:42 -0300 |
commit | 13fdfe875efdfb33d392c5e634ceff494962e7dc (patch) | |
tree | 48e6d89b63f9af3a14d2ef4564f1c7cdceef77d5 /jet.cpp | |
parent | 880047d09eb4b9a448a5817699422abc6f07b5d6 (diff) | |
parent | 291748a56824f77b137c66e9879ec0a4ecb14ced (diff) | |
download | jet-13fdfe875efdfb33d392c5e634ceff494962e7dc.tar.gz jet-13fdfe875efdfb33d392c5e634ceff494962e7dc.zip |
Merge pull request #10 from jmtomas/4
Diffstat (limited to 'jet.cpp')
-rw-r--r-- | jet.cpp | 30 |
1 files changed, 6 insertions, 24 deletions
@@ -1,6 +1,7 @@ -#include <stdlib.h> #include <stdio.h> +#include <stdint.h> #include <string.h> +#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> @@ -11,11 +12,13 @@ #include <unistd.h> #include <sys/epoll.h> +#include "ipc.cpp" +#include "page.cpp" #include "buffer.cpp" +#include "point.cpp" #include "client.cpp" #define PORT 6969 -#define MAX_COMMAND_SIZE 128 #define MAX_EVENTS 10 int create_listener() { @@ -28,24 +31,6 @@ int create_listener() { return s; } -void parse_command(char *command, Client *client) { - char *token = strtok(command, " \n"); - while (token) { - if (strcmp(token, "show") == 0) { - client->show(); - } else if (strcmp(token, "move") == 0) { - client->move(); - } else if (strcmp(token, "push") == 0) { - client->push(); - } else if (strcmp(token, "pop") == 0) { - client->pop(); - } else { - client->args.push(atoi(token)); - } - token = strtok(0, " \n"); - } -} - int main() { Buffer scratch("scratch"); scratch.read_file("LICENSE"); @@ -78,10 +63,7 @@ int main() { clients[clientfd] = c; epoll_ctl(epollfd, EPOLL_CTL_ADD, clientfd, &ev); } else { - char command[MAX_COMMAND_SIZE] = {}; - int clientfd = events[i].data.fd; - read(clientfd, command, MAX_COMMAND_SIZE - 1); - parse_command(command, clients[clientfd]); + clients[events[i].data.fd]->parse_message(); } } } |