added command to close connection between users

This commit is contained in:
2025-08-07 16:59:26 -06:00
parent 71835bf84a
commit 73193c93d9
+11 -6
View File
@@ -23,6 +23,7 @@
#define BACKLOG 10 #define BACKLOG 10
LIST *receivelist, *sendlist; LIST *receivelist, *sendlist;
pthread_t input_thread, send_thread, receive_thread, output_thread;
pthread_mutex_t sendmut, receivemut; pthread_mutex_t sendmut, receivemut;
int sockfd, confd, client; int sockfd, confd, client;
char *remote_machine, *local_port, *remote_port; char *remote_machine, *local_port, *remote_port;
@@ -79,7 +80,8 @@ void *sender(void *arg) {
move(row - 1, 0); move(row - 1, 0);
clrtoeol(); clrtoeol();
refresh(); refresh();
if ((strncmp(msg, "/c", 3)) == 0) { if ((strncmp(msg, "/c", 2)) == 0) {
pthread_cancel(receive_thread);
pthread_exit(&closed); pthread_exit(&closed);
} }
if (bytes == -1) { if (bytes == -1) {
@@ -98,6 +100,10 @@ void *receiver(void *arg) {
memset(buf, 0, 128); memset(buf, 0, 128);
bytes = recv(confd, buf, 128, 0); bytes = recv(confd, buf, 128, 0);
buf[bytes] = '\0'; buf[bytes] = '\0';
if ((strncmp(buf, "/c", 2)) == 0) {
pthread_cancel(send_thread);
pthread_exit(&closed);
}
if (bytes != -1) { if (bytes != -1) {
move(0, 0); move(0, 0);
deleteln(); deleteln();
@@ -115,9 +121,7 @@ void *receiver(void *arg) {
pthread_exit(&error); pthread_exit(&error);
} }
if ((strncmp(buf, "/c", 3)) == 0) {
pthread_exit(&closed);
}
} }
return 0; return 0;
@@ -132,7 +136,6 @@ void *get_in_addr(struct sockaddr *sa) {
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
pthread_t input_thread, send_thread, receive_thread, output_thread;
socklen_t sin_size; socklen_t sin_size;
struct addrinfo *p, *q; struct addrinfo *p, *q;
struct addrinfo hints; struct addrinfo hints;
@@ -270,7 +273,9 @@ int main(int argc, char* argv[]) {
pthread_join(receive_thread, NULL); pthread_join(receive_thread, NULL);
close(sockfd); close(sockfd);
close(confd); close(confd);
refresh();
endwin(); endwin();
return 0; printf("Connection closed.\n");
return 0;
} }