MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / cdb2_close

Function cdb2_close

cdb2api/cdb2api.c:3584–3690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3582}
3583
3584int cdb2_close(cdb2_hndl_tp *hndl)
3585{
3586 cdb2_event *curre;
3587 void *callbackrc;
3588 int rc = 0;
3589
3590 if (log_calls)
3591 fprintf(stderr, "%p> cdb2_close(%p)\n", (void *)pthread_self(), hndl);
3592
3593 if (!hndl)
3594 return 0;
3595
3596 if (hndl->fdb_hndl) {
3597 cdb2_close(hndl->fdb_hndl);
3598 hndl->fdb_hndl = NULL;
3599 }
3600
3601 if (hndl->ack)
3602 ack(hndl);
3603
3604 if (hndl->auto_consume_timeout_ms > 0 && hndl->sb && !hndl->in_trans && hndl->firstresponse &&
3605 (!hndl->lastresponse || (hndl->lastresponse->response_type != RESPONSE_TYPE__LAST_ROW))) {
3606 int nrec = 0;
3607 sbuf2settimeout(hndl->sb, hndl->auto_consume_timeout_ms, hndl->auto_consume_timeout_ms);
3608 struct timeval tv;
3609 gettimeofday(&tv, NULL);
3610 uint64_t starttimems = ((uint64_t)tv.tv_sec) * 1000 + tv.tv_usec / 1000;
3611 while (cdb2_next_record_int(hndl, 0) == CDB2_OK) {
3612 nrec++;
3613 gettimeofday(&tv, NULL);
3614 uint64_t curr = ((uint64_t)tv.tv_sec) * 1000 + tv.tv_usec / 1000;
3615 /* auto consume for up to CDB2_AUTO_CONSUME_TIMEOUT_MS */
3616 if (curr - starttimems >= hndl->auto_consume_timeout_ms)
3617 break;
3618 }
3619 if (hndl->debug_trace) {
3620 gettimeofday(&tv, NULL);
3621 uint64_t curr = ((uint64_t)tv.tv_sec) * 1000 + tv.tv_usec / 1000;
3622 fprintf(stderr, "%s: auto consume %d records took %" PRIu64 " ms\n",
3623 __func__, nrec, curr - starttimems);
3624 }
3625 }
3626
3627 if (hndl->sb)
3628 newsql_disconnect(hndl, hndl->sb, __LINE__);
3629
3630 if (hndl->firstresponse) {
3631 cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
3632 free((void *)hndl->first_buf);
3633 hndl->first_buf = NULL;
3634 }
3635
3636 if (hndl->lastresponse) {
3637 if (hndl->protobuf_used_sysmalloc)
3638 cdb2__sqlresponse__free_unpacked(hndl->lastresponse,
3639 &hndl->allocator);
3640 hndl->protobuf_offset = 0;
3641 free((void *)hndl->last_buf);

Callers 15

db_generatorFunction · 0.85
process_escapeFunction · 0.85
run_statementFunction · 0.85
send_cancel_cnonceFunction · 0.85
mainFunction · 0.85
process_eventsFunction · 0.85
mainFunction · 0.85
cdb2_run_statement_typedFunction · 0.85
insert_records_thdFunction · 0.85
update_records_thdFunction · 0.85
record_countFunction · 0.85

Calls 10

ackFunction · 0.85
cdb2_next_record_intFunction · 0.85
newsql_disconnectFunction · 0.85
freeFunction · 0.85
cdb2_clearbindingsFunction · 0.85
cdb2_free_context_msgsFunction · 0.85
cdb2_next_callbackFunction · 0.85
cdb2_invoke_callbackFunction · 0.85
free_eventsFunction · 0.85
free_query_listFunction · 0.85

Tested by 8

masterFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
test_closeFunction · 0.68
process_escapeFunction · 0.68
run_statementFunction · 0.68
mainFunction · 0.68
test_register_timeoutFunction · 0.68