/* * This is the thread routine for removing * items from the chat buffer and sending * them to the user. */ #include #include #include "chat.h" void *OutputToUser(void *ptArgs) { struct chatbuff * volatile G ; int mySock ; struct linebuff myLineBuff ; int myNextSlot ; int stillConnected ; FILE *sockOut ; mySock = ((struct ptGenericArg *)ptArgs) -> sock ; G = ((struct ptGenericArg *)ptArgs) -> G ; free(ptArgs) ; stillConnected = 1 ; myNextSlot = G->nextSlot ; if ((sockOut = fdopen(mySock, "w")) == (FILE *)NULL) { perror("fdopen") ; pthread_exit((void *)NULL) ; } while (stillConnected) { int i ; while (myNextSlot == G->nextSlot) { sleep(1) ; #ifdef DEBUG printf("nextSlot = %d, G->nextSlot = %d\n", myNextSlot, G->nextSlot) ; #endif } /* spinning */ bcopy((void *)&G->buff[myNextSlot], (void *)&myLineBuff, sizeof(struct linebuff)); for (i=0; i