foobar2000 SDK  2015-08-03
Public Member Functions | Data Fields
pfc::fdSelect

#include <nix-objects.h>

Public Member Functions

int Select ()
 
int Select (double timeOutSeconds)
 
int Select_ (int timeOutMS)
 

Data Fields

fdSet Errors
 
fdSet Reads
 
fdSet Writes
 

Detailed Description

Definition at line 59 of file nix-objects.h.

Member Function Documentation

int pfc::fdSelect::Select ( )

Definition at line 94 of file nix-objects.cpp.

94  {
95  return Select_( -1 );
96  }
int Select_(int timeOutMS)
int pfc::fdSelect::Select ( double  timeOutSeconds)

Definition at line 97 of file nix-objects.cpp.

97  {
98  int ms;
99  if (timeOutSeconds < 0) {
100  ms = -1;
101  } else if (timeOutSeconds == 0) {
102  ms = 0;
103  } else {
104  ms = pfc::rint32( timeOutSeconds * 1000 );
105  if (ms < 1) ms = 1;
106  }
107  return Select_( ms );
108  }
int Select_(int timeOutMS)
t_int32 rint32(double p_val)
Definition: other.cpp:209
int pfc::fdSelect::Select_ ( int  timeOutMS)

Definition at line 110 of file nix-objects.cpp.

110  {
111  fdSet total = Reads;
112  total += Writes;
113  total += Errors;
114  const size_t count = total.m_fds.size();
116  v.set_size_discard( count );
117  size_t walk = 0;
118  for( auto i = total.m_fds.begin(); i != total.m_fds.end(); ++ i ) {
119  const int fd = *i;
120  auto & f = v[walk++];
121  f.fd = fd;
122  f.events = (Reads[fd] ? POLLIN : 0) | (Writes[fd] ? POLLOUT : 0);
123  f.revents = 0;
124  }
125  int status = poll(v.get_ptr(), (int)count, timeOutMS);
126  if (status < 0) throw exception_nix();
127 
129 
130  if (status > 0) {
131  for(walk = 0; walk < count; ++walk) {
132  auto & f = v[walk];
133  if (f.revents & POLLIN) Reads += f.fd;
134  if (f.events & POLLOUT) Writes += f.fd;
135  if (f.events & POLLERR) Errors += f.fd;
136  }
137  }
138 
139  return status;
140  }
std::set< int > m_fds
Definition: nix-objects.h:49
const t_item * get_ptr() const
Definition: array.h:213
void clear()
Definition: nix-objects.cpp:84
void set_size_discard(t_size p_size)
Definition: array.h:128

Field Documentation

fdSet pfc::fdSelect::Errors

Definition at line 66 of file nix-objects.h.

fdSet pfc::fdSelect::Reads

Definition at line 66 of file nix-objects.h.

fdSet pfc::fdSelect::Writes

Definition at line 66 of file nix-objects.h.


The documentation for this class was generated from the following files: