This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[metaconfig.git] / U / perl / selectminbits.U
CommitLineData
959f3c4c
JH
1?RCS: $Id$
2?RCS:
3?RCS: Copyright (c) 1998, Jarkko Hietaniemi
0065f4af 4?RCS:
65a32477 5?RCS: You may redistribute only under the terms of the Artistic License,
959f3c4c
JH
6?RCS: as specified in the README file that comes with the distribution.
7?RCS: You may reuse parts of this distribution only within the terms of
65a32477 8?RCS: that same Artistic License; a copy of which may be found at the root
959f3c4c
JH
9?RCS: of the source tree for dist 3.0.
10?RCS:
2cb64bf6 11?MAKE:selectminbits: Compile cat rm_try Oldconfig d_select \
959f3c4c 12 i_time i_systime i_systimek i_sysselct selecttype d_socket \
f3dab845 13 byteorder Myread Setvar run i_stdlib ptrsize
959f3c4c
JH
14?MAKE: -pick add $@ %<
15?S:selectminbits:
16?S: This variable holds the minimum number of bits operated by select.
17?S: That is, if you do select(n, ...), how many bits at least will be
18?S: cleared in the masks if some activity is detected. Usually this
19?S: is either n or 32*ceil(n/32), especially many little-endians do
20?S: the latter. This is only useful if you have select(), naturally.
21?S:.
22?C:SELECT_MIN_BITS:
23?C: This symbol holds the minimum number of bits operated by select.
24?C: That is, if you do select(n, ...), how many bits at least will be
25?C: cleared in the masks if some activity is detected. Usually this
26?C: is either n or 32*ceil(n/32), especially many little-endians do
27?C: the latter. This is only useful if you have select(), naturally.
28?C:.
29?H:#define SELECT_MIN_BITS $selectminbits /**/
30?H:.
959f3c4c 31?T:bits
f3dab845 32?T:safebits
0065f4af 33?F:!try
959f3c4c
JH
34: check for the select 'width'
35case "$selectminbits" in
f3dab845
JH
36'') safebits=`expr $ptrsize \* 8`
37 case "$d_select" in
959f3c4c
JH
38 $define)
39 $cat <<EOM
40
41Checking to see on how many bits at a time your select() operates...
42EOM
43 $cat >try.c <<EOCP
44#include <sys/types.h>
45#$i_time I_TIME
46#$i_systime I_SYS_TIME
47#$i_systimek I_SYS_TIME_KERNEL
48#ifdef I_TIME
49# include <time.h>
50#endif
51#ifdef I_SYS_TIME
52# ifdef I_SYS_TIME_KERNEL
53# define KERNEL
54# endif
55# include <sys/time.h>
56# ifdef I_SYS_TIME_KERNEL
57# undef KERNEL
58# endif
59#endif
60#$i_sysselct I_SYS_SELECT
61#ifdef I_SYS_SELECT
62#include <sys/select.h>
63#endif
64#$d_socket HAS_SOCKET
65#ifdef HAS_SOCKET
66# include <sys/socket.h> /* Might include <sys/bsdtypes.h> */
67#endif
68#include <stdio.h>
3b148aa9
JH
69#$i_stdlib I_STDLIB
70#ifdef I_STDLIB
71#include <stdlib.h>
72#endif
959f3c4c
JH
73$selecttype b;
74#define S sizeof(*(b))
75#define MINBITS 64
76#define NBYTES (S * 8 > MINBITS ? S : MINBITS/8)
77#define NBITS (NBYTES * 8)
78int main() {
dc952a08 79 char *s = (char *)malloc(NBYTES);
959f3c4c
JH
80 struct timeval t;
81 int i;
82 FILE* fp;
83 int fd;
84
f3dab845
JH
85 if (!s)
86 exit(1);
959f3c4c
JH
87 fclose(stdin);
88 fp = fopen("try.c", "r");
89 if (fp == 0)
f3dab845 90 exit(2);
959f3c4c
JH
91 fd = fileno(fp);
92 if (fd < 0)
f3dab845 93 exit(3);
959f3c4c
JH
94 b = ($selecttype)s;
95 for (i = 0; i < NBITS; i++)
96 FD_SET(i, b);
97 t.tv_sec = 0;
98 t.tv_usec = 0;
99 select(fd + 1, b, 0, 0, &t);
100 for (i = NBITS - 1; i > fd && FD_ISSET(i, b); i--);
f3dab845 101 free(s);
959f3c4c
JH
102 printf("%d\n", i + 1);
103 return 0;
104}
105EOCP
106 set try
107 if eval $compile_ok; then
85f8323d 108 selectminbits=`$run ./try 2>/dev/null`
959f3c4c
JH
109 case "$selectminbits" in
110 '') cat >&4 <<EOM
111Cannot figure out on how many bits at a time your select() operates.
f3dab845 112I'll play safe and guess it is $safebits bits.
959f3c4c 113EOM
f3dab845
JH
114 selectminbits=$safebits
115 bits="$safebits bits"
959f3c4c
JH
116 ;;
117 1) bits="1 bit" ;;
118 *) bits="$selectminbits bits" ;;
119 esac
120 echo "Your select() operates on $bits at a time." >&4
121 else
122 rp='What is the minimum number of bits your select() operates on?'
123 case "$byteorder" in
f3dab845
JH
124 12345678) dflt=64 ;;
125 1234) dflt=32 ;;
959f3c4c
JH
126 *) dflt=1 ;;
127 esac
128 . ./myread
129 val=$ans
130 selectminbits="$val"
131 fi
2cb64bf6 132 $rm_try
959f3c4c
JH
133 ;;
134 *) : no select, so pick a harmless default
f3dab845 135 selectminbits=$safebits
959f3c4c
JH
136 ;;
137 esac
138 ;;
139esac
140