I wonder if select()/poll() works if the communication is unbuffered on both sides (reading and writing side). Unbuffered means no kernel buffer. The data is copied from user-space memory into user-space memory. The data is copied from the buffer provided in write() directly into the one provided by read().
Now let's assume program A wants to read and program B writes.
Both programs call poll() to wait until they can read/write.
But poll() will never return on both sides. Program A will never be able to read because the other side is not writing. And program B will never be able to write because the other side is not reading.
I want to know if this can happen. If there is always a kernel buffer then of course it will never happen.
int fd[] = {..., ...}; // this could be a pipe, file, fifo, tcp socket, local socket, ... (without any kernel buffer)
pid_t p = fork();
if (p == 0)
{
struct pollfd pfd;
pfd.fd = fd[0];
pfd.events = POLLIN;
pfd.revents = 0;
poll(&pfd, 1, -1); // poll will never return as the other side is not writing
}
else
{
struct pollfd pfd;
pfd.fd = fd[1];
pfd.events = POLLOUT;
pfd.revents = 0;
poll(&pfd, 1, -1); // poll will never return as the other side is not reading
}
I simply want to know if this is possible (poll() not returning on both sides).