18#include "connectiontcpclient.h"
21#include "mutexguard.h"
28#if ( !defined( _WIN32 ) && !defined( _WIN32_WCE ) ) || defined( __SYMBIAN32__ )
29# include <sys/types.h>
30# include <sys/socket.h>
31# include <sys/select.h>
35#elif ( defined( _WIN32 ) || defined( _WIN32_WCE ) ) && !defined( __SYMBIAN32__ )
101 m_server +
": connection refused" );
109 "Unknown error condition" );
129 if( m_cancel || m_socket < 0 )
131 m_recvMutex.unlock();
135 if( !dataAvailable( timeout ) )
137 m_recvMutex.unlock();
141#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
142 int size =
static_cast<int>(
::recv( m_socket, m_buf, m_bufsize, 0 ) );
144 int size =
static_cast<int>(
::recv( m_socket, m_buf, m_bufsize, MSG_DONTWAIT ) );
147 m_totalBytesIn += size;
149 m_recvMutex.unlock();
157 if( errno == EAGAIN || errno == EWOULDBLOCK )
162 std::string message =
"recv() failed. "
163#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
164 "WSAGetLastError: " + util::int2string( ::WSAGetLastError() );
166 "errno: " + util::int2string( errno ) +
": " + strerror( errno );
173 m_handler->handleDisconnect(
this, error );
180 m_handler->handleReceivedData(
this, std::string( m_buf, size ) );
An abstract base class for a connection.
const std::string & server() const
ConnectionDataHandler * m_handler
This is an abstract base class to receive events from a ConnectionBase-derived object.
ConnectionTCPBase(const LogSink &logInstance, const std::string &server, int port=-1)
virtual ConnectionError recv(int timeout=-1)
virtual ConnectionBase * newInstance() const
virtual ConnectionError connect()
ConnectionTCPClient(const LogSink &logInstance, const std::string &server, int port=-1)
virtual ~ConnectionTCPClient()
static int connect(const std::string &host, const LogSink &logInstance)
An implementation of log sink and source.
The namespace for the gloox library.
@ LogAreaClassConnectionTCPClient