- nread = read(socket, recvbuff, strlen(sendbuff));
- if (nread < 0) {
- printf("Errore in lettura %s\n", strerror(errno));
+ select(maxfd, &fset, NULL, NULL, NULL); /* wait for read ready */
+ if (FD_ISSET(fileno(filein), &fset)) { /* if ready on stdin */
+ if (fgets(sendbuff, MAXLINE, filein) == NULL) { /* if no input */
+ eof = 1; /* EOF on input */
+ shutdown(socket, SHUT_WR); /* close write half */
+ FD_CLR(fileno(filein), &fset); /* no more interest on stdin */
+ } else { /* else we have to write to socket */
+ nwrite = FullWrite(socket, sendbuff, strlen(sendbuff));
+ if (nwrite < 0) { /* on error stop */
+ printf("Errore in scrittura: %s", strerror(errno));
+ return;
+ }
+ }