prev UP NEXT C++ socket classes for OS/2

1.3.1: Class Hierarchy



Each socket class which is derived from ios has a corresponding class which is derived from streambuf.

Each stream class has a private pointer to a corresponding buf class.

Sockstream is derived from ios. Sockunix and sockinet are derived from sockstream and similarly for the corresponding buf classes.

Each of the classes sockstream, sockinet, and sockunix has different variants that allow input, output, or both input and output. These variants use the prefixes i, o, or io and they "mixin" the classes istream, ostream or iostream respectively. For example, the class isockinet is an internet stream class which allows the same input functions and manipulators as the istream class. The class iosockunix is a UNIX interprocess communications class which allows the same input and output operations as iostreams.

The constructors for each of the above classes takes a pointer to a corresponding buf class. The caller of such a constructor must assure that the buf object exists for the duration of the stream class. This is inconvenient. Therefore, special classes, whose names begin with the prefix "b", have been created which contain the corresponding buf objects as data members. The constructors for these "b" classes have take parameters similar to their corresponding buf classes. The "b" classes are derived from the corresponding class without the "b". This is similar to the way the ifstream, ofstream, and fstream classes work in the C++ class library. It is expected that most application code will construct sockstream objects using these "b" variants. However functions will often have arguments which are references to more basic classes for generality. This is similar to the way one uses iostreams. Often one constructs an object of type ofstream and then passes it to a function taking a reference to an ostream as a parameter. These "b" variants did not exist in Gnanasekaran Swaminathan's sockbuf library for UNIX.

Protocol is derived from sockstream and iostream. The classes ftp, echo, and smtp are derived from protocol. The corresponding buf classes are derived in a similar pattern. There are "b" prefix classes for these classes as well.

1.3.1.1: ios::init()

The class ios is a virtual base class for all stream classes. Because of this, and C++ language rules, all classes derived from a stream must specify a initializer for ios in their ctor list if they do not want the default constructor to be used by default. However, the default constructor for ios does not do what one would want. It does not set up the pointer to the streambuf. Thus, the member function ios::init() is provided to finish the initialization. Each of the stream classes has its own version of init() which should be called if the class is constructed via a default constructor.