FBB::Selector(3bobcat)
π FBB::Selector(3bobcat) β Timed Delays, Multiple File I/O π
okay bestie, pull up a chair, we're doing the bobcat manual pages and this one is genuinely a bop. it's FBB::Selector, from the 3bobcat manual, and it's giving "I control time AND your file descriptors." iconic behaviour, honestly.
β¨ NAME β¨
FBB::Selector β Timed delays, Alarms and Multiple File I/O. π
β¨ SYNOPSIS β¨
#include <bobcat/selector>
Linking option: -lbobcat
β¨ DESCRIPTION β¨
so like. FBB::Selector objects are wrappers around the select(2) system calls, and they let you do timed delays, alarm functionality, and/or multiple file I/O. slay.
the one catch: it needs file descriptors, and file descriptors are not an official part of C++. like, they're just not in the C++ syllabus. but most operating systems literally offer them, so we're fine. and sockets? sockets are well-known file descriptors. iykyk. π
β¨ NAMESPACE β¨
FBB
all constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. periodt.
β¨ INHERITS FROM β¨
-
(nothing bestie, it stands on its own two feet π)
β¨ CONSTRUCTORS β¨
Selector()β this constructor initializes the object. that's it, that's the job. π
also, copy and move constructors (and assignment operators) are available. so you can copy it, move it, whatever your heart desires.
β¨ MEMBER FUNCTIONS β¨
void addExceptFd(int fd)β adds a file descriptor to the set of file descriptors that are monitored for exceptions. and no, bestie, these are not C++ exceptions β don't get it twisted. seeman 2 selectfor the details. πvoid addReadFd(int fd)β adds a file descriptor to the set of file descriptors that are monitored for reading. yes, reading. we love a reader. πvoid addWriteFd(int fd)β adds a file descriptor to the set of file descriptors that are monitored for writing. βοΈint exceptFd()β returns-1if no more file descriptors are available in the exception category. otherwise it returns the next available file descriptor in the exception category. once you return fromwait, you can call this repeatedly until-1comes back, servicing each available file descriptor in turn. it's a little assembly line, and it ate. π₯void noAlarm()β this member prevents any timeout-alarm from occurring. bye bye alarm. π§int nReady()β returns the number of available file descriptors. returns0at a timeout, and returns-1whenselect(2)itself failed. (not me noticing the original says "-1: is returned" β yes bestie, there's a lil colon typo in the source, we keep it real.) πint readFd()β returns-1if no more file descriptors are available for reading. otherwise it returns the next available file descriptor for reading. once you return fromwait, you can call this repeatedly until-1comes back, servicing each available file descriptor in turn.
now listen: the file whose file descriptor is returned by readFd may also be at its end-of-file position. the file is ready for reading, but no characters will be returned when you try to read from it, because of its end-of-file status. in that case the file descriptor is probably best removed from the set of active file descriptors. like, respectfully, it's done here. π«Ά
void rmExceptFd(int fd)β removes a file descriptor from the set of file descriptors that are monitored for exceptions. again, not C++ exceptions. seeman 2 selectfor details. πvoid rmReadFd(int fd)β removes a file descriptor from the set of file descriptors that are monitored for reading.void rmWriteFd(int fd)β removes a file descriptor from the set of file descriptors that are monitored for writing.void setAlarm(int sec, int usec = 0)β this member sets the alarm at the indicated seconds and micro-seconds. if no action occurred on one of the monitored file descriptions following the indicated amount of time,waitwill return withnReadyreturning0.
β οΈ the requested alarm time (sec + usec / 1e+6) may not be negative and may not exceedstd::numeric_limits<int>::max()β otherwise anFBB::Exceptionexception will be thrown. no cap.
a 0 alarm time specification results in wait returning immediately. and to switch off the alarm time? use noAlarm. π
int wait()β this member should be called to wait for activities on the installed file descriptors or the timeout-period. the membersexceptFd,nReady,readFdandwriteFdonly show their defined behaviours afterwaithas returned. before that? they're just vibes.
it throws an FBB::Exception exception when select(2) fails, which may very well indicate the end of any available input. an exception is also thrown if the program received a signal. π
if wait returns normally, its return value represents the number of available file descriptors. note that wait may also return with an input file descriptor returned by readFd of a file at its end-of-file position. the file is ready for reading, but no characters will be returned when trying to read from it due to its end-of-file status. same energy as before, bestie β it's ready, but it has nothing to say. π
int writeFd()β returns-1if no more file descriptors are available for writing. otherwise the next available file descriptor for writing is returned. once you return fromwait, you can call this repeatedly until-1is returned, servicing each available file descriptor in turn. π
β¨ EXAMPLE β¨
here's the whole thing, verbatim, because code is sacred:
#include <string>
#include <iostream>
#include <bobcat/selector>
#include <bobcat/exception>
using namespace std;
using namespace FBB;
int main(int argc, char **argv, char **envp)
try
{
Selector selector;
selector.setAlarm(5); // every 5 secs: alarm fires
selector.addReadFd(STDIN_FILENO); // look also at cin
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() << β\nβ;
return 1;
}
like, "Are you still there?" is so real of this program. it's checking in. it cares. π₯Ί
β¨ FILES β¨
bobcat/selectorβ defines the class interface. π
β¨ SEE ALSO β¨
β¨ BUGS β¨
None reported. we're clean, bestie. β¨
β¨ BOBCAT PROJECT FILES β¨
https://fbb-git.gitlab.io/bobcat/β gitlab project page;
Debian Bobcat project files:
libbobcat6β debian package containing the shared library, changelog and copyright note;libbobcat-devβ debian package containing the static library, headers, manual pages, and developer info;
β¨ BOBCAT β¨
Bobcat is an acronym of Brokkenβs Own Base Classes And Templates. cute, right? π¦
β¨ 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). π
and that's the whole page, bestie!! this came out of thelibbobcat-devpackage, version6.15.01, dated2005-2026β yeah, two decades of bobcat, we love a long-running icon. go forth andselect(2)responsibly. mwah. π β¨πΈ
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms