poll.d

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
import std.stdio;

const POLLIN = 0x001;
const POLLPRI = 0x002;
const POLLOUT = 0x004;

struct pollfd
{
  int fd;
  short events;
  short revents;
};

extern (C)
{
  int poll(pollfd* fds, ulong nfds, int timeout);
}

void main()
{
  pollfd[1] fds;

  fds[0].fd = 0;
  fds[0].events = POLLIN;

  int rv = poll(cast(pollfd*) fds, 1, 3500);
  if (rv == -1) {
    writeln("poll error");
  }
  else if (rv == 0) {
    writeln("timeout! not data.");
  }
  else {
    if (fds[0].events & POLLIN) {
      writeln("got data!");
    }
  }
}