namespace Akenti class SocketImpl

A SocketImpl object provides the implementation for both server and client socket functions such as set/get the host, set/get the port, do the connect, bind, listen and accept for the socket

Inheritance:


Public Methods

SocketImpl ()
Constructs this object
virtual ~SocketImpl ()
Destroys this object
void setHost (const string& host)
Sets the host name to host
const string& getHost () const
Returns the name of the host
void setPort (int port)
Sets the port number to port
int getPort () const
Returns the port number
virtual void doConnect ()
Provides the SocketImpl with either a plain Unix socket or a secure socket that has been connected to the host and port associated with the SocketImpl
virtual void doListen (int backlog)
Does a listen call on the encapsulated socket file descriptor
virtual void doAccept (SocketImpl* impl)
Does an accept call on the encapsulated socket IOHandler which references a socket that a listen has been done on and if successful, replaces the SocketImpl IOHandler with one referencing the new socket that is connected to a client
virtual void doClose ()
Closes the socket and sets the input and output streams to NULL
InputStream& getInputStream ()
If the socketImpl already has an input stream, returns it, otherwise it creates a new one and returns it
OutputStream& getOutputStream ()
If the socketImpl already has an output stream, returns it, otherwise it creates a new one and returns it
virtual SocketImpl* newInstance ()
Returns a new SocketImpl
virtual string paramString () const
Returns a string representation for SocketImpl which is used for debugging purposes

Protected Methods

int openConnection ()
Provides the SocketImpl with a new Unix socket which has been connected to the host and the port associated with this SocketImpl
int bindToAddress ()
Provides the SocketImpl with a new Unix socket which has been bound to the port associated with the SocketImpl
int acceptConnection (SocketImpl* impl)
Drills down in the SocketImpl to find a Unix socket file descriptor on which it is assumed that listen call has been done, does a Unix accept call on it and returns a new Unix socket file descriptor
virtual istream* doGetInputStream ()
Creates a new SocketInputStream initialized from a new SocketInBuffer attached to the IOHandler associated with the socketImpl
virtual ostream* doGetOutputStream ()
Creates a new SocketOutPutStream initialized from a new SocketOutBuffer attached to the IOHandler associated with the socketImpl

Documentation

A SocketImpl object provides the implementation for both server and client socket functions such as set/get the host, set/get the port, do the connect, bind, listen and accept for the socket. Contains the host, port, inputstream, outputsream and IOhandler associated with the socket. The IOHandler in turn contains a file descriptor which refers to either a plain Unix socket or a SSLsocket structure.

Normally a application will reference these methods thru either a Socket or SSLSocket if it is the client-side of the connection or thru either a ServerSocket or SSLServerSocket if it is the server-side of the connection. Thus client sockets only call doConnect, and server sockets only call doBind, doListen and doAccept.

SocketImpl()
Constructs this object

virtual ~SocketImpl()
Destroys this object

void setHost(const string& host)
Sets the host name to host.
Parameters:
host - the name of the host

const string& getHost() const
Returns the name of the host.
Returns:
the name of the host

void setPort(int port)
Sets the port number to port.
Throws:
Error - if port is less than zero
Parameters:
port - the port number

int getPort() const
Returns the port number.
Returns:
the port number

virtual void doConnect()
Provides the SocketImpl with either a plain Unix socket or a secure socket that has been connected to the host and port associated with the SocketImpl. The IOHandler for the connected fd is kept in the SocketImpl. Called by the client-side of a connection.
Throws:
IOException if can't open stream socket
IOException if can't connect to host
IOException if can't connect to port
See Also:
IOHandlerImpl()
openconnection()

virtual void doListen(int backlog)
Does a listen call on the encapsulated socket file descriptor. Done by the server-side of the connection, which is now ready to accept a connect message from a client.
Throws:
Error the socketImpl's fd is not bound to a port.
IOException listen call failed
Parameters:
backlog - the size of the request queue

virtual void doAccept(SocketImpl* impl)
Does an accept call on the encapsulated socket IOHandler which references a socket that a listen has been done on and if successful, replaces the SocketImpl IOHandler with one referencing the new socket that is connected to a client.
Throws:
Error if accept gets an invalid argument
IOException accept call failed.
Parameters:
impl - the SocketImpl
See Also:
acceptConnection()

virtual void doClose()
Closes the socket and sets the input and output streams to NULL.
Throws:
Error invalid operation if the socket has already been closed
IOException error from close.

InputStream& getInputStream()
If the socketImpl already has an input stream, returns it, otherwise it creates a new one and returns it.
Throws:
Error if invalid operation if the SocketImpl fd is not set
Error if bad alloc
IOException if bad input stream
Returns:
the input stream
See Also:
doGetInputStream()

OutputStream& getOutputStream()
If the socketImpl already has an output stream, returns it, otherwise it creates a new one and returns it.
Throws:
Error invalid operation if the SocketImpl fd is not set exception Error if bad alloc
IOException if bad output stream
Returns:
the output stream
See Also:
doGetOutputStream()

virtual SocketImpl* newInstance()
Returns a new SocketImpl. The default host is null and the default port is -1.
Returns:
a new SocketImpl

virtual string paramString() const
Returns a string representation for SocketImpl which is used for debugging purposes.
Returns:
debugging info

int openConnection()
Provides the SocketImpl with a new Unix socket which has been connected to the host and the port associated with this SocketImpl.
Throws:
IOException if can't open stream socket
IOException if can't connect to host
IOException if can't connect to port
Returns:
the connected file descriptor
See Also:
IOHandlerImpl()

int bindToAddress()
Provides the SocketImpl with a new Unix socket which has been bound to the port associated with the SocketImpl.
Throws:
IOException if cannot open stream socket
IOException if setsockop failed
IOException if cannot bind local address
Returns:
the fd for the newly created socket

int acceptConnection(SocketImpl* impl)
Drills down in the SocketImpl to find a Unix socket file descriptor on which it is assumed that listen call has been done, does a Unix accept call on it and returns a new Unix socket file descriptor. This socket will be connected to a client who has made a connect call to the port that this server is listening on.
Throws:
Error if no impl is input.
IOException if the new connection failed
Returns:
the sd for the newly created socket

virtual istream* doGetInputStream()
Creates a new SocketInputStream initialized from a new SocketInBuffer attached to the IOHandler associated with the socketImpl.
Returns:
a new istream connected to the SocketImpl's IOHandler.

virtual ostream* doGetOutputStream()
Creates a new SocketOutPutStream initialized from a new SocketOutBuffer attached to the IOHandler associated with the socketImpl.
Returns:
a new ostream connected to the SocketImpl's IOHandler.


Direct child classes:
SecureSocketImpl
Author:
Srilekha Mudumbai Abdelilah Essiari
Version:
1.1 00/11/01

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de