summaryrefslogtreecommitdiff
path: root/jet.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-11 21:09:08 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-11 21:09:08 -0300
commita193e6a9fee8760000561ba4fe1a6ec13ea0018d (patch)
treeadd6c1f7fe08fcf7c91e73a5bdf41e61bf7255c5 /jet.cpp
parente450b0d47e9d05a806769d096646d723845e0ba2 (diff)
downloadjet-a193e6a9fee8760000561ba4fe1a6ec13ea0018d.tar.gz
jet-a193e6a9fee8760000561ba4fe1a6ec13ea0018d.zip
Implement IPC using binary format
Diffstat (limited to 'jet.cpp')
-rw-r--r--jet.cpp26
1 files changed, 2 insertions, 24 deletions
diff --git a/jet.cpp b/jet.cpp
index 1ae3eeb..2006a77 100644
--- a/jet.cpp
+++ b/jet.cpp
@@ -1,6 +1,6 @@
#include <stdio.h>
-#include <string.h>
#include <stdint.h>
+#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -19,7 +19,6 @@
#include "client.cpp"
#define PORT 6969
-#define MAX_COMMAND_SIZE 128
#define MAX_EVENTS 10
int create_listener() {
@@ -32,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");
@@ -82,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();
}
}
}