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

Chapter 10: Class protocol

protocol class is the base class for all the other application protocol classes like echo, smtp, etc. protocol is derived publicly from iosockstream. It uses protocolbuf class, a nested class of protocol, as its stream buffer.

The protocol class is an abstract class and thus, you cannot instantiate an object of protocol.

10.1: Class protocol::protocolbuf

protocol::protocolbuf class is publicly derived from sockinetbuf and thus, it inherits all the latter's public member functions. In addition, the protocolbuf defines the following member functions.

In what follows,

protocol::protocolbuf::protocolbuf (pname)
constructs protocolbuf object with the transport protocol set to pname.
p.protocol_name ()
returns the name of the transport protocol of p as a char string.
p.rfc_name ()
returns the name of the application protocol name of p as a char string. protocolbuf::rfc_name () is a pure virtual function; thus, any class derived from protocol::protocolbuf should provide a definition for protocolbuf::rfc_name ().
p.rfc_doc ()
returns the RFC document name of the application protocol of p as a char string. protocolbuf::rfc_doc () is a pure virtual function; thus, any class derived from protocol::protocolbuf should provide a definition for protocolbuf::rfc_doc ().
p.serve_clients (portno)
converts p into a server. Use the port specified in /etc/services for the application if portno < 0. Use a default port if 0 <= portno <= 1024. Otherwise, use portno as the port to accept clients requesting service. protocolbuf::serve_clients() calls the virtual function serve_clients_on_thread(). This function creates a seperate thread which runs the code in serve_client_on_thread(). In derived classes, serve_clients_on_thread() should be defined with the code you want to run to serve a client. Or, if you do not want to use threading to serve clients, you must override protocolbuf::serve_clients().

Please do not change the meaning of portno when you derive your own class.

p.bind ()
same as p.serve_clients (-1). It returns 0 on success and returns the errno on failure.
p.connect ()
connects to the local host's server for the application. p acts as the client. It returns 0 on success and returns the errno on failure.
p.connect (addr)
connects to the server running at the machine with address, addr. p acts as the client. It returns 0 on success and returns the errno on failure.
p.connect (host)
connects to the server running at the machine, host. p acts as the client. It returns 0 on success and returns the errno on failure.
p.connect (host, portno)
connects to the server servicing clients at portno at the machine, host. Unlike this connect call, the other variants of connect uses the port specified in the /etc/services file. It returns 0 on success and returns the errno on failure.