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__ )
46 const std::string& server,
int port )
52 const std::string& server,
int port )
101 m_server +
": connection refused" );
109 "Unknown error condition" );
129 if( m_cancel || m_socket < 0 )
135 if( !dataAvailable( timeout ) )
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;
156 #if defined(__unix__)
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 );
An abstract base class for a connection.
ConnectionDataHandler * m_handler
This is an abstract base class to receive events from a ConnectionBase-derived object.
virtual void handleReceivedData(const ConnectionBase *connection, const std::string &data)=0
virtual void handleDisconnect(const ConnectionBase *connection, ConnectionError reason)=0
virtual void handleConnect(const ConnectionBase *connection)=0
This is a base class for a simple TCP connection.
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.
void err(LogArea area, const std::string &message) const
The namespace for the gloox library.
@ LogAreaClassConnectionTCPClient