diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-25 18:26:28 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-25 18:26:31 +0200 |
commit | 4d47a6cefe3c5ac022aa2e91033065a2354f4d19 (patch) | |
tree | ddc1f9778113d0bc1395bf321e8a685dc368d439 | |
parent | f56da4808343aafd2c8b76f6691dec33c16dd80c (diff) |
Documentation & chore
Includes:
- increase the limit
- update with sources
- remove arena include in send.c
-rw-r--r-- | v2/README.md | 41 | ||||
-rw-r--r-- | v2/chatty.c | 3 | ||||
-rw-r--r-- | v2/common.h | 7 | ||||
-rw-r--r-- | v2/send.c | 2 |
4 files changed, 31 insertions, 22 deletions
diff --git a/v2/README.md b/v2/README.md index 2f1e648..8ef1c6b 100644 --- a/v2/README.md +++ b/v2/README.md @@ -3,30 +3,27 @@ The idea is the following: - tcp server that you can send messages to - history upon connecting - date of messages sent -- authentication -- encrypted communication (tls?) - client for reading the messages and sending them at the same time - - rooms - encryption - authentication ## client -- wrapping messages -- prompt -- sending message +- [x] prompt +- [x] sending message - [x] bug: do not allow sending empty message +- [x] wrapping messages ## server -- log messages -- check if when sending and the client is offline (due to connection loss) what happens -- timeout on recv? +- [ ] log messages to file (save history) +- [ ] check if when sending and the client is offline (due to connection loss) what happens +- [ ] timeout on recv? ## common -- handle messages that are too large -- connect/disconnections messages -- use IP address / domain -- chat history +- [ ] handle messages that are too large +- [ ] connect/disconnections messages +- [ ] use IP address / domain +- [ ] chat history ## Protocol For now the protocol consists of sending Message type over the network, but in the future something @@ -37,9 +34,8 @@ more flexible might be required. Because it will make it easier to do things li - The null terminator must be sent with the string. - The text can be arbitrary length -- [ ] use char text[]; instead of char* -- todo: compression? +- [ ] compression ## Arena's 1. There is an arena for the messages' texts (`msgTextArena`) and an arena for the messages @@ -51,8 +47,23 @@ M.text = ArenaPush(msgTextArena, M.text_len); ``` Notice, that this depends on knowing the text's length before allocating the memory. +## Strings +- the length of a string (eg. `Message.text_len`) always **excludes** the null terminator unless stated explicitly +- the `#define *_LEN` are the max length **including** the null terminator ## Keybinds - `Ctrl+C` | `Ctrl+D`: quits - `Ctrl+U`: Erase input line - `Ctrl+W`: Erase word behind cursor + + +## Resources I used for building this +- source code I looked at: + - https://github.com/git-bruh/matrix-tui + - https://github.com/NikitaIvanovV/ictree + - https://github.com/termbox/termbox2 +- *mmap & gdb*: [Tsoding - "Why linux has this syscall?" ](https://youtu.be/sFYFuBzu9Ow?si=CX32IzFVA8OPDZvS) +- *pthreads*: [C for dummies](https://c-for-dummies.com/blog/?p=5365) +- *unicode and wide characters*: [C for dummies](https://c-for-dummies.com/blog/?p=2578) +- *sockets*: [Nir Lichtman - Making Minimalist Chat Server in C on Linux](https://www.youtube.com/watch?v=gGfTjKwLQxY) +- syscall manpages diff --git a/v2/chatty.c b/v2/chatty.c index 5697bcd..ddaae5c 100644 --- a/v2/chatty.c +++ b/v2/chatty.c @@ -428,8 +428,9 @@ int main(int argc, char **argv) } if (quit) break; + } - } else if (fds[FDS_RESIZE].revents & POLLIN) { + if (fds[FDS_RESIZE].revents & POLLIN) { tb_poll_event(&ev); } diff --git a/v2/common.h b/v2/common.h index 0f14329..60d8984 100644 --- a/v2/common.h +++ b/v2/common.h @@ -15,13 +15,10 @@ #define PORT 9983 // buffer size for holding data received from recv() // TODO: choose a good size -#define STREAM_BUF 256 +#define STREAM_BUF 1024 // max data received in one recv() call on serverfd // TODO: choose a good size -#define STREAM_LIMIT 512 -// max message that can be displayed with writef() -#define WRITEF_MAX 256 - +#define STREAM_LIMIT 1024 typedef uint8_t u8; typedef uint16_t u16; @@ -4,9 +4,9 @@ #include <assert.h> #include <stdarg.h> #include <string.h> +#include <stdlib.h> #include <unistd.h> -#include "arena.h" #include "common.h" int main(int argc, char **argv) |