Exemple #1
0
static void pni_connection_writable(pn_selectable_t *sel)
{
  pn_reactor_t *reactor = (pn_reactor_t *) pni_selectable_get_context(sel);
  pn_transport_t *transport = pni_transport(sel);
  ssize_t pending = pn_transport_pending(transport);
  if (pending > 0) {
    ssize_t n = pn_send(pni_reactor_io(reactor), pn_selectable_get_fd(sel),
                        pn_transport_head(transport), pending);
    if (n < 0) {
      if (!pn_wouldblock(pni_reactor_io(reactor))) {
        pn_condition_t *cond = pn_transport_condition(transport);
        if (!pn_condition_is_set(cond)) {
          pn_condition_set_name(cond, "proton:io");
          pn_condition_set_description(cond, pn_error_text(pn_reactor_error(reactor)));
        }
        pn_transport_close_head(transport);
      }
    } else {
      pn_transport_pop(transport, n);
    }
  }

  ssize_t newpending = pn_transport_pending(transport);
  if (newpending != pending) {
    pni_connection_update(sel);
    pn_reactor_update(reactor, sel);
  }
}
const_buffer connection_engine::write_buffer() const {
    ssize_t pending = pn_transport_pending(unwrap(transport_));
    if (pending > 0)
        return const_buffer(pn_transport_head(unwrap(transport_)), pending);
    else
        return const_buffer(0, 0);
}
void connection_engine::try_write() {
    size_t max = can_write();
    if (max == 0) return;
    try {
        size_t n = io_write(pn_transport_head(ctx_->transport), max);
        if (n > max) {
            throw io_error(msg() << "write invalid size: " << n << " > " << max);
        }
        pn_transport_pop(ctx_->transport, n);
    } catch (const closed_error&) {
        pn_transport_close_head(ctx_->transport);
    } catch (const io_error& e) {
        set_error(ctx_, e.what());
        pn_transport_close_head(ctx_->transport);
    }
}