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
.
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,
p
is an object of a non-abstract class derived from
protocolbuf
.
pname
is the transport protocol name which is either
protocol::tcp
or protocol::udp
.
addr
is an unsigned long denoting the valid address of a machine in
host byte order.
host
is a char string denoting the name of a machine like
"kelvin.seas.virginia.edu".
portno
is an int and denotes the port number in host byte order.
protocol::protocolbuf::protocolbuf (pname)
protocolbuf
object with the transport protocol set to
pname
.
p.protocol_name ()
p
as a char string.
p.rfc_name ()
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 ()
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)
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 ()
p.serve_clients (-1)
.
It returns 0 on success and returns the errno on failure.
p.connect ()
p
acts as
the client. It returns 0 on success and returns the errno on failure.
p.connect (addr)
addr
.
p
acts as the client.
It returns 0 on success and returns the errno on failure.
p.connect (host)
host
.
p
acts as the client.
It returns 0 on success and returns the errno on failure.
p.connect (host, portno)
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.