예제 #1
0
int pn_scanner_verr(pn_scanner_t *scanner, int code, const char *fmt, va_list ap)
{
  char error[ERROR_SIZE];

  int line, col;
  pn_scanner_line_info(scanner, &line, &col);
  int size = scanner->token.size;
  int ln = snprintf(error, ERROR_SIZE,
                    "input line %i column %i %s:'%.*s': ", line, col,
                    pn_token_type(scanner->token.type),
                    size, scanner->token.start);
  if (ln >= ERROR_SIZE) {
    return pn_scanner_err(scanner, code, "error info truncated");
  } else if (ln < 0) {
    error[0] = '\0';
  }

  int n = snprintf(error + ln, ERROR_SIZE - ln, fmt, ap);

  if (n >= ERROR_SIZE - ln) {
    return pn_scanner_err(scanner, code, "error info truncated");
  } else if (n < 0) {
    error[0] = '\0';
  }

  return pn_error_set(scanner->error, code, error);
}
예제 #2
0
int pn_error_vformat(pn_error_t *error, int code, const char *fmt, va_list ap)
{
  char text[1024];
  int n = vsnprintf(text, 1024, fmt, ap);
  if (n >= 1024) {
    text[1023] = '\0';
  }
  return pn_error_set(error, code, text);
}
예제 #3
0
파일: iocp.c 프로젝트: JemDay/qpid-proton
static void set_iocp_error_status(pn_error_t *error, int code, HRESULT status)
{
  char buf[512];
  if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_FROM_SYSTEM,
                    0, status, 0, buf, sizeof(buf), 0))
    pn_error_set(error, code, buf);
  else {
    fprintf(stderr, "pn internal Windows error: %lu\n", GetLastError());
  }
}
예제 #4
0
int pn_error_copy(pn_error_t *error, pn_error_t *src)
{
  assert(error);
  if (src) {
    return pn_error_set(error, pn_error_code(src), pn_error_text(src));
  } else {
    pn_error_clear(error);
    return 0;
  }
}
예제 #5
0
int pn_messenger_put(pn_messenger_t *messenger, pn_message_t *msg)
{
  if (!messenger) return PN_ARG_ERR;
  if (!msg) return pn_error_set(messenger->error, PN_ARG_ERR, "null message");
  outward_munge(messenger, msg);
  const char *address = pn_message_get_address(msg);
  pn_link_t *sender = pn_messenger_target(messenger, address);
  if (!sender)
    return pn_error_format(messenger->error, PN_ERR,
                           "unable to send to address: %s (%s)", address,
                           pn_driver_error(messenger->driver));
  // XXX: proper tag
  char tag[8];
  void *ptr = &tag;
  uint64_t next = messenger->next_tag++;
  *((uint32_t *) ptr) = next;
  pn_delivery(sender, pn_dtag(tag, 8));
  size_t size = 1024;
  // XXX: max message size
  while (size < 16*1024) {
    char encoded[size];
    int err = pn_message_encode(msg, encoded, &size);
    if (err == PN_OVERFLOW) {
      size *= 2;
    } else if (err) {
      return err;
    } else {
      ssize_t n = pn_send(sender, encoded, size);
      if (n < 0) {
        return n;
      } else {
        pn_advance(sender);
        pn_messenger_tsync(messenger, false_pred, 0);
        return 0;
      }
    }
  }

  return PN_ERR;
}