Lines Matching +full:write +full:- +full:1

1 /*-
8 * 1. Redistributions of source code must retain the above copyright
50 * - If there's no data to read, then for blocking fifos, we block, and for
51 * non-blocking, we return EAGAIN.
53 * - If we write ten bytes, ten bytes can be read, and they're the same
56 * - If we write two batches of five bytes, we can read the same ten bytes in
59 * - If we write ten bytes, we can read the same ten bytes in two reads of
62 * - If we over-fill a buffer (by writing 512k, which we take to be a large
65 * - That once 512k (ish) is read from the other end, the blocked writer
68 * - When a fifo is empty, poll, select, kqueue, and fionread report it is
71 * - When a fifo has data in it, poll, select, and kqueue report that it is
74 * - XXX: blocked reader semantics?
76 * - XXX: event behavior on remote close?
103 err(-1, "%s: makefifo: mkfifo: %s", testname, fifoname); in makefifo()
110 if (fd1 != -1) in cleanfifo2()
112 if (fd2 != -1) in cleanfifo2()
121 if (fd3 != -1) in cleanfifo3()
127 * Open two different file descriptors for a fifo: one read, one write. Do
128 * so using non-blocking opens in order to avoid deadlocking the process.
137 return (-1); in openfifo()
143 return (-1); in openfifo()
152 * Open one file descriptor for the fifo, supporting both read and write.
161 return (-1); in openfifo_rw()
175 return(-1); in set_nonblocking()
182 return (-1); in set_nonblocking()
196 return(-1); in set_blocking()
203 return (-1); in set_blocking()
220 return (-1); in drain_fd()
229 return (-1); in drain_fd()
233 return (-1); in drain_fd()
237 * Simple I/O test: write ten integers, and make sure we get back the same
252 cleanfifo2("testfifo", -1, -1); in test_simpleio()
253 exit(-1); in test_simpleio()
259 len = write(writer_fd, (char *)buffer, sizeof(buffer)); in test_simpleio()
261 warn("test_simpleio: write"); in test_simpleio()
263 exit(-1); in test_simpleio()
269 exit(-1); in test_simpleio()
276 exit(-1); in test_simpleio()
282 exit(-1); in test_simpleio()
287 warnx("test_simpleio: write byte %d as 0x%02x, but read " in test_simpleio()
290 exit(-1); in test_simpleio()
298 * Non-destructive SIGALRM handler.
304 alarm_fired = 1; in sigalarm()
308 * Wrapper function for write, which uses a timer to interrupt any blocking.
325 return (-1); in timed_write()
328 written_len = write(fd, data, len); in timed_write()
333 return (-1); in timed_write()
336 *timedoutp = 1; in timed_write()
342 return (-1); in timed_write()
365 return (-1); in timed_read()
373 return (-1); in timed_read()
376 *timedoutp = 1; in timed_read()
382 return (-1); in timed_read()
388 * This test operates on blocking and non-blocking fifo file descriptors, in
390 * mean: don't block for non-blocking sockets, and do block for blocking
411 cleanfifo2("testfifo", -1, -1); in test_blocking_read_empty()
412 exit(-1); in test_blocking_read_empty()
421 exit(-1); in test_blocking_read_empty()
426 if (ret != -1) { in test_blocking_read_empty()
430 exit(-1); in test_blocking_read_empty()
435 exit(-1); in test_blocking_read_empty()
439 * Read one byte from an empty non-blocking fifo, return EAGAIN as in test_blocking_read_empty()
444 exit(-1); in test_blocking_read_empty()
449 if (ret != -1) { in test_blocking_read_empty()
453 exit(-1); in test_blocking_read_empty()
458 exit(-1); in test_blocking_read_empty()
465 * Write one byte to an empty fifo, then try to read one byte and make sure
466 * we don't block in either the write or the read. This tests both for
479 cleanfifo2("testfifo", -1, -1); in test_blocking_one_byte()
480 exit(-1); in test_blocking_one_byte()
485 exit(-1); in test_blocking_one_byte()
489 exit(-1); in test_blocking_one_byte()
498 exit(-1); in test_blocking_one_byte()
501 warnx("test_blocking_one_byte: timed_write: tried to write " in test_blocking_one_byte()
504 exit(-1); in test_blocking_one_byte()
513 exit(-1); in test_blocking_one_byte()
519 exit(-1); in test_blocking_one_byte()
525 exit(-1); in test_blocking_one_byte()
532 * Write one byte to an empty fifo, then try to read one byte and make sure
545 cleanfifo2("testfifo", -1, -1); in test_nonblocking_one_byte()
546 exit(-1); in test_nonblocking_one_byte()
551 exit(-1); in test_nonblocking_one_byte()
560 exit(-1); in test_nonblocking_one_byte()
563 warnx("test_nonblocking_one_byte: timed_write: tried to write " in test_nonblocking_one_byte()
566 exit(-1); in test_nonblocking_one_byte()
575 exit(-1); in test_nonblocking_one_byte()
581 exit(-1); in test_nonblocking_one_byte()
587 exit(-1); in test_nonblocking_one_byte()
594 * First of two test cases involving a 512K buffer: write the buffer into a
597 * write.
609 cleanfifo2("testfifo", -1, -1); in test_blocking_partial_write()
610 exit(-1); in test_blocking_partial_write()
615 exit(-1); in test_blocking_partial_write()
622 exit(-1); in test_blocking_partial_write()
632 exit(-1); in test_blocking_partial_write()
640 exit(-1); in test_blocking_partial_write()
647 exit(-1); in test_blocking_partial_write()
654 * Write a 512K buffer to an empty fifo using a non-blocking file descriptor,
667 cleanfifo2("testfifo", -1, -1); in test_nonblocking_partial_write()
668 exit(-1); in test_nonblocking_partial_write()
673 exit(-1); in test_nonblocking_partial_write()
680 exit(-1); in test_nonblocking_partial_write()
690 exit(-1); in test_nonblocking_partial_write()
695 "non-blocking socket timed out"); in test_nonblocking_partial_write()
698 exit(-1); in test_nonblocking_partial_write()
706 exit(-1); in test_nonblocking_partial_write()
713 exit(-1); in test_nonblocking_partial_write()
734 cleanfifo2("testfifo", -1, -1); in test_coalesce_big_read()
735 exit(-1); in test_coalesce_big_read()
738 /* Write five, write five, read ten. */ in test_coalesce_big_read()
742 len = write(writer_fd, buffer, 5); in test_coalesce_big_read()
744 warn("test_coalesce_big_read: write 5"); in test_coalesce_big_read()
746 exit(-1); in test_coalesce_big_read()
749 warnx("test_coalesce_big_read: write 5 wrote %zd", len); in test_coalesce_big_read()
751 exit(-1); in test_coalesce_big_read()
754 len = write(writer_fd, buffer + 5, 5); in test_coalesce_big_read()
756 warn("test_coalesce_big_read: write 5"); in test_coalesce_big_read()
758 exit(-1); in test_coalesce_big_read()
761 warnx("test_coalesce_big_read: write 5 wrote %zd", len); in test_coalesce_big_read()
763 exit(-1); in test_coalesce_big_read()
770 exit(-1); in test_coalesce_big_read()
775 exit(-1); in test_coalesce_big_read()
784 exit(-1); in test_coalesce_big_read()
787 cleanfifo2("testfifo", -1, -1); in test_coalesce_big_read()
792 * message boundaries by performing one big write, then two smaller reads
793 * that should return sequential elements of data from the write.
805 cleanfifo2("testfifo", -1, -1); in test_coalesce_big_write()
806 exit(-1); in test_coalesce_big_write()
809 /* Write ten, read five, read five. */ in test_coalesce_big_write()
813 len = write(writer_fd, buffer, 10); in test_coalesce_big_write()
815 warn("test_coalesce_big_write: write 10"); in test_coalesce_big_write()
817 exit(-1); in test_coalesce_big_write()
820 warnx("test_coalesce_big_write: write 10 wrote %zd", len); in test_coalesce_big_write()
822 exit(-1); in test_coalesce_big_write()
829 exit(-1); in test_coalesce_big_write()
834 exit(-1); in test_coalesce_big_write()
841 exit(-1); in test_coalesce_big_write()
846 exit(-1); in test_coalesce_big_write()
855 exit(-1); in test_coalesce_big_write()
858 cleanfifo2("testfifo", -1, -1); in test_coalesce_big_write()
865 struct pollfd fds[1]; in poll_status()
871 if (poll(fds, 1, 0) < 0) { in poll_status()
873 return (-1); in poll_status()
875 *readable = (fds[0].revents & POLLIN) ? 1 : 0; in poll_status()
876 *writable = (fds[0].revents & POLLOUT) ? 1 : 0; in poll_status()
877 *exception = (fds[0].revents & POLLERR) ? 1 : 0; in poll_status()
896 if (select(fd+1, &readfds, &writefds, &exceptfds, &timeout) < 0) { in select_status()
898 return (-1); in select_status()
900 *readable = FD_ISSET(fd, &readfds) ? 1 : 0; in select_status()
901 *writable = FD_ISSET(fd, &writefds) ? 1 : 0; in select_status()
902 *exception = FD_ISSET(fd, &exceptfds) ? 1 : 0; in select_status()
907 * Given an existing kqueue, set up read and write event filters for the
909 * once for the write endpoint.
924 EV_SET(&kevent_changelist[1], fd, EVFILT_WRITE, EV_ADD, 0, 0, 0); in kqueue_setup()
931 return (-1); in kqueue_setup()
939 if (kp->flags != EV_ERROR) in kqueue_setup()
941 errno = kp->data; in kqueue_setup()
944 return (-1); in kqueue_setup()
965 return (-1); in kqueue_status()
971 if (kp->ident != (u_int)fd) in kqueue_status()
973 if (kp->filter == EVFILT_READ) in kqueue_status()
974 *readable = 1; in kqueue_status()
975 if (kp->filter == EVFILT_WRITE) in kqueue_status()
976 *writable = 1; in kqueue_status()
989 return (-1); in fionread_status()
993 *readable = 1; in fionread_status()
999 #define READABLE 1
1000 #define WRITABLE 1
1001 #define EXCEPTION 1
1015 return (-1); in assert_status()
1021 return (-1); in assert_status()
1025 return (-1); in assert_status()
1031 return (-1); in assert_status()
1036 return (-1); in assert_status()
1042 return (-1); in assert_status()
1046 return (-1); in assert_status()
1051 return (-1); in assert_status()
1074 cleanfifo2("testfifo", -1, -1); in test_events_outofbox()
1075 exit(-1); in test_events_outofbox()
1082 exit(-1); in test_events_outofbox()
1087 exit(-1); in test_events_outofbox()
1092 exit(-1); in test_events_outofbox()
1096 * Make sure that fresh, out-of-the-box fifo file descriptors have in test_events_outofbox()
1099 * a read-only descriptor), and there's no reason for error yet. in test_events_outofbox()
1104 exit(-1); in test_events_outofbox()
1108 * Make sure that fresh, out-of-the-box fifo file descriptors have in test_events_outofbox()
1109 * good initial states. The writer_fd should be ready to write. in test_events_outofbox()
1114 exit(-1); in test_events_outofbox()
1130 cleanfifo2("testfifo", -1, -1); in test_events_write_read_byte()
1131 exit(-1); in test_events_write_read_byte()
1138 exit(-1); in test_events_write_read_byte()
1143 exit(-1); in test_events_write_read_byte()
1148 exit(-1); in test_events_write_read_byte()
1152 * Write a byte to the fifo, and make sure that the read end becomes in test_events_write_read_byte()
1153 * readable, and that the write end remains writable (small write). in test_events_write_read_byte()
1156 len = write(writer_fd, &ch, sizeof(ch)); in test_events_write_read_byte()
1158 warn("%s: write", __func__); in test_events_write_read_byte()
1160 exit(-1); in test_events_write_read_byte()
1164 NOT_EXCEPTION, __func__, "write", "reader_fd") < 0) { in test_events_write_read_byte()
1166 exit(-1); in test_events_write_read_byte()
1173 NOT_EXCEPTION, __func__, "write", "writer_fd") < 0) { in test_events_write_read_byte()
1175 exit(-1); in test_events_write_read_byte()
1186 exit(-1); in test_events_write_read_byte()
1190 NOT_EXCEPTION, __func__, "write+read", "reader_fd") < 0) { in test_events_write_read_byte()
1192 exit(-1); in test_events_write_read_byte()
1199 NOT_EXCEPTION, __func__, "write+read", "writer_fd") < 0) { in test_events_write_read_byte()
1201 exit(-1); in test_events_write_read_byte()
1208 * Write a 512k buffer to the fifo in non-blocking mode, and make sure that
1209 * the write end becomes un-writable as a result of a partial write that
1222 cleanfifo2("testfifo", -1, -1); in test_events_partial_write()
1223 exit(-1); in test_events_partial_write()
1230 exit(-1); in test_events_partial_write()
1235 exit(-1); in test_events_partial_write()
1240 exit(-1); in test_events_partial_write()
1245 exit(-1); in test_events_partial_write()
1252 exit(-1); in test_events_partial_write()
1256 len = write(writer_fd, buffer, 512*1024); in test_events_partial_write()
1258 warn("test_events_partial_write: write"); in test_events_partial_write()
1261 exit(-1); in test_events_partial_write()
1267 NOT_EXCEPTION, __func__, "big write", "writer_fd") < 0) { in test_events_partial_write()
1269 exit(-1); in test_events_partial_write()
1274 exit(-1); in test_events_partial_write()
1282 NOT_EXCEPTION, __func__, "big write + drain", "writer_fd") < 0) { in test_events_partial_write()
1284 exit(-1); in test_events_partial_write()
1307 cleanfifo2("testfifo", -1, -1); in test_events_rdwr()
1308 exit(-1); in test_events_rdwr()
1314 cleanfifo2("testifo", fd, -1); in test_events_rdwr()
1315 exit(-1); in test_events_rdwr()
1320 exit(-1); in test_events_rdwr()
1330 exit(-1); in test_events_rdwr()
1334 * Write a byte, which should cause the file descriptor to become in test_events_rdwr()
1338 len = write(fd, &ch, sizeof(ch)); in test_events_rdwr()
1340 warn("%s: write", __func__); in test_events_rdwr()
1342 exit(-1); in test_events_rdwr()
1346 __func__, "write", "fd") < 0) { in test_events_rdwr()
1348 exit(-1); in test_events_rdwr()
1359 exit(-1); in test_events_rdwr()
1363 NOT_EXCEPTION, __func__, "write+read", "fd") < 0) { in test_events_rdwr()
1365 exit(-1); in test_events_rdwr()
1377 err(-1, "mkdtemp"); in main()
1381 err(-1, "chdir %s", temp_dir); in main()