FBB::Selector(3bobcat)

Timed Delays, Multiple File I/O
(libbobcat-dev_4.08.03-x.tar.gz)

2005-2018

NAME

FBB::Selector - Timed delays, Alarms and Multiple File I/O.

SYNOPSIS

#include <bobcat/selector>
Linking option: -lbobcat

DESCRIPTION

FBB::Selector objects are wrappers around the select(2) system calls and allow timed delays, alarm functionality and/or multiple file I/O. It requires the use of file descriptors, which are not an official part of C++. However, most operating systems offer file descriptors. Sockets are well-known file descriptors.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

CONSTRUCTORS

The copy constructor is available.

MEMBER FUNCTIONS

EXAMPLE


#include <string>
#include <iostream>

#include <bobcat/selector>
#include <bobcat/exception>

using namespace std;
using namespace FBB;

int main(int argc, char **argv, char **envp)
{
    Selector selector;

    selector.setAlarm(5);               // every 5 secs: alarm fires
    selector.addReadFd(STDIN_FILENO);   // look also at cin

    try
    {
        while (true)
        {
            if (!selector.wait())           // 0: alarm fires
                cout << "Are you still there?" << endl;                
            else
            {
                string s;
                if (!getline(cin, s) || !s.length())
                    return 0;
                cout << "Thank you for: " << s << endl;
            }
        }
    }
    catch (Exception const &e)
    {
        cout << e.what() << endl;
    }
    return 0;
}
    

FILES

bobcat/selector - defines the class interface

SEE ALSO

bobcat(7), select(2)

BUGS

Not so much a bug as something to be aware of: When removing input file descriptors of files at their end-of-file positions the set of active file descriptors monitored by wait may decay to an empty set. If wait is thereupon called it will wait forever since there are no more file descriptors to monitor. The monitoring process should check for this empty-set situation before calling wait.

Facilities to prevent wait from waiting indefinitely in this situation will be added to Selector in a future Bobcat release.

DISTRIBUTION FILES

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).