From 51f646eae8cde2dc1ad844866e1ba802f534dd85 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sat, 26 Oct 2024 02:21:27 +0200 Subject: fixed bug when sending message after disconnect This is because for sending, receiving & closing serverfd variable was used instead of `fds[FDS_SERVER].fd`. --- v2/README.md | 2 +- v2/chatty.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/v2/README.md b/v2/README.md index 7b1a617..8e45866 100644 --- a/v2/README.md +++ b/v2/README.md @@ -13,7 +13,7 @@ The idea is the following: - [x] sending message - [x] bug: do not allow sending empty message - [x] wrapping messages -- [ ] bug: when sending message after diconnect (serverfd?) +- [x] bug: when sending message after diconnect (serverfd?) ## server - [ ] log messages to file (save history) diff --git a/v2/chatty.c b/v2/chatty.c index 3c26f66..68f6e87 100644 --- a/v2/chatty.c +++ b/v2/chatty.c @@ -356,7 +356,7 @@ int main(int argc, char **argv) u8 timestamp[TIMESTAMP_LEN]; message_timestamp(timestamp); - nrecv = recv(serverfd, buf, STREAM_LIMIT, 0); + nrecv = recv(fds[FDS_SERVER].fd, buf, STREAM_LIMIT, 0); assert(nrecv != -1); // TODO: Handle this in a thread, the best way would be @@ -365,7 +365,7 @@ int main(int argc, char **argv) // -> try to reconnect in background if (nrecv == 0) { // close diconnected server's socket - err = close(serverfd); + err = close(fds[FDS_SERVER].fd); assert(err == 0); fds[FDS_SERVER].fd = -1; // ignore // start trying to reconnect in a thread @@ -439,7 +439,7 @@ int main(int argc, char **argv) // copy everything but the text memcpy(buf, sendmsg, AUTHOR_LEN + TIMESTAMP_LEN + sizeof(wchar_t)); memcpy(&mbuf->text, input, input_len * sizeof(wchar_t)); - nsend = send(serverfd, buf, AUTHOR_LEN + TIMESTAMP_LEN + input_len * sizeof(wchar_t), 0); + nsend = send(fds[FDS_SERVER].fd, buf, AUTHOR_LEN + TIMESTAMP_LEN + input_len * sizeof(wchar_t), 0); assert(nsend > 0); case TB_KEY_CTRL_U: // clear input -- cgit v1.2.3