plptools
Loading...
Searching...
No Matches
IOWatch Class Reference

A simple thread-safe wrapper for select() More...

#include <iowatch.h>

Public Member Functions

 IOWatch ()
 Creates a new instance. More...
 
 ~IOWatch ()
 Destroys an instance. More...
 
void addIO (const int fd)
 Adds a file descriptor to the set of descriptors. More...
 
void remIO (const int fd)
 Removes a file descriptor from the set of descriptors. More...
 
bool watch (const long secs, const long usecs)
 Performs a select() call. More...
 

Private Attributes

std::mutex lock_
 
int fileDescriptorCount_
 
int * fileDescriptors_
 

Detailed Description

A simple thread-safe wrapper for select()

IOWatch is a simple wrapper for the select system call. In particular, it takes care of passing the maximum file descriptor argument (arg 1) of select() correctly. IOWatch handles select on read descriptors only.

Definition at line 34 of file iowatch.h.

Constructor & Destructor Documentation

◆ IOWatch()

IOWatch::IOWatch ( )

Creates a new instance.

Definition at line 32 of file iowatch.cc.

◆ ~IOWatch()

IOWatch::~IOWatch ( )

Destroys an instance.

Definition at line 38 of file iowatch.cc.

Member Function Documentation

◆ addIO()

void IOWatch::addIO ( const int  fd)

Adds a file descriptor to the set of descriptors.

Parameters
fdThe file descriptor to add.

Definition at line 42 of file iowatch.cc.

◆ remIO()

void IOWatch::remIO ( const int  fd)

Removes a file descriptor from the set of descriptors.

Parameters
fdThe file descriptor to remove.

Definition at line 54 of file iowatch.cc.

◆ watch()

bool IOWatch::watch ( const long  secs,
const long  usecs 
)

Performs a select() call.

Parameters
secsNumber of seconds to wait.
usecsNumber of microseconds to wait.
Returns
true, if any of the descriptors is readable; false if the underlying select returned an error or the timeout expired.

Definition at line 64 of file iowatch.cc.

Member Data Documentation

◆ fileDescriptorCount_

int IOWatch::fileDescriptorCount_
private

Definition at line 74 of file iowatch.h.

◆ fileDescriptors_

int* IOWatch::fileDescriptors_
private

Definition at line 75 of file iowatch.h.

◆ lock_

std::mutex IOWatch::lock_
private

Definition at line 73 of file iowatch.h.


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