#include "unpthread.h" void *copyto(void *); struct args { int sockfd; FILE *fp; } ; typedef struct args argdef; void str_cli(FILE *fp_arg, int sockfd_arg) { char recvline[MAXLINE]; pthread_t tid; argdef argsstr; argsstr.sockfd = sockfd_arg; argsstr.fp = fp_arg; Pthread_create(&tid, NULL, copyto, &argsstr); while (Readline(argsstr.sockfd, recvline, MAXLINE) > 0) Fputs(recvline, stdout); } void * copyto(void *arg) { char sendline[MAXLINE]; argdef * argsstr = (argdef*) arg; while (Fgets(sendline, MAXLINE, argsstr->fp) != NULL) Writen(argsstr->sockfd, sendline, strlen(sendline)); Shutdown(argsstr->sockfd, SHUT_WR); /* EOF on stdin, send FIN */ return(NULL); /* 4return (i.e., thread terminates) when EOF on stdin */ }