From e450b0d47e9d05a806769d096646d723845e0ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 11 Jul 2020 12:13:59 -0300 Subject: Make client side ipc binary --- jet2.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'jet2.cpp') diff --git a/jet2.cpp b/jet2.cpp index 729fbc7..994ba14 100644 --- a/jet2.cpp +++ b/jet2.cpp @@ -1,5 +1,4 @@ #include -#include #include #include @@ -9,6 +8,8 @@ #include #include +#include "ipc.cpp" + #define NORMAL_MODE 0 #define INSERT_MODE 1 #define PORT 6969 @@ -27,7 +28,6 @@ int main(int argc, char *argv[]) { char *view = new char[window_width * window_height]; for (int i = 0; i < window_width * window_height; view[i++] = 0); - int s = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr = { AF_INET, htons(PORT), htonl(INADDR_LOOPBACK)}; connect(s, (sockaddr *) &addr, sizeof(sockaddr_in)); @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) { clear(); char msg[32] = {}; - int len = sprintf(msg, " %d %d show ", window_width, window_height); + int len = sprintf(msg, "%d%d%d%d%d", OP_I4, window_width, OP_I4, window_height, OP_SHOW); write(s, msg, len); read(s, view, window_width * window_height); for (int i = 0; i < window_width * window_height; i++) { @@ -57,11 +57,11 @@ int main(int argc, char *argv[]) { mode = INSERT_MODE; break; case 'h': - len = sprintf(msg, " -1 move "); + len = sprintf(msg, "%d%d%d", OP_I1, -1, OP_MOVE); write(s, msg, len); break; case 'l': - len = sprintf(msg, " 1 move "); + len = sprintf(msg, "%d%d%d", OP_I1, 1, OP_MOVE); write(s, msg, len); break; } @@ -71,11 +71,11 @@ int main(int argc, char *argv[]) { mode = NORMAL_MODE; break; case KEY_BACKSPACE: - len = sprintf(msg, " pop "); + len = sprintf(msg, "%d", OP_DELETE); write(s, msg, len); break; default: - len = sprintf(msg, " %d push ", input); + len = sprintf(msg, "%d%d%d", OP_I1, input, OP_INSERT); write(s, msg, len); } } -- cgit v1.2.3 From a193e6a9fee8760000561ba4fe1a6ec13ea0018d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 11 Jul 2020 21:09:08 -0300 Subject: Implement IPC using binary format --- jet2.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'jet2.cpp') diff --git a/jet2.cpp b/jet2.cpp index 994ba14..1a088dd 100644 --- a/jet2.cpp +++ b/jet2.cpp @@ -38,15 +38,19 @@ int main(int argc, char *argv[]) { while (!quit) { clear(); - char msg[32] = {}; - int len = sprintf(msg, "%d%d%d%d%d", OP_I4, window_width, OP_I4, window_height, OP_SHOW); - write(s, msg, len); + uint8_t msg[5]; + msg[0] = OP_SHOW; + encode2(window_width, msg, 1); + encode2(window_height, msg, 3); + write(s, msg, 5); read(s, view, window_width * window_height); for (int i = 0; i < window_width * window_height; i++) { printw("%c", view[i]); } - memset(msg, 0, 32); + uint8_t mov[2]; + uint8_t del[1]; + uint8_t ins[2]; int input = getch(); if (mode == NORMAL_MODE) { switch (input) { @@ -57,12 +61,14 @@ int main(int argc, char *argv[]) { mode = INSERT_MODE; break; case 'h': - len = sprintf(msg, "%d%d%d", OP_I1, -1, OP_MOVE); - write(s, msg, len); + mov[0] = OP_MOVE1; + mov[1] = -1; + write(s, mov, 2); break; case 'l': - len = sprintf(msg, "%d%d%d", OP_I1, 1, OP_MOVE); - write(s, msg, len); + mov[0] = OP_MOVE1; + mov[1] = 1; + write(s, mov, 2); break; } } else { @@ -71,12 +77,13 @@ int main(int argc, char *argv[]) { mode = NORMAL_MODE; break; case KEY_BACKSPACE: - len = sprintf(msg, "%d", OP_DELETE); - write(s, msg, len); + del[0] = OP_DELETE; + write(s, del, 1); break; default: - len = sprintf(msg, "%d%d%d", OP_I1, input, OP_INSERT); - write(s, msg, len); + ins[0] = OP_INSERT; + ins[1] = input; + write(s, ins, 2); } } } -- cgit v1.2.3 From d4cc43aa36c6522aeb170ff46dc25ce50085e75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 11 Jul 2020 21:31:36 -0300 Subject: Update build params --- jet2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'jet2.cpp') diff --git a/jet2.cpp b/jet2.cpp index 1a088dd..fc4fcaa 100644 --- a/jet2.cpp +++ b/jet2.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include -- cgit v1.2.3