GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  REDIRECTOR (3)

NAME

FBB::Redirector - Redirects a file descriptor to another descriptor

CONTENTS

SYNOPSIS

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

DESCRIPTION

Objects of the class FBB::Redirector set up a system level file redirection, using file descriptors rather than streams. Redirector objects are effectively wrappers around the dup2(2) system call. System level redirection allows the programmer to send output to, e.g., the standard output stream, which actually appears at another stream (e.g., the standard error).

Redirector objects are used to redirect the output sent to a stream having file descriptor x to another stream having file descriptor y, much like the shell\(cqs > operator redirects the standard output to some file.

Redirector objects can also be used to extract the information from a stream having file descriptor x in fact from another stream having file descriptor y, much like the shell\(cqs < operator is used to read the information in some file from the standard input.

Redirection using Redirector objects represents a stronger form of redirection than redirection offered by C++ itself, which uses std::streambuf redirection, and which is, because of that, bound to the program\(cqs scope. System level redirection, on the other hand, is applied at the system level, allowing the programmer to redirect standard streams when starting a program. For example, the standard error is commonly written to the standard output using an invocation like program 2>&1.

When constructing Redirector objects a file descriptor is required. The file descriptor specified at the constructor is the file descriptor that is used by the program to read information from or to write information to. Another file descriptor is required to set up the redirection: the file descriptor used here is the file descriptor of the stream that actually holds the information which is extracted from the file descriptor that was passed to the Redirector\(cqs constructor; or it is the file descriptor of the stream receiving the information which is written to the stream having the file descriptor that was passed to the Redirector\(cqs constructor.

When a Redirector object goes out of scope, its file descriptor are left as-is. In particular, note that no close(2) operation is performed on the Redirector\(cqs file descriptors. After setting up redirection using the Redirector\(cqs member functions and passing the Redirector\(cqs file descriptors to code that uses the Redirector\(cqs descriptors, the Redirector object could in fact safely be destroyed.

Formally, file descriptors are not defined in C++, but they are available in many types of operating systems. In those systems each ‘file\(cq has an associated ‘file descriptor\(cq. A file descriptor is an int, which is an index into the program\(cqs file allocation table, maintained by the system. Another type of well-known entities which are file descriptors are sockets.

Well-known filedescriptors (defined in, e.g., unistd.h) having fixed values are 0 (STDIN_FILENO), representing the standard input stream (std::cin); 1, (STDOUT_FILENO), representing the standard output stream (std::cout); 2, (STDERR_FILENO), representing the standard error stream (cerr); Notes:
o System-level redirections are kept during system calls of the exec(3) family.
o Destroying a Redirector object does not undo the redirection set up by that object.

NAMESPACE

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

INHERITS FROM

-

ENUM

The enumeration StandardFileno holds the following values:
o STDIN (0)
o STDOUT (1)
o STDERR (2) These values may be used to set up a redirection instead of the plain numbers.

CONSTRUCTORS

o Redirector(int fd):
This constructor expects the file descriptor of the file that will be used by the program to access (read, write) another file. The file descriptor that is passed to the constructor is used by the program, and will often be STDIN, STDOUT, or STDERR, allowing the program to use cin, cout, or cerr to extract information from, or insert information into other streams using its standard input and output streams. The copy constructor is available.

MEMBER FUNCTIONS

o void swallow(int otherFd) const:
This member function expects a file descriptor which should become a synonym of the constructor\(cqs file descriptor. The constructor\(cqs file descriptor is redirected to otherFd.
After successfully calling swallow information written to otherFd is in fact written to the constructor\(cqs file descriptor. E.g., if the constructor\(cqs file descriptor represents a file on disk and otherFd is STDOUT_FILENO then all information sent to the standard output stream is actually sent to the file on disk:

information sent to otherFd -> is received at the constructor\(cqs Fd (e.g., otherFd = STDOUT_FILENO)

Conversely, if the constructor\(cqs file descriptor represents a file on disk and otherFd is STDIN_FILENO then all information extracted from the standard input stream is actually read from the file on disk.

information extracted from otherFd <- is read from the constructor\(cqs Fd (e.g., otherFd = STDIN_FILENO)

Following swallow both file descriptors are open, and refer to the constructor\(cqs file descriptor.
Before setting up the redirection, the original otherFd is closed by close(2). Following swallow both file descriptors can be used, and refer to the constructor\(cqs file descriptor. If after calling swallow close(2) is called for one of them, then the other one remains open.
If redirection fails an FBB::Exception object is thrown, whose which() member shows the system\(cqs errno value set by the failing dup2(2) function.
o void through(int otherFd) const:
This member function expects a file descriptor which should become a synonym of the constructor\(cqs file descriptor. The constructor\(cqs file descriptor is redirected to otherFd. The constructor\(cqs file descriptor can no longer be used, as it is closed by close(2).
After successfully calling through information written to otherFd is in fact written to the constructor\(cqs file descriptor. E.g., if the constructor\(cqs file descriptor represents a file on disk and otherFd is STDOUT_FILENO then all information sent to the standard output stream is actually sent to the file on disk:

information sent to otherFd -> is received at the constructor\(cqs Fd (e.g., otherFd = STDOUT_FILENO)

Conversely, if the constructor\(cqs file descriptor represents a file on disk and otherFd is STDIN_FILENO then all information extracted from the standard input stream is actually read from the file on disk.

information extracted from otherFd <- is read from the constructor\(cqs Fd (e.g., otherFd = STDIN_FILENO)

Before setting up the redirection, the original otherFd is closed by close(2). Following through only otherFd can be used, and it refers to (i.e., reads or writes) the constructor\(cqs file descriptor.
If redirection fails an FBB::Exception object is thrown, whose which() member shows the system\(cqs errno value set by the failing dup2(2) function.

EXAMPLE

#include <iostream> #include <bobcat/redirector> using namespace std; using namespace FBB; int main() { Redirector redirector(Redirector::STDOUT); redirector.swallow(Redirector::STDERR); cerr << \(dqThis appears at the standard output stream\n\(dq \(dquse ‘a.out > /dev/null\(cq to suppress this message\(dq << endl; }

FILES

bobcat/redirector - defines the class interface

SEE ALSO

bobcat(7), dup2(2), execl(3)

BUGS

None Reported.

DISTRIBUTION FILES

o bobcat_3.25.01-x.dsc: detached signature;
o bobcat_3.25.01-x.tar.gz: source archive;
o bobcat_3.25.01-x_i386.changes: change log;
o libbobcat1_3.25.01-x_*.deb: debian package holding the libraries;
o libbobcat1-dev_3.25.01-x_*.deb: debian package holding the libraries, headers and manual pages;
o http://sourceforge.net/projects/bobcat: public archive location;

BOBCAT

Bobcat is an acronym of ‘Brokken\(cqs Own Base Classes And Templates\(cq.

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).

Search for    or go to Top of page |  Section 3 |  Main Index


libbobcat-dev_3&.25&.01-x&.tar&.gz FBB::REDIRECTOR (3bobcat) 2005-2015

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.