qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From An Yang <an.eurof...@gmail.com>
Subject compile qpid program with C++0X thread failed
Date Fri, 02 May 2014 11:23:56 GMT
Hi all,

I'm using CentOS 6.5, and write a demo program with C++0x thread, it should
create sender and receiver thread, but I got the followings:
$g++ -std=c++0x -pthread qpid-thread.cpp  -o qpid-thread -lqpidmessaging
qpid-thread.cpp: In function 'void qpid::tests::qpidReceive()':
qpid-thread.cpp:27: error: no matching function for call to
'qpid::messaging::Receiver::fetch(qpid::messaging::Message&, int)'
/usr/include/qpid/messaging/Receiver.h:78: note: candidates are: bool
qpid::messaging::Receiver::fetch(qpid::messaging::Message&,
qpid::messaging::Duration)
/usr/include/qpid/messaging/Receiver.h:90: note:
qpid::messaging::Message
qpid::messaging::Receiver::fetch(qpid::messaging::Duration)

qpid-thread.cpp
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Session.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Sender.h>
#include <qpid/messaging/Message.h>

#include <iostream>       // std::cout
#include <thread>         // std::thread

using namespace qpid::messaging;
using namespace qpid::types;
//using namespace std;

namespace qpid {
namespace tests {

void qpidReceive()
{
Connection connection;
try {
    connection = Connection("ampq:tcp:localhost");
    connection.open();
    Session session = connection.createSession();
    Receiver receiver = session.createReceiver("benchmark");
    receiver.setCapacity(1000);
    Message msg;
    if (receiver.fetch(msg, 0))
        std::cout << "got a message" << std::endl;
    session.commit();
    session.acknowledge();
    session.close();
    connection.close();
    } catch(const std::exception& error) {
        std::cerr << "qpid-receive: " << error.what() << std::endl;
        connection.close();
    }
}

void qpidSend(int x)
{
Connection connection;
try {
    connection = Connection("ampq:tcp:localhost");
    connection.open();
    Session session = connection.createSession();
    Sender sender = session.createSender("benchmark");
    sender.setCapacity(1000);
    Message msg;
    msg.setDurable(false);
    //char * buf= new char [1024];
    //string buffer;
    //buffer.assign(buf, 1024);
    //msg.setContent(buffer);
    sender.send(msg);
    session.sync();
    session.close();
    connection.close();
    } catch(const std::exception& error) {
        std::cerr << "qpid-send: " << error.what() << std::endl;
        connection.close();
    }
}
}} // namespace qpid::tests

using namespace qpid::tests;

int main()
{
       std::thread send (qpidSend,0);  // spawn new thread that calls
qpidSend(0)
       std::thread receive (qpidReceive);     // spawn new thread that
calls qpidReceive()

       std::cout << "main, qpid-receive and qpid-send thread now execute
concurrently...\n";

       // synchronize threads:
       receive.join();                // pauses until receive finishes
       send.join();               // pauses until send finishes

       std::cout << "qpid-send and qpid-receive thread completed.\n";

       return 0;
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message