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.
13 void buffers(int sockfd
)
18 /* Allocate the read and write buffers. */
21 if ( (rbuf
= malloc(readlen
)) == NULL
)
22 err_sys("malloc error for read buffer");
26 if ( (wbuf
= malloc(writelen
)) == NULL
)
27 err_sys("malloc error for write buffer");
30 /* Set the socket send and receive buffer sizes (if specified).
31 The receive buffer size is tied to TCP's advertised window. */
34 if (setsockopt(sockfd
, SOL_SOCKET
, SO_RCVBUF
, &rcvbuflen
,
35 sizeof(rcvbuflen
)) < 0)
36 err_sys("SO_RCVBUF setsockopt error");
39 if (getsockopt(sockfd
, SOL_SOCKET
, SO_RCVBUF
, &n
, &optlen
) < 0)
40 err_sys("SO_RCVBUF getsockopt error");
42 err_quit("error: requested rcvbuflen = %d, resulting SO_RCVBUF = %d", rcvbuflen
, n
);
44 fprintf(stderr
, "SO_RCVBUF = %d\n", n
);
48 if (setsockopt(sockfd
, SOL_SOCKET
, SO_SNDBUF
, &sndbuflen
,
49 sizeof(sndbuflen
)) < 0)
50 err_sys("SO_SNDBUF setsockopt error");
53 if (getsockopt(sockfd
, SOL_SOCKET
, SO_SNDBUF
, &n
, &optlen
) < 0)
54 err_sys("SO_SNDBUF getsockopt error");
56 err_quit("error: requested sndbuflen = %d, resulting SO_SNDBUF = %d", sndbuflen
, n
);
58 fprintf(stderr
, "SO_SNDBUF = %d\n", n
);