24.1
|
Yes, in the first example, 2 bytes are sent with
a single urgent pointer that points to the byte following the
b. But in the second example (the two function calls),
first the a is sent with an urgent pointer that points
just beyond it, and this is followed by another TCP segment
containing the b with a different urgent pointer that
points just beyond it.
|
24.2
|
24.2
Figure E.16 shows the
version using poll.
Figure E.16
Version of Figure 24.6 using
poll instead of select.
oob/tcprecv03p.c
1 #include "unp.h"
2 int
3 main(int argc, char **argv)
4 {
5 int listenfd, connfd, n, justreadoob = 0;
6 char buff[100];
7 struct pollfd pollfd[1];
8 if (argc == 2)
9 listenfd = Tcp_listen(NULL, argv[1], NULL);
10 else if (argc == 3)
11 listenfd = Tcp_listen(argv[1], argv[2], NULL);
12 else
13 err_quit("usage: tcprecv03p [ <host> ] <port#>");
14 connfd = Accept(listenfd, NULL, NULL);
15 pollfd[0].fd = connfd;
16 pollfd[0].events = POLLRDNORM;
17 for ( ; ; ) {
18 if (justreadoob == 0)
19 pollfd[0].events|= POLLRDBAND;
20 Poll(pollfd, 1, INFTIM);
21 if (pollfd[0].revents & POLLRDBAND) {
22 n = Recv(connfd, buff, sizeof(buff) - 1, MSG_OOB);
23 buff[n] = 0; /* null terminate */
24 printf("read %d OOB byte: %s\n", n, buff);
25 justreadoob = 1;
26 pollfd[0].events &= ~POLLRDBAND; /* turn bit off */
27 }
28 if (pollfd[0].revents & POLLRDNORM) {
29 if ( (n = Read(connfd, buff, sizeof(buff) - 1)) == 0) {
30 printf("received EOF\n");
31 exit(0);
32 }
33 buff[n] = 0; /* null terminate */
34 printf("read %d bytes: %s\n", n, buff);
35 justreadoob = 0;
36 }
37 }
38 }
|