connectiontcpbase.h
/*
Copyright (c) 2004-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef CONNECTIONTCPBASE_H__
#define CONNECTIONTCPBASE_H__
#include "gloox.h"
#include "connectionbase.h"
#include "logsink.h"
#include "mutex.h"
#ifdef __MINGW32__
#include <ws2tcpip.h>
#endif
#include <string>
namespace gloox
{
namespace util
{
class Mutex;
}
class GLOOX_API ConnectionTCPBase : public ConnectionBase
{
public:
ConnectionTCPBase( const LogSink& logInstance, const std::string& server, int port = -1 );
ConnectionTCPBase( ConnectionDataHandler* cdh, const LogSink& logInstance,
const std::string& server, int port = -1 );
virtual ~ConnectionTCPBase();
// reimplemented from ConnectionBase
virtual bool send( const std::string& data );
// reimplemented from ConnectionBase
virtual ConnectionError receive();
// reimplemented from ConnectionBase
virtual void disconnect();
// reimplemented from ConnectionBase
virtual void cleanup();
// reimplemented from ConnectionBase
virtual void getStatistics( long int &totalIn, long int &totalOut );
int socket() const { return m_socket; }
void setSocket( int socket ) { m_cancel = false; m_state = StateConnected; m_socket = socket; }
virtual int localPort() const;
virtual const std::string localInterface() const;
protected:
ConnectionTCPBase& operator=( const ConnectionTCPBase& );
void init( const std::string& server, int port );
bool dataAvailable( int timeout = -1 );
void cancel();
const LogSink& m_logInstance;
util::Mutex m_sendMutex;
util::Mutex m_recvMutex;
char* m_buf;
int m_socket;
long int m_totalBytesIn;
long int m_totalBytesOut;
const int m_bufsize;
bool m_cancel;
};
}
#endif // CONNECTIONTCPBASE_H__
gloox::ConnectionBase::m_state
ConnectionState m_state
Definition connectionbase.h:155
gloox::ConnectionBase::port
int port() const
Definition connectionbase.h:121
gloox::ConnectionBase::server
const std::string & server() const
Definition connectionbase.h:115
gloox::ConnectionBase::ConnectionBase
ConnectionBase(ConnectionDataHandler *cdh)
Definition connectionbase.h:42
gloox::ConnectionDataHandler
This is an abstract base class to receive events from a ConnectionBase-derived object.
Definition connectiondatahandler.h:36
gloox::ConnectionTCPBase
This is a base class for a simple TCP connection.
Definition connectiontcpbase.h:45
gloox::ConnectionTCPBase::setSocket
void setSocket(int socket)
Definition connectiontcpbase.h:103
gloox::ConnectionTCPBase::cleanup
virtual void cleanup()
Definition connectiontcpbase.cpp:167
gloox::ConnectionTCPBase::ConnectionTCPBase
ConnectionTCPBase(const LogSink &logInstance, const std::string &server, int port=-1)
Definition connectiontcpbase.cpp:53
gloox::ConnectionTCPBase::disconnect
virtual void disconnect()
Definition connectiontcpbase.cpp:86
gloox::ConnectionTCPBase::send
virtual bool send(const std::string &data)
Definition connectiontcpbase.cpp:123
gloox::ConnectionTCPBase::socket
int socket() const
Definition connectiontcpbase.h:95
gloox::ConnectionTCPBase::receive
virtual ConnectionError receive()
Definition connectiontcpbase.cpp:112
gloox::ConnectionTCPBase::getStatistics
virtual void getStatistics(long int &totalIn, long int &totalOut)
Definition connectiontcpbase.cpp:161
gloox::LogSink
An implementation of log sink and source.
Definition logsink.h:39
gloox::util::Mutex
A simple implementation of mutex as a wrapper around a pthread mutex or a win32 critical section.
Definition mutex.h:34
gloox::util
A namespace holding a couple utility functions.
Definition atomicrefcount.cpp:36
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::ConnectionError
ConnectionError
Definition gloox.h:684
gloox::StateConnected
@ StateConnected
Definition gloox.h:644