readd input thread
This commit is contained in:
@@ -31,19 +31,19 @@ int row, col;
|
|||||||
char s[INET6_ADDRSTRLEN];
|
char s[INET6_ADDRSTRLEN];
|
||||||
char closed[] = "Connection closed.";
|
char closed[] = "Connection closed.";
|
||||||
|
|
||||||
/*
|
|
||||||
void *input(void *arg) {
|
void *input(void *arg) {
|
||||||
char msg[128];
|
char msg[128];
|
||||||
while (1) {
|
while (1) {
|
||||||
|
pthread_mutex_unlock(&sendmut);
|
||||||
memset(msg, 0, 128);
|
memset(msg, 0, 128);
|
||||||
printf("Typpe a message: ");
|
mvprintw(row - 1, 0, "Type a message: ");
|
||||||
fgets(msg, sizeof(msg), stdin);
|
getstr(msg);
|
||||||
pthread_mutex_lock(&sendmut);
|
|
||||||
ListAppend(sendlist, msg);
|
ListAppend(sendlist, msg);
|
||||||
pthread_mutex_unlock(&sendmut);
|
pthread_mutex_unlock(&sendmut);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void *output(void *arg) {
|
void *output(void *arg) {
|
||||||
char msg[128];
|
char msg[128];
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -61,16 +61,15 @@ void *output(void *arg) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void *sender(void *arg) {
|
void *sender(void *arg) {
|
||||||
char msg[128];
|
char msg[128];
|
||||||
int bytes;
|
int bytes;
|
||||||
char error[] = "pthread sender exit";
|
char error[] = "pthread sender exit";
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
memset(msg, 0, 128);
|
pthread_mutex_unlock(&sendmut);
|
||||||
mvprintw(row - 1, 0, "Type a message: ");
|
ListFirst(sendlist);
|
||||||
getstr(msg);
|
strcpy(msg, (char*)ListCurr(sendlist));
|
||||||
bytes = send(confd, msg, sizeof(msg), 0);
|
bytes = send(confd, msg, sizeof(msg), 0);
|
||||||
move(0, 0);
|
move(0, 0);
|
||||||
deleteln();
|
deleteln();
|
||||||
@@ -82,12 +81,14 @@ void *sender(void *arg) {
|
|||||||
refresh();
|
refresh();
|
||||||
if ((strncmp(msg, "/c", 2)) == 0) {
|
if ((strncmp(msg, "/c", 2)) == 0) {
|
||||||
pthread_cancel(receive_thread);
|
pthread_cancel(receive_thread);
|
||||||
|
pthread_cancel(input_thread);
|
||||||
pthread_exit(&closed);
|
pthread_exit(&closed);
|
||||||
}
|
}
|
||||||
if (bytes == -1) {
|
if (bytes == -1) {
|
||||||
perror("send");
|
perror("send");
|
||||||
pthread_exit(&error);
|
pthread_exit(&error);
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&sendmut);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -266,6 +267,7 @@ int main(int argc, char* argv[]) {
|
|||||||
getmaxyx(stdscr, row, col);
|
getmaxyx(stdscr, row, col);
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
|
|
||||||
|
pthread_create(&input_thread, NULL, input, NULL);
|
||||||
pthread_create(&send_thread, NULL, sender, NULL);
|
pthread_create(&send_thread, NULL, sender, NULL);
|
||||||
pthread_create(&receive_thread, NULL, receiver, NULL);
|
pthread_create(&receive_thread, NULL, receiver, NULL);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user