In step 3 the accept function opens a new connected

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ptor fd to memory location buf. A return value of ½ indicates an error, and a return value of ¼ indicates EOF. Otherwise, the return value indicates the number of bytes that were actually transferred. The write function copies at most count bytes from memory location buf to the current file position of descriptor fd. Figure 12.14 shows a program that uses read and write calls to copy the standard input to the standard output, one byte at a time. 12.4. UNIX FILE I/O 621 code/net/cpstdin.c 1 2 3 4 5 6 7 8 9 10 11 #include "csapp.h" int main(void) { char c; /* copy stdin to stdout, one byte at a time */ while(Read(STDIN_FILENO, &c, 1) != 0) Write(STDOUT_FILENO, &c, 1); exit(0); } code/net/cpstdin.c Figure 12.14: Copies standard input to standard output. 12.4.2 Robust File I/O With the readn and writen Functions. In some situations, read and write transfer fewer bytes than the application requests. Such short counts do not indicate an error, and can occur for a number of reasons: ¯ ¯ ¯ Encountering end-of-file on reads. If...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online