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.
15 source_tcp(int sockfd
)
21 pattern(wbuf
, writelen
); /* fill send buffer with a pattern */
24 sleep_us(pauseinit
*1000);
26 for (i
= 1; i
<= nbuf
; i
++) {
29 if ( (n
= send(sockfd
, &oob
, 1, MSG_OOB
)) != 1)
30 err_sys("send of MSG_OOB returned %d, expected %d",
33 fprintf(stderr
, "wrote %d byte of urgent data\n", n
);
36 if ( (n
= write(sockfd
, wbuf
, writelen
)) != writelen
) {
38 err_ret("write returned %d, expected %d", n
, writelen
);
39 /* also call getsockopt() to clear so_error */
40 optlen
= sizeof(option
);
41 if (getsockopt(sockfd
, SOL_SOCKET
, SO_ERROR
,
42 &option
, &optlen
) < 0)
43 err_sys("SO_ERROR getsockopt error");
45 err_sys("write returned %d, expected %d", n
, writelen
);
48 fprintf(stderr
, "wrote %d bytes\n", n
);
51 sleep_us(pauserw
*1000);
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 */