1 /* Test for nonblocking read and write.
3 Copyright (C) 2011-2020 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* A data block ought to be larger than the size of the in-kernel buffer.
19 Working values of SOCKET_DATA_BLOCK_SIZE, depending on kernel:
21 Platform SOCKET_DATA_BLOCK_SIZE
23 Linux >= 7350000 (depends on circumstances)
24 Linux/Android >= 1700000 (approx.)
26 OpenBSD >= 106430 (depends on circumstances)
27 Mac OS X >= 680000 (depends on circumstances)
29 AIX 7.1 >= 200000 (depends on circumstances)
33 Solaris 7 >= 63000 (depends on circumstances)
37 Solaris 11 2010-11 >= 73729
38 Cygwin 1.5.x >= 66294401 but then write() fails with ENOBUFS
39 Cygwin 1.7.x >= 163838 (depends on circumstances)
40 native Windows >= 66294401
42 #define SOCKET_DATA_BLOCK_SIZE 1000000
44 /* On Linux, Mac OS X, Cygwin 1.5.x, native Windows,
45 sockets have very large buffers in the kernel, so that write() calls
46 succeed before the reader has started reading, even if fd is blocking
47 and the amount of data is larger than 1 MB. */
48 #if defined __linux__ || defined __ANDROID__ || (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __CYGWIN__
49 # define SOCKET_HAS_LARGE_BUFFER 1
51 # define SOCKET_HAS_LARGE_BUFFER 0