Skip to content
This repository was archived by the owner on Feb 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/SimplePocoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <cstring>
#include <cassert>
#include <iostream>

#include <Poco/Net/IPAddress.h>
#include <Poco/Net/StreamSocket.h>

#include "SimplePocoHandler.h"
Expand Down Expand Up @@ -84,6 +86,7 @@ struct SimplePocoHandlerImpl
Buffer outBuffer;
std::vector<char> tmpBuff;
};

SimplePocoHandler::SimplePocoHandler(const std::string& host, uint16_t port) :
m_impl(new SimplePocoHandlerImpl)
{
Expand All @@ -92,6 +95,14 @@ SimplePocoHandler::SimplePocoHandler(const std::string& host, uint16_t port) :
m_impl->socket.setKeepAlive(true);
}

SimplePocoHandler::SimplePocoHandler(const Poco::Net::IPAddress& ip, uint16_t port) :
m_impl(new SimplePocoHandlerImpl)
{
const Poco::Net::SocketAddress address(ip, port);
m_impl->socket.connect(address);
m_impl->socket.setKeepAlive(true);
}

SimplePocoHandler::~SimplePocoHandler()
{
close();
Expand Down
3 changes: 3 additions & 0 deletions src/SimplePocoHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <memory>
#include <amqpcpp.h>

#include <Poco/Net/IPAddress.h>

class SimplePocoHandlerImpl;
class SimplePocoHandler: public AMQP::ConnectionHandler
{
Expand All @@ -13,6 +15,7 @@ class SimplePocoHandler: public AMQP::ConnectionHandler
static constexpr size_t TEMP_BUFFER_SIZE = 1024 * 1024; //1Mb

SimplePocoHandler(const std::string& host, uint16_t port);
SimplePocoHandler(const Poco::Net::IPAddress& ip, uint16_t port);
virtual ~SimplePocoHandler();

void loop();
Expand Down
6 changes: 4 additions & 2 deletions src/send.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#include <iostream>
#include <Poco/Net/IPAddress.h>

#include "SimplePocoHandler.h"

int main(void)
{
SimplePocoHandler handler("localhost", 5672);
Poco::Net::IPAddress ip("127.0.0.1");
SimplePocoHandler handler(ip, 5672);

AMQP::Connection connection(&handler, AMQP::Login("guest", "guest"), "/");
AMQP::Channel channel(&connection);

channel.onReady([&]()
{
if(handler.connected())
if (handler.connected())
{
channel.publish("", "hello", "Hello World!");
std::cout << " [x] Sent 'Hello World!'" << std::endl;
Expand Down