added way to exit client

This commit is contained in:
Václav Šmejkal 2023-02-20 19:09:55 +01:00
parent 5b855d21bd
commit 62fc06ab52
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 7 additions and 0 deletions

View File

@ -44,6 +44,8 @@ int main(void)
printf("%s\n", line);
send_socket(line, listen_socket);
if (strcmp(line, "!exit") == 0) break; //USER REQUESTED PROGRAM EXIT
}
free(line); //TODO: Unreachable; add exit

View File

@ -18,6 +18,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/chat/common.h>
#include <unistd.h>
char *read_socket(int socket);
void *communicate_thread(void *arg);
@ -68,11 +70,14 @@ void *communicate_thread(void *arg)
if (received == NULL) return NULL; //FAILED; EXIT THREAD
if (strcmp(received, "!exit") == 0) break; //USER REQUESTED PROGRAM EXIT
printf("Received:\n%s\n\n", received);
why2_deallocate(received);
}
close(*((int*) arg));
return NULL;
}