6 concurrent servers 639 descriptor table the child

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: that it refreshes in MAXLINE-sized blocks. Variable read ptr points to the buffer byte to return to the caller, and variable read cnt is the number of bytes in the buffer that have yet to be returned to the caller. The function initiates a new block-read operation each time read cnt drops to zero (line 6). The readline function calls my read at most maxlen-1 times, terminating either when it encounters a newline character (line 30), when my read returns EOF (line 35), or when my read indicates an error (line 40). 12.4.4 The stat Function An application retrieves information about disk files by calling the stat function. 624 CHAPTER 12. NETWORK PROGRAMMING code/src/csapp.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 static ssize_t my_read(int fd, char *ptr) { static int read_cnt = 0; static char *read_ptr, read_buf[MAXLINE]; if (read_cnt <= 0) { again: if ( (read_cnt = read(fd, read_buf, sizeof(read_buf))) < 0) { if (errno == EINTR) goto again; return -1; } e...
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