This preview shows page 1. Sign up to view the full content.
Unformatted text preview: the ﬁle 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-ﬁle) by returning a short count of zero. Reading text lines from a terminal. If the open ﬁle 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 ﬁle 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 inefﬁcient because it requires ¾Ò system calls. Instead, you should use the readn and writen functions from W. Richard Stevens’s classic network programming text .
#include "csapp.h" ssize t readn(int fd, void *buf, size t count); ssize t w...
View Full Document