void gpbridge_import_start(PG_FUNCTION_ARGS) { gphadoop_context* context = create_context(fcinfo); parse_gphd_uri(context, true, fcinfo); context->current_fragment = list_head(context->gphd_uri->fragments); build_uri_for_read(context); context->churl_headers = churl_headers_init(); add_querydata_to_http_header(context, fcinfo); set_current_fragment_headers(context); context->churl_handle = churl_init_download(context->uri.data, context->churl_headers); /* read some bytes to make sure the connection is established */ churl_read_check_connectivity(context->churl_handle); }
void churl_cleanup(CHURL_HANDLE handle, bool after_error) { churl_context* context = (churl_context*)handle; if (!context) return; /* don't try to read/write data after an error */ if (!after_error) { if (context->upload) finish_upload(context); else churl_read_check_connectivity(handle); } cleanup_curl_handle(context); cleanup_internal_buffer(context->download_buffer); cleanup_internal_buffer(context->upload_buffer); churl_cleanup_context(context); }
/* * Wrapper for libchurl */ static void process_request(ClientContext* client_context, char *uri) { size_t n = 0; char buffer[RAW_BUF_SIZE]; print_http_headers(client_context->http_headers); client_context->handle = churl_init_download(uri, client_context->http_headers); memset(buffer, 0, RAW_BUF_SIZE); resetStringInfo(&(client_context->the_rest_buf)); /* * This try-catch ensures that in case of an exception during the "communication with PXF and the accumulation of * PXF data in client_context->the_rest_buf", we still get to terminate the libcurl connection nicely and avoid * leaving the PXF server connection hung. */ PG_TRY(); { /* read some bytes to make sure the connection is established */ churl_read_check_connectivity(client_context->handle); while ((n = churl_read(client_context->handle, buffer, sizeof(buffer))) != 0) { appendBinaryStringInfo(&(client_context->the_rest_buf), buffer, n); memset(buffer, 0, RAW_BUF_SIZE); } churl_cleanup(client_context->handle, false); } PG_CATCH(); { if (client_context->handle) churl_cleanup(client_context->handle, true); PG_RE_THROW(); } PG_END_TRY(); }