#include <ulxr_tcpip_connection.h>
Inheritance diagram for ulxr::TcpIpConnection:
Public Member Functions | |
TcpIpConnection (bool server, const CppString &domain, unsigned port=80) | |
Constructs a generic connection, primarily for a client. | |
void | setProxy (long adr, unsigned port) |
Sets a proxy for further connections. | |
void | setProxy (const CppString &domain, unsigned port) |
Constructs a generic connection, primarily for a client. | |
TcpIpConnection (bool server, long adr=INADDR_ANY, unsigned port=0) | |
Constructs a generic connection, primarily for a server. | |
virtual | ~TcpIpConnection () |
Destroys the connection. | |
virtual Connection * | detach () |
Detaches the connection by creating a duplicate of the connection and closing the original connection afterwards. | |
virtual void | open () |
Opens the connection in client mode. | |
virtual bool | accept (int timeout=0) |
Opens the connection in server mode, thus waiting for connections from clients. | |
virtual void | close () |
Closes the connection. | |
virtual void | shutdown (int mode) |
Shuts down the socket. | |
unsigned | getPort () |
Returns the configured port. | |
CppString | getHostName () const |
Gets the host name. | |
CppString | getServerDomain () const |
Gets the server doamin. | |
CppString | getPeerName () const |
Gets the name of the remote machine. | |
void | asciiToInAddr (const char *address, struct in_addr &saddr) |
Converts ascii text to in_addr struct. | |
int | abortOnClose (int bOn) |
Sets abort on close flag for a socket. | |
void | setTcpNoDelay (bool bOn) |
Sets the socket buffer mechanism. | |
virtual CppString | getInterfaceName () |
Tests if the current transmission expects a return value. | |
virtual int | getLastError () |
Portable function to return the current socket error number. | |
bool | isServerMode () const |
Checks if the connection is run as server. | |
virtual int | getServerHandle () |
Returns the server connection handle. | |
Protected Member Functions | |
hostent * | getHostAdress (const CppString &hostname) |
Creates a hostent struct from a host name. | |
virtual TcpIpConnection * | makeClone () |
Creates a shallow copy of this object. | |
virtual void | decrementServerRef (bool shutdown=false) |
Decrements the reference count to the server data. | |
void | setServerData (ServerSocketData *serv_data) |
Sets the pointer to the server-data. | |
ServerSocketData * | getServerData () const |
Gets the pointer to the server-data. | |
TcpIpConnection (const TcpIpConnection &) | |
Private Member Functions | |
void | init (unsigned port) |
Initializes internal variables. | |
int | doTcpNoDelay () |
Sets the socket buffer mechanism. | |
TcpIpConnection & | operator= (const TcpIpConnection &) |
Private Attributes | |
PImpl * | pimpl |
int | noDelayOpt |
Classes | |
struct | PImpl |
class | ServerSocketData |
Helper class to handle the server socket. More... |
Definition at line 59 of file ulxr_tcpip_connection.h.
ulxr::TcpIpConnection::TcpIpConnection | ( | bool | server, | |
const CppString & | domain, | |||
unsigned | port = 80 | |||
) |
Constructs a generic connection, primarily for a client.
The connection is not yet open after construction.
server | true: bind socket to adress for server mode | |
domain | domain name of the server | |
port | port on the the server. (If port==0 the system might choose a free port. Retrievable with getPort() ) |
Definition at line 213 of file ulxr_tcpip_connection.cpp.
References ulxr::Connection::getErrorString(), getHostAdress(), getLastError(), getServerHandle(), ulxr::Connection::getTimeout(), ulxr::TcpIpConnection::PImpl::hostdata, ulxr::Connection::init(), pimpl, ulxr::TcpIpConnection::PImpl::port, ulxr::TcpIpConnection::PImpl::remote_name, ulxr::TcpIpConnection::PImpl::server_data, ulxr::TcpIpConnection::PImpl::serverdomain, ulxr::SystemError, ULXR_GET_STRING, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
ulxr::TcpIpConnection::TcpIpConnection | ( | bool | server, | |
long | adr = INADDR_ANY , |
|||
unsigned | port = 0 | |||
) |
Constructs a generic connection, primarily for a server.
The connection is not yet open after construction.
server | true: bind socket to adress for server mode | |
adr | accepted client adress | |
port | port on which the connect is accepted |
Definition at line 171 of file ulxr_tcpip_connection.cpp.
References ulxr::Connection::getErrorString(), getLastError(), getServerHandle(), ulxr::Connection::getTimeout(), ulxr::TcpIpConnection::PImpl::hostdata, ulxr::Connection::init(), pimpl, ulxr::TcpIpConnection::PImpl::port, ulxr::TcpIpConnection::PImpl::server_data, ulxr::SystemError, ULXR_GET_STRING, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
ulxr::TcpIpConnection::~TcpIpConnection | ( | ) | [virtual] |
Destroys the connection.
Definition at line 439 of file ulxr_tcpip_connection.cpp.
References decrementServerRef(), pimpl, ULXR_PCHAR, and ULXR_TRACE.
ulxr::TcpIpConnection::TcpIpConnection | ( | const TcpIpConnection & | ) | [protected] |
void ulxr::TcpIpConnection::setProxy | ( | long | adr, | |
unsigned | port | |||
) |
Sets a proxy for further connections.
This setting only applies for client connections.
adr | adress for proxy | |
port | port on which to connect to the proxy |
Definition at line 286 of file ulxr_tcpip_connection.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
void ulxr::TcpIpConnection::setProxy | ( | const CppString & | domain, | |
unsigned | port | |||
) |
Constructs a generic connection, primarily for a client.
The connection is not yet open after construction.
domain | name for proxy | |
port | port on which to connect to the proxy |
Definition at line 294 of file ulxr_tcpip_connection.cpp.
References ulxr::SystemError, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
Connection * ulxr::TcpIpConnection::detach | ( | ) | [virtual] |
Detaches the connection by creating a duplicate of the connection and closing the original connection afterwards.
Implements ulxr::Connection.
Reimplemented in funtik::SSLConnection.
Definition at line 265 of file ulxr_tcpip_connection.cpp.
References ulxr::Connection::getHandle(), pimpl, ulxr::TcpIpConnection::PImpl::server_data, setServerData(), ULXR_PCHAR, and ULXR_TRACE.
void ulxr::TcpIpConnection::open | ( | ) | [virtual] |
Opens the connection in client mode.
Implements ulxr::Connection.
Reimplemented in ulxr::SSLConnection, and funtik::SSLConnection.
Definition at line 486 of file ulxr_tcpip_connection.cpp.
References ulxr::ApplicationError, ulxr::gethostbyaddrMutex, ulxr::HtmlFormHandler::makeNumber(), ulxr::SystemError, ULXR_GET_STRING, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
Referenced by ulxr::SSLConnection::open(), ulxr::Log4JSender::open(), and funtik::SSLConnection::open().
bool ulxr::TcpIpConnection::accept | ( | int | timeout = 0 |
) | [virtual] |
Opens the connection in server mode, thus waiting for connections from clients.
timeout | the timeout value [sec] for incoming data (0 - no timeout) |
true
when connection has been accepted Implements ulxr::Connection.
Reimplemented in ulxr::SSLConnection.
Definition at line 567 of file ulxr_tcpip_connection.cpp.
References ulxr::ApplicationError, ulxr::gethostbyaddrMutex, ulxr::HtmlFormHandler::makeNumber(), ulxr::SystemError, ULXR_GET_STRING, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
Referenced by ulxr::SSLConnection::accept(), and funtik::SSLConnection::accept().
void ulxr::TcpIpConnection::close | ( | ) | [virtual] |
Closes the connection.
Reimplemented from ulxr::Connection.
Reimplemented in ulxr::SSLConnection, and funtik::SSLConnection.
Definition at line 825 of file ulxr_tcpip_connection.cpp.
References ulxr::Connection::close(), ULXR_PCHAR, and ULXR_TRACE.
Referenced by ulxr::TcpIpConnection::ServerSocketData::close(), ulxr::SSLConnection::close(), ulxr::Log4JSender::close(), and funtik::SSLConnection::close().
void ulxr::TcpIpConnection::shutdown | ( | int | mode | ) | [virtual] |
Shuts down the socket.
mode | shutdown mode
|
Implements ulxr::Connection.
Definition at line 804 of file ulxr_tcpip_connection.cpp.
References ulxr::TransportError, ULXR_PCHAR, and ULXR_TRACE.
Referenced by ulxr::TcpIpConnection::ServerSocketData::shutdown().
unsigned ulxr::TcpIpConnection::getPort | ( | ) |
Returns the configured port.
Definition at line 741 of file ulxr_tcpip_connection.cpp.
Referenced by ulxr::HttpProtocol::HttpProtocol().
CppString ulxr::TcpIpConnection::getHostName | ( | ) | const |
Gets the host name.
Definition at line 757 of file ulxr_tcpip_connection.cpp.
CppString ulxr::TcpIpConnection::getServerDomain | ( | ) | const |
Gets the server doamin.
Definition at line 763 of file ulxr_tcpip_connection.cpp.
CppString ulxr::TcpIpConnection::getPeerName | ( | ) | const |
Gets the name of the remote machine.
ĉattention Does not seem to work on all plattforms. Search source file for ULXR_ENABLE_GET_PEERNAME
on how to enable this features.
Definition at line 769 of file ulxr_tcpip_connection.cpp.
Referenced by ulxr::HttpProtocol::HttpProtocol().
void ulxr::TcpIpConnection::asciiToInAddr | ( | const char * | address, | |
struct in_addr & | saddr | |||
) |
Converts ascii text to in_addr struct.
address | literal string of address to convert | |
saddr | return struct with data |
Definition at line 389 of file ulxr_tcpip_connection.cpp.
References ulxr::gethostbynameMutex, ulxr::SystemError, ULXR_GET_STRING, ulxr_i18n, and ULXR_PCHAR.
int ulxr::TcpIpConnection::abortOnClose | ( | int | bOn | ) |
Sets abort on close flag for a socket.
bOn | sets SO_LINGER state of the socket on/off. |
Definition at line 835 of file ulxr_tcpip_connection.cpp.
void ulxr::TcpIpConnection::setTcpNoDelay | ( | bool | bOn | ) |
Sets the socket buffer mechanism.
By disabling the buffer mechanism all data is sent immediately. This may result in higher performance especially with persistent connections but will also increase network traffic with more but smaller packets. Use with care.
bOn | sets the TCP_NODELAY option on the socket |
Definition at line 850 of file ulxr_tcpip_connection.cpp.
CppString ulxr::TcpIpConnection::getInterfaceName | ( | ) | [virtual] |
Tests if the current transmission expects a return value.
Implements ulxr::Connection.
Reimplemented in ulxr::SSLConnection, and funtik::SSLConnection.
Definition at line 884 of file ulxr_tcpip_connection.cpp.
References ULXR_PCHAR.
int ulxr::TcpIpConnection::getLastError | ( | ) | [virtual] |
Portable function to return the current socket error number.
Reimplemented from ulxr::Connection.
Definition at line 890 of file ulxr_tcpip_connection.cpp.
Referenced by TcpIpConnection().
bool ulxr::TcpIpConnection::isServerMode | ( | ) | const |
Checks if the connection is run as server.
Definition at line 480 of file ulxr_tcpip_connection.cpp.
int ulxr::TcpIpConnection::getServerHandle | ( | ) | [virtual] |
Returns the server connection handle.
Implements ulxr::Connection.
Definition at line 788 of file ulxr_tcpip_connection.cpp.
Referenced by TcpIpConnection().
struct hostent * ulxr::TcpIpConnection::getHostAdress | ( | const CppString & | hostname | ) | [protected] |
Creates a hostent
struct from a host name.
hostent
structure Definition at line 416 of file ulxr_tcpip_connection.cpp.
References ulxr::gethostbynameMutex, ulxr::getLatin1(), and ULXR_PCHAR.
Referenced by TcpIpConnection().
TcpIpConnection * ulxr::TcpIpConnection::makeClone | ( | ) | [protected, virtual] |
Creates a shallow copy of this object.
Reimplemented in ulxr::SSLConnection.
Definition at line 259 of file ulxr_tcpip_connection.cpp.
void ulxr::TcpIpConnection::decrementServerRef | ( | bool | shutdown = false |
) | [protected, virtual] |
Decrements the reference count to the server data.
If the count reaches 0 the server is deleted.
shutdown | true: shutdown the socket |
Definition at line 455 of file ulxr_tcpip_connection.cpp.
References ulxr::TcpIpConnection::ServerSocketData::decRef(), ulxr::TcpIpConnection::ServerSocketData::isOpen(), pimpl, ulxr::TcpIpConnection::PImpl::server_data, ulxr::TcpIpConnection::ServerSocketData::shutdown(), ULXR_PCHAR, and ULXR_TRACE.
Referenced by ~TcpIpConnection().
void ulxr::TcpIpConnection::setServerData | ( | ServerSocketData * | serv_data | ) | [protected] |
Sets the pointer to the server-data.
The reference count to the previous server is decremented.
serv_data | pointer to server |
Definition at line 775 of file ulxr_tcpip_connection.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
Referenced by detach(), and funtik::SSLConnection::detach().
TcpIpConnection::ServerSocketData * ulxr::TcpIpConnection::getServerData | ( | ) | const [protected] |
Gets the pointer to the server-data.
Definition at line 797 of file ulxr_tcpip_connection.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
Referenced by funtik::SSLConnection::detach().
void ulxr::TcpIpConnection::init | ( | unsigned | port | ) | [private] |
Initializes internal variables.
port | the port used for the connection |
Definition at line 306 of file ulxr_tcpip_connection.cpp.
References ulxr::gethostbynameMutex, ulxr::getLatin1(), ulxr::SystemError, ULXR_GET_STRING, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
int ulxr::TcpIpConnection::doTcpNoDelay | ( | ) | [private] |
Sets the socket buffer mechanism.
Definition at line 859 of file ulxr_tcpip_connection.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
TcpIpConnection& ulxr::TcpIpConnection::operator= | ( | const TcpIpConnection & | ) | [private] |
PImpl* ulxr::TcpIpConnection::pimpl [private] |
Definition at line 245 of file ulxr_tcpip_connection.h.
Referenced by decrementServerRef(), detach(), TcpIpConnection(), and ~TcpIpConnection().
int ulxr::TcpIpConnection::noDelayOpt [private] |
Definition at line 247 of file ulxr_tcpip_connection.h.