Codenetechoclientc 1 2 3 4 5 6 7 8 9 10 11 12 13 14

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: the file contains only 20 more bytes and we are reading in 50byte chunks, then the current read will return a short count of 20. The next read will signal EOF (end-of-file) by returning a short count of zero. Reading text lines from a terminal. If the open file is associated with a terminal (i.e., a keyboard and display), then the read function will transfer the next text line. Reading and writing network sockets. If the open file corresponds to a network socket, then internal buffering constraints and long network delays can cause read and write to return short counts. Robust applications in general, and network applications in particular, must anticipate and deal with short counts. In Figure 12.14 we skirted this issue by transferring one byte at a time. While technically correct, this approach is grossly inefficient because it requires ¾Ò system calls. Instead, you should use the readn and writen functions from W. Richard Stevens’s classic network programming text [77]. #include "csapp.h" ssize t readn(int fd, void *buf, size t count); ssize t w...
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