void blocking_connection_impl::wait(const condition &condition, const std::string &msg, duration wait_timeout)
{
    reactor& reactor = container_->reactor();

    if (wait_timeout == duration(-1))
        wait_timeout = container_->reactor().timeout();

    if (wait_timeout == duration::FOREVER) {
        while (!condition()) {
            reactor.process();
        }
    } else {
        save_timeout st(reactor);
        reactor.timeout(wait_timeout);
        pn_timestamp_t deadline = pn_reactor_mark(pn_cast(&reactor)) + wait_timeout.milliseconds;
        while (!condition()) {
            reactor.process();
            if (!condition()) {
                pn_timestamp_t now = pn_reactor_mark(pn_cast(&reactor));
                if (now < deadline)
                    reactor.timeout(duration(deadline - now));
                else
                    throw timeout_error("connection timed out " + msg);
            }
        }
    }
}
Пример #2
0
bool encoder::encode(char* buffer, size_t& size) {
    save_state ss(pn_cast(this)); // In case of error
    ssize_t result = pn_data_encode(pn_cast(this), buffer, size);
    if (result == PN_OVERFLOW) {
        result = pn_data_encoded_size(pn_cast(this));
        if (result >= 0) {
            size = result;
            return false;
        }
    }
    check(result, pn_cast(this));
    size = result;
    ss.cancel();                // Don't restore state, all is well.
    pn_data_clear(pn_cast(this));
    return true;
}
blocking_connection_impl::blocking_connection_impl(const url& url, duration timeout) :
    container_(new container())
{
    container_->reactor().start();
    container_->reactor().timeout(timeout);
    connection_ = container_->connect(url, this).ptr(); // Set this as handler.
    wait(connection_opening(pn_cast(connection_.get())));
}
Пример #4
0
session& connection::default_session() {
    struct connection_context& ctx = connection_context::get(pn_cast(this));
    if (!ctx.default_session) {
        ctx.default_session = &create_session();
        ctx.default_session->open();
    }
    return *ctx.default_session;
}
Пример #5
0
encoder& operator<<(encoder& e, const start& s) {
    switch (s.type) {
    case ARRAY:
        pn_data_put_array(pn_cast(&e), s.is_described, pn_type_t(s.element));
        break;
    case MAP:
        pn_data_put_map(pn_cast(&e));
        break;
    case LIST:
        pn_data_put_list(pn_cast(&e));
        break;
    case DESCRIBED:
        pn_data_put_described(pn_cast(&e));
        break;
    default:
        throw encode_error(MSG("" << s.type << " is not a container type"));
    }
    pn_data_enter(pn_cast(&e));
    return e;
}
Пример #6
0
encoder& operator<<(encoder& e, amqp_long value) {
    return insert(e, pn_cast(&e), value, pn_data_put_long);
}
Пример #7
0
encoder& operator<<(encoder& e, amqp_timestamp value) {
    return insert(e, pn_cast(&e), value, pn_data_put_timestamp);
}
Пример #8
0
data& encoder::data() {
    return *data::cast(pn_cast(this));
}
Пример #9
0
terminus& link::remote_target() const { return *terminus::cast(pn_link_remote_target(pn_cast(this))); }
Пример #10
0
encoder& operator<<(encoder& e, amqp_symbol value) {
    return insert(e, pn_cast(&e), value, pn_data_put_symbol);
}
Пример #11
0
encoder& operator<<(encoder& e, const data& v) {
    if (pn_cast(&e) == pn_cast(&v)) throw encode_error("cannot insert into self");
    check(pn_data_append(pn_cast(&e), pn_cast(&v)), pn_cast(&e));
    return e;
}
Пример #12
0
endpoint::state link::state() const { return pn_link_state(pn_cast(this)); }
Пример #13
0
encoder& operator<<(encoder& e, amqp_decimal128 value) {
    return insert(e, pn_cast(&e), value, pn_data_put_decimal128);
}
Пример #14
0
void link::handler(class handler &h) {
    pn_record_t *record = pn_link_attachments(pn_cast(this));
    connection_context& cc(connection_context::get(pn_cast(&connection())));
    counted_ptr<pn_handler_t> chandler = cc.container_impl->cpp_handler(&h);
    pn_record_set_handler(record, chandler.get());
}
Пример #15
0
void link::detach_handler() {
    pn_record_t *record = pn_link_attachments(pn_cast(this));
    pn_record_set_handler(record, 0);
}
Пример #16
0
class session &link::session() const {
    return *session::cast(pn_link_session(pn_cast(this)));
}
Пример #17
0
class connection &link::connection() const {
    return *connection::cast(pn_session_connection(pn_link_session(pn_cast(this))));
}
Пример #18
0
std::string link::name() const { return std::string(pn_link_name(pn_cast(this)));}
Пример #19
0
encoder& operator<<(encoder& e, amqp_float value) {
    return insert(e, pn_cast(&e), value, pn_data_put_float);
}
Пример #20
0
delivery& blocking_sender::send(const message_value &msg, duration timeout) {
    delivery& dlv = sender().send(msg);
    connection_.impl_->wait(delivery_settled(pn_cast(&dlv)), "sending on sender " + link_->name(), timeout);
    return dlv;
}
Пример #21
0
encoder& operator<<(encoder& e, amqp_double value) {
    return insert(e, pn_cast(&e), value, pn_data_put_double);
}
Пример #22
0
encoder& operator<<(encoder& e, finish) {
    pn_data_exit(pn_cast(&e));
    return e;
}
Пример #23
0
encoder& operator<<(encoder& e, amqp_uuid value) {
    return insert(e, pn_cast(&e), value, pn_data_put_uuid);
}
Пример #24
0
int link::credit() const {
    return pn_link_credit(pn_cast(this));
}
Пример #25
0
encoder& operator<<(encoder& e, amqp_binary value) {
    return insert(e, pn_cast(&e), value, pn_data_put_binary);
}
Пример #26
0
encoder& operator<<(encoder& e, amqp_boolean value) {
    return insert(e, pn_cast(&e), value, pn_data_put_bool);
}
Пример #27
0
const receiver* link::receiver() const {
    return pn_link_is_receiver(pn_cast(this)) ? reinterpret_cast<const class receiver*>(this) : 0;
}
Пример #28
0
encoder& operator<<(encoder& e, amqp_char value) {
    return insert(e, pn_cast(&e), value, pn_data_put_char);
}
Пример #29
0
encoder& operator<<(encoder& e, amqp_null) {
    pn_data_put_null(pn_cast(&e));
    return e;
}
Пример #30
0
terminus& link::remote_source() const { return *terminus::cast(pn_link_remote_source(pn_cast(this))); }