/* * This is the thread routine for taking input from * the user and placing it into the chat buffer. */ #include #include #include #include "chat.h" void AddToChatBuffer(struct chatbuff *G, struct linebuff *pMyLineBuff){ int mySlot ; pthread_mutex_lock(&G->nextSlotMutex) ; mySlot = G->nextSlot ; INCRSLOT(&G->nextSlot) ; /* Not releasing waiting readers until the buffer is filled * This could slow down processes that are "catching" up * By the way, the RW lock is only needed to deal with slow readers * who are about to be "lapped" */ pthread_rwlock_wrlock(&G->buffRWlock[mySlot]) ; bcopy((void *)pMyLineBuff,(void *)&G->buff[mySlot],sizeof(struct linebuff)); pthread_rwlock_unlock(&G->buffRWlock[mySlot]) ; pthread_cond_broadcast(&G->nextSlotConditional) ; pthread_mutex_unlock(&G->nextSlotMutex) ; } void *InputFromUser(void *ptArgs) { struct chatbuff * volatile G ; int mySock ; struct linebuff myLineBuff ; struct timeval present ; int userInputSize ; int stillConnected ; FILE *sockIn ; mySock = ((struct ptGenericArg *)ptArgs) -> sock ; G = ((struct ptGenericArg *)ptArgs) -> G ; free(ptArgs) ; if ((sockIn = fdopen(mySock, "r")) == (FILE *)NULL) { perror("fdopen") ; pthread_exit((void *)NULL) ; } stillConnected = 1 ; myLineBuff.status = MESSAGE ; while (stillConnected) { int nextC = 0 ; myLineBuff.size = 0 ; while (stillConnected && myLineBuff.size