1 /* -*- c-basic-offset: 8; -*-
3 * Copyright (c) 1993 W. Richard Stevens. All rights reserved.
4 * Permission to use or modify this software and its documentation only for
5 * educational purposes and without fee is hereby granted, provided that
6 * the above copyright notice appear in all copies. The author makes no
7 * representations about the suitability of this software for any purpose.
8 * It is provided "as is" without express or implied warranty.
20 sleep_us(pauseinit
*1000);
22 for ( ; ; ) { /* read until peer closes connection; -n opt ignored */
23 /* msgpeek = 0 or MSG_PEEK */
26 if ( (n
= recv(sockfd
, rbuf
, readlen
, flags
)) < 0) {
27 err_sys("recv error");
31 fprintf(stderr
, "connection closed by peer\n");
34 #ifdef notdef /* following not possible with TCP */
35 } else if (n
!= readlen
)
36 err_quit("read returned %d, expected %d", n
, readlen
);
42 fprintf(stderr
, "received %d bytes%s\n", n
,
43 (flags
== MSG_PEEK
) ? " (MSG_PEEK)" : "");
46 sleep_us(pauserw
*1000);
49 flags
= 0; /* no infinite loop */
50 goto oncemore
; /* read the message again */
54 if (pauseclose
) { /* pausing here puts peer into FIN_WAIT_2 */
56 fprintf(stderr
, "pausing before close\n");
57 sleep_us(pauseclose
*1000);
60 if (close(sockfd
) < 0)
61 err_sys("close error"); /* since SO_LINGER may be set */