Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

cbits::SSLServerSocket Class Reference

This class is a SSL-enabled cbits::ServerSocket. More...

#include <SSLServerSocket.h>

Inheritance diagram for cbits::SSLServerSocket:

[legend]
Collaboration diagram for cbits::SSLServerSocket:
[legend]
List of all members.

Public Methods

 SSLServerSocket (const int port, const int qdepth=20, SSLContext *const ctxt=0) throw ( SocketException )
 Construct an SSL-enabled server socket. More...

virtual SSLSocketaccept (const long int msec=0) throw ( SocketException )
 Accept the next SSL connection on this server socket. More...

void close ()
 Close the server socket. More...

socket_t getHandle () const
 Access the BSD socket descriptor. More...

const bool isError () const
 Determine if the server socket is an error condition. More...

const std::string & getError () const
 Get human readable description of the last error, if any. More...

const int getSockOpt (const int level, const int op_name, char *result, int *result_len) const
 Set a socket option on the server socket. More...

std::ostream * getLogger () const
 Access this ServerSocket's debug logging stream. More...

std::ostream * getLocalLogger () const
 Access this ServerSocket's individual logging stream, set via cbits::ServerSocket::setLocalLogger, if any. More...

void setLocalLogger (std::ostream *os) const
 Set the instance debug logging stream for this ServerSocket. More...

void closeLocalLogger () const
 Close this ServerSocket's individually set debug log stream, set via cbits::ServerSocket::setLocalLogger, if any. More...


Static Public Methods

void setGlobalContext (SSLContext *g_ctxt) throw ( SSLContextException )
 Set a SSL context to be used by ALL new SSLServerSocket instances. More...

std::ostream * getGlobalLogger ()
 Access the global debug logging stream for all ServerSocket instances that don't have an individual logging streams. More...

void setGlobalLogger (std::ostream *os)
 Set a global debug logging stream to be used by all ServerSocket instances. More...

void closeGlobalLogger ()
 Close the globally set debug log stream, set via cbits::ServerSocket::setGlobalLogger, if any. More...


Protected Methods

virtual const socket_t accept_h (const long int msec=0) throw ( SocketException )
 Low level method to accept the next client network connection. More...

Socketget_tcp_socket () const
 Get a reference to the cbits::Socket instance used by this ServerSocket to bind to the server port. More...


Protected Attributes

bool _error
 errno value of the last error that occurred. More...

std::string _errstr
 A human readable description of _error, if any. More...

std::ostream * _llogr
 Debug logging sream for this instance, if set. More...


Static Protected Attributes

std::ostream * _glogr = 0
 Global, default logging stream for all cbits::ServerSocket instances, if set. More...


Private Attributes

BIO * _bio
 OpenSSL BIO object wrapping the low-level BSD socket. More...

SSLContext * _ctxt
 The SSL context for this SSLServerSocket. More...

CriticalSection _csect
 Critical section to prevent multiple threads from invoking cbits::SSLServerSocket::accept simultaneously. More...


Static Private Attributes

SSLContext * _global_ctxt
 The global, default SSL security context, if set. More...


Detailed Description

This class is a SSL-enabled cbits::ServerSocket.

The OpenSSL library (http://www.openssl.org) is used to provide SSL-related functionality and X.509 certificate handling.

From the user's perspective, a cbits::SSLServerSocket is (in principle) identical to a cbits::ServerSocket in terms of functionality after the network connection has been established and the SSL handshake has succeeded.

However, all SSL sockets have to be created within a particular SSL context that defines parameters and data used during the SSL handshake, such as what ciphers are allowed (or not) and the location of relevant X.509 certificates.

The cbits::SSLContext class is used to represent an SSL security context for establishing SSL network connections. An instance of cbits::SSLContext should be provided to the cbits::SSLServerSocket constructor or set globally, in advance, for all (future) SSLServerSocket instances via the cbits::SSLServerSocket::setGlobalContext method.

Further, all cbits::SSLSocket connections produced from a cbits::SSLServerSocket, as a result of the SSL-enabled server accepting SSL connections from remote clients, inherit the cbits::SSLContect of the cbits::SSLServerSocket that produced them.


Constructor & Destructor Documentation

cbits::SSLServerSocket::SSLServerSocket const int    port,
const int    qdepth = 20,
SSLContext *const    ctxt = 0
throw ( SocketException )
 

Construct an SSL-enabled server socket.

port - the port to accept client connections on.

Returns: ------------ n/a

Exceptions: ----------- SocketException - if the socket can not be created.

Parameters:
port  local host port
qdepth  Max number of pending client connections. In most cases, the default is adequate.
ctxt  SSL context to use for this connection. If not specified, then a global context should have already been set.


Member Function Documentation

virtual SSLSocket* cbits::SSLServerSocket::accept const long int    msec = 0 throw ( SocketException ) [virtual]
 

Accept the next SSL connection on this server socket.

Returns:
A pointer to a cbits::SSLSocket representing a new client connection, or 0 if the call timed out.
Exceptions:
SocketException  if an error occurred on the underlying socket.
Parameters:
msec  The maximum number of milliseconds to wait for a client connection. A zero or negative number is interpreted to mean 'wait forever'.

Reimplemented from cbits::ServerSocket.

const socket_t ServerSocket::accept_h const long int    msec = 0 throw ( SocketException ) [protected, virtual, inherited]
 

Low level method to accept the next client network connection.

This method could be reimplemented in a derived class that does this differently (on a different platform, say).

Returns:
A socket handle representing a new client connection, or 0 if the maximum wait time elapsed.
Exceptions:
SocketException  if an error occurs on the socket.
Parameters:
mmsec  Maximum number of milliseconds to wait for a client connection if one is not immediately available. A negative or zero value is interpreted to mean 'wait forever'.

void ServerSocket::close   [inherited]
 

Close the server socket.

void ServerSocket::closeGlobalLogger   [static, inherited]
 

Close the globally set debug log stream, set via cbits::ServerSocket::setGlobalLogger, if any.

Since the output stream supplied to cbits::ServerSocket::setGlobalLogger is externally created, the output stream itself is not closed by this action.

This action does not affect any cbits::Socket instances created by this ServerSocket.

void ServerSocket::closeLocalLogger   const [inherited]
 

Close this ServerSocket's individually set debug log stream, set via cbits::ServerSocket::setLocalLogger, if any.

Since the output stream supplied to cbits::ServerSocket::setLocalLogger is externally created, the output stream itself is not closed by this action.

This action does not affect any cbits::Socket instances created by this ServerSocket.

Socket* cbits::ServerSocket::get_tcp_socket   const [inline, protected, inherited]
 

Get a reference to the cbits::Socket instance used by this ServerSocket to bind to the server port.

Returns:
A pointer to a cbits::Socket instance.

const std::string& cbits::ServerSocket::getError   const [inline, inherited]
 

Get human readable description of the last error, if any.

std::ostream * ServerSocket::getGlobalLogger   [static, inherited]
 

Access the global debug logging stream for all ServerSocket instances that don't have an individual logging streams.

This only accesses the logging stream that is used by ServerSocket instances that haven't been individually configured with their own logging stream via cbits::ServerSocket::setLocalLogger.

Returns:
pointer to std::ostream instance or 0 if no global logger has been set.

socket_t ServerSocket::getHandle   const [inherited]
 

Access the BSD socket descriptor.

Returns:
BSD socket descriptor for the server socket.

std::ostream * ServerSocket::getLocalLogger   const [inherited]
 

Access this ServerSocket's individual logging stream, set via cbits::ServerSocket::setLocalLogger, if any.

Returns:
a pointer to a std::ostream instance, or 0 if not set.

std::ostream * ServerSocket::getLogger   const [inherited]
 

Access this ServerSocket's debug logging stream.

A pointer to a stream is always returned. Logging statements that use this method should perform runtime checks to determine if application debug logging is enabled.

Returns:
Pointer to std::ostream instance.

const int ServerSocket::getSockOpt const int    level,
const int    op_name,
char *    result,
int *    result_len
const [inherited]
 

Set a socket option on the server socket.

Returns:
See the getsockopt manpage for a description of the return values on your platform.
Parameters:
level  See getsockopt documentation.
op_name  See getsockopt documentation.
buffer  See getsockopt documentation.
buflen  See getsockopt documentation.

const bool ServerSocket::isError   const [inherited]
 

Determine if the server socket is an error condition.

Returns:
true if the socket is in an error state; otherwise, false.

void cbits::SSLServerSocket::setGlobalContext SSLContext *    g_ctxt throw ( SSLContextException ) [static]
 

Set a SSL context to be used by ALL new SSLServerSocket instances.

This may be overridden for individual SSLServerSocket instances by supplying a different context to the SSLServerSocket constructor when the SSLServerSocket is created.

Exceptions:
SSLContextException  if an invalid SSL context is supplied.
Parameters:
g_ctxt  Global SSL context

void ServerSocket::setGlobalLogger std::ostream *    os [static, inherited]
 

Set a global debug logging stream to be used by all ServerSocket instances.

This does not override a ServerSocket instance's individual logging stream, if any, set via cbits::ServerSocket::setLocalLogger.

This method is a useful way to provide a default logging stream to all ServerSocket instances, without having to configure each instance separately, but still be able to set the logging stream for specific ServerSocket instances.

If this ServerSocket doesn't have an individual logging stream configured, the global logging stream (if set) is used to configure the logging stream for all cbits::Socket instances created by this ServerSocket.

Parameters:
os  Pointer to global debug logging stream

void ServerSocket::setLocalLogger std::ostream *    os const [inherited]
 

Set the instance debug logging stream for this ServerSocket.

This logger is also configured for all cbits::Socket instances that are created by this ServerSocket.


Member Data Documentation

BIO* cbits::SSLServerSocket::_bio [private]
 

OpenSSL BIO object wrapping the low-level BSD socket.

CriticalSection cbits::SSLServerSocket::_csect [private]
 

Critical section to prevent multiple threads from invoking cbits::SSLServerSocket::accept simultaneously.

Reimplemented from cbits::ServerSocket.

SSLContext* cbits::SSLServerSocket::_ctxt [private]
 

The SSL context for this SSLServerSocket.

bool cbits::ServerSocket::_error [protected, inherited]
 

errno value of the last error that occurred.

std::string cbits::ServerSocket::_errstr [protected, inherited]
 

A human readable description of _error, if any.

SSLContext* cbits::SSLServerSocket::_global_ctxt [static, private]
 

The global, default SSL security context, if set.

std::ostream * ServerSocket::_glogr = 0 [static, protected, inherited]
 

Global, default logging stream for all cbits::ServerSocket instances, if set.

std::ostream* cbits::ServerSocket::_llogr [protected, inherited]
 

Debug logging sream for this instance, if set.


The documentation for this class was generated from the following file:
Generated by
doxygen
Hosted by
SourceForge