Commit ba711deb authored by Jeremy Soller's avatar Jeremy Soller

Convert select example to use pipes

parent 378ea3ac
Pipeline #4006 failed with stages
in 5 minutes and 43 seconds
......@@ -6,19 +6,37 @@
#include "test_helpers.h"
int main(void) {
int fd = open("select.c", 0, 0);
int pipefd[2];
if (pipe2(pipefd, O_NONBLOCK) < 0) {
return 1;
char c = 'c';
if (write(pipefd[1], &c, sizeof(c)) < 0) {
return 1;
fd_set read;
FD_SET(fd, &read);
FD_SET(pipefd[0], &read);
printf("Is set before? %d\n", FD_ISSET(fd, &read));
printf("Is set before? %d\n", FD_ISSET(pipefd[0], &read));
// This should actually test TCP streams and stuff, but for now I'm simply
// testing whether it ever returns or not.
printf("Amount of things ready: %d\n", select(fd + 1, &read, NULL, NULL, NULL));
int nfds = select(pipefd[0] + 1, &read, NULL, NULL, NULL);
if (nfds < 0) {
return 1;
printf("Amount of things ready: %d\n", nfds);
printf("Is set after? %d\n", FD_ISSET(pipefd[0], &read));
printf("Is set after? %d\n", FD_ISSET(fd, &read));
return 0;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment