~ubuntu-branches/ubuntu/karmic/cvm/karmic

« back to all changes in this revision

Viewing changes to iopoll.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape
  • Date: 2005-01-15 11:32:52 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050115113252-0jj7skrzjb0s6837
Tags: 0.32-1
* new upstream version.
* debian/copyright: adapt, 2005.
* debian/diff/ld.diff: adapt.
* debian/rules: strip diet binaries if DEB_BUILD_OPTIONS=diet is set.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "iopoll.h"
2
 
#include "select.h"
3
 
 
4
 
#ifdef IOPOLL_SELECT
5
 
 
6
 
int iopoll(iopoll_fd* fds, unsigned nfds, unsigned long timeout)
7
 
{
8
 
  struct timeval tv;
9
 
  fd_set rfds;
10
 
  fd_set wfds;
11
 
  int fdmax;
12
 
  iopoll_fd* io;
13
 
  int fd;
14
 
  unsigned i;
15
 
  int r;
16
 
  
17
 
  FD_ZERO(&rfds);
18
 
  FD_ZERO(&wfds);
19
 
 
20
 
  for (fdmax = 0, i = 0, io = fds; i < nfds; ++i, ++io) {
21
 
    fd = io->fd;
22
 
    if (fd < 0) continue;
23
 
    if (fd > fdmax) fdmax = fd + 1;
24
 
    if (io->events & IOPOLL_READ) FD_SET(fd, &rfds);
25
 
    if (io->events & IOPOLL_WRITE) FD_SET(fd, &wfds);
26
 
  }
27
 
 
28
 
  tv.tv_sec = timeout / 1000;
29
 
  tv.tv_usec = (timeout % 1000) * 1000;
30
 
 
31
 
  if ((r = select(fdmax, &rfds, &wfds, (fd_set*)0, &tv)) <= 0) return r;
32
 
 
33
 
  for (i = 0, io = fds; i < nfds; ++i, ++io) {
34
 
    fd = io->fd;
35
 
    if (fd < 0) continue;
36
 
    if ((io->events & IOPOLL_READ) && FD_ISSET(fd, &rfds))
37
 
      io->revents |= IOPOLL_READ;
38
 
    if ((io->events & IOPOLL_WRITE) && FD_ISSET(fd, &wfds))
39
 
      io->revents |= IOPOLL_WRITE;
40
 
  }
41
 
  return r;
42
 
}
43
 
 
44
 
#endif