Example #1
0
const CassErrorResult* cass_future_get_error_result(CassFuture* future) {
  if (future->type() != cass::CASS_FUTURE_TYPE_RESPONSE) {
    return NULL;
  }
  cass::ResponseFuture* response_future =
      static_cast<cass::ResponseFuture*>(future->from());

  if (!response_future->is_error()) return NULL;

  cass::SharedRefPtr<cass::ErrorResponse> error_result(response_future->response());
  if (error_result) error_result->inc_ref();
  return CassErrorResult::to(error_result.get());
}
Example #2
0
static void test_error(void)
{
    char* error = malloc(32);
    struct result* result = 0;

    sprintf(error, "some error message");

    result = error_result(error);

    CU_ASSERT_PTR_NOT_NULL_FATAL(result);
    CU_ASSERT_STRING_EQUAL(result->error, "some error message");
    CU_ASSERT_PTR_NULL(result->data);
    CU_ASSERT_PTR_NULL(result->free_data);
    CU_ASSERT_PTR_NULL(result->location);

    free_result(result);
}
Example #3
0
    int
main(int argc, char *argv[])
{
    PROCKET_STATE *ps = NULL;
    int ch = 0;


    ps = calloc(1, sizeof(PROCKET_STATE));

    if (ps == NULL)
        error_result(ps, errno);

    ps->backlog = BACKLOG;

    ps->family = PF_UNSPEC; /* bind IPv4 and IPv6 socket */
    ps->type = SOCK_STREAM;
    ps->protocol = IPPROTO_TCP;

    ps->fdtype = PROCKET_FD_SOCKET;

    while ( (ch = getopt(argc, argv, "b:d:F:hI:p:P:T:u:v")) != -1) {
        switch (ch) {
            case 'b':   /* listen backlog */
                ps->backlog = atoi(optarg);
                break;
            case 'F':   /* socket family/domain */
                ps->family = atoi(optarg);
                break;
            case 'u':   /* path to Unix socket */
                ps->path = strdup(optarg);

                if (ps->path == NULL)
                    error_result(ps, errno);

                if (strlen(ps->path) >= UNIX_PATH_MAX)
                    error_result(ps, ENAMETOOLONG);
                break;
            case 'p':   /* port */
                ps->port = strdup(optarg);

                if (ps->port == NULL)
                    error_result(ps, errno);

                if (strlen(ps->port) >= NI_MAXSERV)
                    error_result(ps, ENAMETOOLONG);
                break;
            case 'P':   /* socket protocol */
                ps->protocol = atoi(optarg);
                break;
            case 'T':   /* socket type */
                ps->type = atoi(optarg);
                break;
            case 'I':   /* Interface name */
                ps->ifname = strdup(optarg);

                if (ps->ifname == NULL)
                    error_result(ps, errno);

                if (strlen(ps->ifname) >= IFNAMSIZ)
                    error_result(ps, ENAMETOOLONG);
                break;
            case 'd':   /* Open a character device */
                ps->dev = strdup(optarg);

                if (ps->dev == NULL)
                    error_result(ps, errno);

                if (procket_check_devname(ps->dev, 32) < 0)
                    usage(ps);

                ps->fdtype = PROCKET_FD_CHARDEV;
                break;
            case 'v':
                ps->verbose++;
                break;
            case 'h':
            default:
                usage(ps);
        }
    }

    argc -= optind;
    argv += optind;

    if (ps->path == NULL)
        error_result(ps, ENOENT);

    if (argc > 0) {
        ps->address = strdup(argv[0]);

        if (ps->address == NULL)
            error_result(ps, errno);

        if (strlen(ps->address) >= NI_MAXHOST)
            error_result(ps, ENAMETOOLONG);
    }

    if (procket_open_fd(ps) < 0)
        error_result(ps, errno);

    if ( (setgid(getgid()) < 0) || (setuid(getuid()) < 0))
        error_result(ps, errno);

    if (procket_pipe(ps) < 0)
        error_result(ps, errno);

    exit(0);
}