This source file includes following definitions.
- main_writer_loop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 #include "test-nonblocking-misc.h"
56
57
58
59 static int
60 main_writer_loop (int test, size_t data_block_size, int fd,
61 bool has_large_buffer)
62 {
63 int too_small = 0;
64 unsigned char *data;
65
66
67 data = init_data (data_block_size);
68
69 switch (test)
70 {
71 TIMING_DECLS
72 ssize_t ret;
73
74 case 0:
75 case 2:
76 {
77 int saved_errno;
78
79 usleep (1000000);
80
81 dbgfprintf (stderr, "%s:1: >> write (%lu)\n", PROG_ROLE,
82 (unsigned long) (2 * data_block_size));
83 START_TIMING
84 ret = write (fd, data, 2 * data_block_size);
85 saved_errno = errno;
86 END_TIMING
87 dbgfprintf (stderr, "%s:1: << write -> %ld%s\n", PROG_ROLE,
88 (long) ret, dbgstrerror (ret < 0, saved_errno));
89 ASSERT (ret == 2 * data_block_size);
90 if (!has_large_buffer)
91 {
92
93 if (!(spent_time > 0.5))
94 {
95 fprintf (stderr,
96 "%s:1: spent_time = %g, data_block_size too small\n",
97 PROG_ROLE, spent_time);
98 too_small = 1;
99 }
100 }
101 ASSERT (spent_time < 1.5);
102 }
103 break;
104
105 case 1:
106 case 3:
107 {
108 size_t bytes_written;
109 int saved_errno;
110
111 usleep (1000000);
112
113 bytes_written = 0;
114 while (bytes_written < 2 * data_block_size)
115 {
116 dbgfprintf (stderr, "%s:2: >> write (%lu)\n", PROG_ROLE,
117 (unsigned long) (2 * data_block_size - bytes_written));
118 START_TIMING
119 ret = write (fd, data + bytes_written,
120 2 * data_block_size - bytes_written);
121 saved_errno = errno;
122 END_TIMING
123 dbgfprintf (stderr, "%s:2: << write -> %ld%s\n", PROG_ROLE,
124 (long) ret, dbgstrerror (ret < 0, saved_errno));
125 if (ret < 0 && bytes_written >= data_block_size)
126 {
127 ASSERT (saved_errno == EAGAIN || saved_errno == EWOULDBLOCK);
128 ASSERT (spent_time < 0.5);
129 break;
130 }
131
132
133 ASSERT (spent_time < 0.5);
134 if (ret < 0)
135 {
136 ASSERT (saved_errno == EAGAIN || saved_errno == EWOULDBLOCK);
137 usleep (SMALL_DELAY);
138 }
139 else
140 {
141
142 if (!(ret > 0))
143 {
144 fprintf (stderr,
145 "%s:1: spent_time = %g, data_block_size too small\n",
146 PROG_ROLE, spent_time);
147 too_small = 1;
148 }
149 bytes_written += ret;
150 }
151 }
152 ASSERT (bytes_written >= data_block_size);
153
154 while (bytes_written < 2 * data_block_size)
155 {
156 dbgfprintf (stderr, "%s:3: >> write (%lu)\n", PROG_ROLE,
157 (unsigned long) (2 * data_block_size - bytes_written));
158 START_TIMING
159 ret = write (fd, data + bytes_written,
160 2 * data_block_size - bytes_written);
161 saved_errno = errno;
162 END_TIMING
163 dbgfprintf (stderr, "%s:3: << write -> %ld%s\n", PROG_ROLE,
164 (long) ret, dbgstrerror (ret < 0, saved_errno));
165 ASSERT (spent_time < 0.5);
166 if (ret < 0)
167 {
168 ASSERT (saved_errno == EAGAIN || saved_errno == EWOULDBLOCK);
169 usleep (SMALL_DELAY);
170 }
171 else
172 {
173 ASSERT (ret > 0);
174 bytes_written += ret;
175 }
176 }
177 }
178 break;
179
180 default:
181 abort ();
182 }
183
184 free (data);
185 return too_small;
186 }