bool_t AsyncAcceptor::OnRead(EventResult *evr) { bool_t ret = FALSE; ret = MakeNewConnection(); if(!ret) { ECILA_TRACE(); return FALSE; } AsyncSession* sess = (AsyncSession*)evr->AcceptHandler(); if(!sess) { ECILA_TRACE(); return FALSE; } Socket *sock = (Socket *)sess->Handle(); if(!sock) { ECILA_TRACE(); return FALSE; } ret = sock->SetUpdateAcceptContext((Socket*)this->Handle()); if(!ret) { ECILA_TRACE(); return FALSE; } ret = GetPeerInfomation(evr->Buffer(), evr->BufferSize(), sess); if(!ret) { ECILA_TRACE(); return FALSE; } ret = sess->RecvBuffer()->Reset(); if(!ret) { ECILA_TRACE(); return FALSE; } ret = sess->PostOpen(); if(!ret) { ECILA_TRACE(); return FALSE; } ret = sess->PostRead(); if(!ret) { ECILA_TRACE(); return FALSE; } return TRUE; }
int main(int argc, char** argv) { try { qpid::tests::PingOptions opts; opts.parse(argc, argv); opts.con.heartbeat = (opts.timeout+1)/2; Connection connection; opts.open(connection); if (!opts.quiet) cout << "Opened connection." << endl; AsyncSession s = connection.newSession(); string qname(Uuid(true).str()); s.queueDeclare(queue=qname, autoDelete=true, exclusive=true); s.messageTransfer(content=Message("hello", qname)); if (!opts.quiet) cout << "Sent message." << endl; SubscriptionManager subs(s); subs.get(qname); if (!opts.quiet) cout << "Received message." << endl; s.sync(); s.close(); connection.close(); if (!opts.quiet) cout << "Success." << endl; return 0; } catch (const exception& e) { cerr << "Error: " << e.what() << endl; return 1; } }
void execute(AsyncSession& session, bool isRetry) { if (isRetry) QPID_LOG(info, "Retrying..."); session.txSelect(); SubscriptionManager subs(session); transfer.subscribeToControl(subs); subs.run(); session.txCommit();//commit accept of control messages }
void Listener::received(Message& request) { Message response; // Get routing key for response from the request's replyTo property string routingKey; if (request.getMessageProperties().hasReplyTo()) { routingKey = request.getMessageProperties().getReplyTo().getRoutingKey(); } else { std::cout << "Error: " << "No routing key for request (" << request.getData() << ")" << std::endl; return; } std::cout << "Request: " << request.getData() << " (" <<routingKey << ")" << std::endl; // Transform message content to upper case std::string s = request.getData(); std::transform (s.begin(), s.end(), s.begin(), toupper); response.setData(s); // Send it back to the user response.getDeliveryProperties().setRoutingKey(routingKey); // Asynchronous transfer sends messages as quickly as // possible without waiting for confirmation. asyncSession.messageTransfer(arg::content=response, arg::destination="amq.direct"); }
~Client() { try { if (connection->isOpen()) { session.close(); connection->close(); } } catch (const std::exception& e) { std::cerr << "Error in shutdown: " << e.what() << std::endl; } }