improvements to work directly with tcp connections
This commit is contained in:
parent
189d6c9ef1
commit
df801953a1
|
|
@ -67,7 +67,9 @@
|
|||
#include <amqpcpp/channelimpl.h>
|
||||
#include <amqpcpp/channel.h>
|
||||
#include <amqpcpp/login.h>
|
||||
#include <amqpcpp/address.h>
|
||||
#include <amqpcpp/connectionhandler.h>
|
||||
#include <amqpcpp/connectionimpl.h>
|
||||
#include <amqpcpp/connection.h>
|
||||
|
||||
#include <amqpcpp/tcphandler.h>
|
||||
#include <amqpcpp/tcpconnection.h>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,24 @@
|
|||
#pragma once
|
||||
/**
|
||||
* Class describing a (mid-level) AMQP channel implementation
|
||||
*
|
||||
* @copyright 2014 Copernica BV
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include guard
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Set up namespace
|
||||
*/
|
||||
namespace AMQP {
|
||||
|
||||
/**
|
||||
* Forward declarations
|
||||
*/
|
||||
class TcpConnection;
|
||||
|
||||
/**
|
||||
* Class definition
|
||||
*/
|
||||
|
|
@ -32,7 +41,17 @@ public:
|
|||
// attach the connection to the channel
|
||||
_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
|
||||
* @param channel
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace AMQP {
|
|||
* Forward declarations
|
||||
*/
|
||||
class ConsumedMessage;
|
||||
class TcpConnection;
|
||||
|
||||
/**
|
||||
* Class definition
|
||||
|
|
@ -109,6 +110,12 @@ private:
|
|||
*/
|
||||
void attach(Connection *connection);
|
||||
|
||||
/**
|
||||
* Attach the connection
|
||||
* @param connection
|
||||
*/
|
||||
void attach(TcpConnection *connection);
|
||||
|
||||
/**
|
||||
* Push a deferred result
|
||||
* @param result The deferred result
|
||||
|
|
|
|||
|
|
@ -26,17 +26,22 @@ class TcpState;
|
|||
/**
|
||||
* Class definition
|
||||
*/
|
||||
class TcpConnection : public Connection, private ConnectionHandler
|
||||
class TcpConnection : private ConnectionHandler
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The state of the TCP connection - this state objecs changes based on
|
||||
* the state of the connection (resolving, connected or closed)
|
||||
*
|
||||
* @var TcpState
|
||||
*/
|
||||
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
|
||||
|
|
@ -65,6 +70,22 @@ private:
|
|||
*/
|
||||
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:
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* @param result The deferred object to push
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ namespace AMQP {
|
|||
/**
|
||||
* Constructor
|
||||
* @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) :
|
||||
Connection(this, address.login(), address.vhost()),
|
||||
_state(new TcpResolver(this, address.hostname(), address.port(), handler)) {}
|
||||
|
||||
TcpConnection::TcpConnection(TcpHandler *handler, const Address &address) :
|
||||
_state(new TcpResolver(this, address.hostname(), address.port(), handler)),
|
||||
_connection(this, address.login(), address.vhost()) {}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue