vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / sock / sourcetcp.c
blobc9a93c60137688e5f0f0a7c2ed57285aa8836f49
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.
9 */
11 #include <stdio.h>
12 #include "sock.h"
14 void
15 source_tcp(int sockfd)
17 int i, n, option;
18 socklen_t optlen;
19 char oob;
21 pattern(wbuf, writelen); /* fill send buffer with a pattern */
23 if (pauseinit)
24 sleep_us(pauseinit*1000);
26 for (i = 1; i <= nbuf; i++) {
27 if (urgwrite == i) {
28 oob = urgwrite;
29 if ( (n = send(sockfd, &oob, 1, MSG_OOB)) != 1)
30 err_sys("send of MSG_OOB returned %d, expected %d",
31 n, writelen);
32 if (verbose)
33 fprintf(stderr, "wrote %d byte of urgent data\n", n);
36 if ( (n = write(sockfd, wbuf, writelen)) != writelen) {
37 if (ignorewerr) {
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");
44 } else
45 err_sys("write returned %d, expected %d", n, writelen);
47 } else if (verbose)
48 fprintf(stderr, "wrote %d bytes\n", n);
50 if (pauserw)
51 sleep_us(pauserw*1000);
54 if (pauseclose) {
55 if (verbose)
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 */