Method: OvirtSDK4::HttpClient#wait

Defined in:
ext/ovirtsdk4c/ov_http_client.c

#wait(request) ⇒ Object

[View source]

1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
# File 'ext/ovirtsdk4c/ov_http_client.c', line 1110

static VALUE ov_http_client_wait(VALUE self, VALUE request) {
    VALUE next;
    VALUE result;
    ov_http_client_object* ptr;
    ov_http_client_wait_context context;

    /* Get the pointer to the native object and check that it isn't closed: */
    ov_http_client_ptr(self, ptr);
    ov_http_client_check_closed(ptr);

    /* Work till the transfer has been completed. */
    context.handle = ptr->handle;
    context.code = CURLE_OK;
    context.cancel = false;
    for (;;) {
        /* Move requests from the queue to libcurl: */
        while (RARRAY_LEN(ptr->queue) > 0 && RHASH_SIZE(ptr->pending) < ptr->limit) {
            next = rb_ary_shift(ptr->queue);
            ov_http_client_submit(self, next);
        }

        /* Check if the response is already available, if so then return it: */
        result = rb_hash_delete(ptr->completed, request);
        if (!NIL_P(result)) {
            return result;
        }

        /* If the response isn't available yet, then do some real work: */
        rb_thread_call_without_gvl(
            ov_http_client_wait_task,
            &context,
            ov_http_client_wait_cancel,
            &context
        );
        if (context.cancel) {
            return Qnil;
        }
        if (context.code != CURLE_OK) {
            rb_raise(ov_error_class, "Unexpected error while waiting: %s", curl_easy_strerror(context.code));
        }
    }

    return Qnil;
}