improvements to work directly with tcp connections

This commit is contained in:
Emiel Bruijntjes 2015-10-31 21:13:41 +01:00
parent 189d6c9ef1
commit df801953a1
6 changed files with 69 additions and 10 deletions

View File

@ -67,7 +67,9 @@
#include <amqpcpp/channelimpl.h> #include <amqpcpp/channelimpl.h>
#include <amqpcpp/channel.h> #include <amqpcpp/channel.h>
#include <amqpcpp/login.h> #include <amqpcpp/login.h>
#include <amqpcpp/address.h>
#include <amqpcpp/connectionhandler.h> #include <amqpcpp/connectionhandler.h>
#include <amqpcpp/connectionimpl.h> #include <amqpcpp/connectionimpl.h>
#include <amqpcpp/connection.h> #include <amqpcpp/connection.h>
#include <amqpcpp/tcphandler.h>
#include <amqpcpp/tcpconnection.h>

View File

@ -1,15 +1,24 @@
#pragma once
/** /**
* Class describing a (mid-level) AMQP channel implementation * Class describing a (mid-level) AMQP channel implementation
* *
* @copyright 2014 Copernica BV * @copyright 2014 Copernica BV
*/ */
/**
* Include guard
*/
#pragma once
/** /**
* Set up namespace * Set up namespace
*/ */
namespace AMQP { namespace AMQP {
/**
* Forward declarations
*/
class TcpConnection;
/** /**
* Class definition * Class definition
*/ */
@ -32,7 +41,17 @@ public:
// attach the connection to the channel // attach the connection to the channel
_implementation->attach(connection); _implementation->attach(connection);
} }
/**
* Construct a channel around a wrapped-connection
* @param connection
*/
Channel(TcpConnection *connection) : _implementation(new ChannelImpl())
{
// attach the connection to the channel
_implementation->attach(connection);
}
/** /**
* Copy'ing of channel objects is not supported * Copy'ing of channel objects is not supported
* @param channel * @param channel

View File

@ -18,6 +18,7 @@ namespace AMQP {
* Forward declarations * Forward declarations
*/ */
class ConsumedMessage; class ConsumedMessage;
class TcpConnection;
/** /**
* Class definition * Class definition
@ -109,6 +110,12 @@ private:
*/ */
void attach(Connection *connection); void attach(Connection *connection);
/**
* Attach the connection
* @param connection
*/
void attach(TcpConnection *connection);
/** /**
* Push a deferred result * Push a deferred result
* @param result The deferred result * @param result The deferred result

View File

@ -26,17 +26,22 @@ class TcpState;
/** /**
* Class definition * Class definition
*/ */
class TcpConnection : public Connection, private ConnectionHandler class TcpConnection : private ConnectionHandler
{ {
private: private:
/** /**
* The state of the TCP connection - this state objecs changes based on * The state of the TCP connection - this state objecs changes based on
* the state of the connection (resolving, connected or closed) * the state of the connection (resolving, connected or closed)
*
* @var TcpState * @var TcpState
*/ */
TcpState *_state = nullptr; TcpState *_state = nullptr;
/**
* The underlying AMQP connection
* @var Connection
*/
Connection _connection;
/** /**
* Method that is called by the connection when data needs to be sent over the network * Method that is called by the connection when data needs to be sent over the network
@ -65,6 +70,22 @@ private:
*/ */
virtual void onClosed(Connection *connection) override; virtual void onClosed(Connection *connection) override;
/**
* Parse a buffer that was received
* @param buffer
*/
uint64_t parse(const Buffer &buffer)
{
// pass to the AMQP connection
return _connection.parse(buffer);
}
/**
* Classes that have access to private data
*/
friend class TcpConnected;
friend class ChannelImpl;
public: public:
/** /**

View File

@ -90,6 +90,16 @@ void ChannelImpl::attach(Connection *connection)
} }
} }
/**
* Initialize the object with an connection
* @param connection
*/
void ChannelImpl::attach(TcpConnection *connection)
{
// pass to the other attach() method
attach(&connection->_connection);
}
/** /**
* Push a deferred result * Push a deferred result
* @param result The deferred object to push * @param result The deferred object to push

View File

@ -21,12 +21,12 @@ namespace AMQP {
/** /**
* Constructor * Constructor
* @param handler User implemented handler object * @param handler User implemented handler object
* @param address AMQP address object * @param hostname The address to connect to
*/ */
TcpConnection::TcpConnection(TcpHandler *handler, const Address &address) : TcpConnection::TcpConnection(TcpHandler *handler, const Address &address) :
Connection(this, address.login(), address.vhost()), _state(new TcpResolver(this, address.hostname(), address.port(), handler)),
_state(new TcpResolver(this, address.hostname(), address.port(), handler)) {} _connection(this, address.login(), address.vhost()) {}
/** /**
* Destructor * Destructor
*/ */