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

Function cdb2_read_record

cdb2api/cdb2api.c:2766–2908  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2764}
2765
2766static int cdb2_read_record(cdb2_hndl_tp *hndl, uint8_t **buf, int *len, int *type)
2767{
2768 /* Got response */
2769 SBUF2 *sb = hndl->sb;
2770 struct newsqlheader hdr = {0};
2771 int b_read;
2772 int rc = 0; /* Make compilers happy. */
2773
2774 void *callbackrc;
2775 int overwrite_rc = 0;
2776 cdb2_event *e = NULL;
2777
2778 while ((e = cdb2_next_callback(hndl, CDB2_BEFORE_READ_RECORD, e)) != NULL) {
2779 callbackrc = cdb2_invoke_callback(hndl, e, 0);
2780 PROCESS_EVENT_CTRL_BEFORE(hndl, e, rc, callbackrc, overwrite_rc);
2781 }
2782
2783 if (overwrite_rc)
2784 goto after_callback;
2785
2786retry:
2787 b_read = sbuf2fread((char *)&hdr, 1, sizeof(hdr), sb);
2788 debugprint("READ HDR b_read=%d, sizeof(hdr)=(%zu):\n", b_read, sizeof(hdr));
2789
2790 if (b_read != sizeof(hdr)) {
2791 debugprint("bad read or numbytes, b_read=%d, sizeof(hdr)=(%zu):\n",
2792 b_read, sizeof(hdr));
2793 rc = -1;
2794 /* In TLS 1.3, client authentication happens after handshake (RFC 8446).
2795 An invalid client (e.g., a revoked cert) may see a successful
2796 handshake but encounter an error when reading data from the server.
2797 Catch the error here. */
2798 if ((hndl->sslerr = sbuf2lasterror(sb, NULL, 0)))
2799 sbuf2lasterror(sb, hndl->errstr, sizeof(hndl->errstr));
2800 goto after_callback;
2801 }
2802
2803 hdr.type = ntohl(hdr.type);
2804 hdr.compression = ntohl(hdr.compression);
2805 hdr.state = ntohl(hdr.state);
2806 hdr.length = ntohl(hdr.length);
2807 hndl->ack = (hdr.type == RESPONSE_HEADER__SQL_RESPONSE_PING);
2808
2809 /* Server requires SSL. Return the header type in `type'.
2810 We may reach here under DIRECT_CPU mode where we skip DBINFO lookup. */
2811 if (hdr.type == RESPONSE_HEADER__SQL_RESPONSE_SSL) {
2812 if (type == NULL) {
2813 rc = -1;
2814 goto after_callback;
2815 }
2816 *type = hdr.type;
2817 rc = 0;
2818 goto after_callback;
2819 }
2820
2821 if (hdr.length == 0) {
2822 debugprint("hdr length (0) from mach %s - going to retry\n",
2823 hndl->hosts[hndl->connected_host]);

Callers 6

cdb2_effects_requestFunction · 0.85
cdb2_next_record_intFunction · 0.85
retry_query_listFunction · 0.85
retry_queries_and_skipFunction · 0.85
comdb2db_get_dbhostsFunction · 0.85

Calls 6

cdb2_next_callbackFunction · 0.85
cdb2_invoke_callbackFunction · 0.85
reallocFunction · 0.85
exitFunction · 0.85
mallocFunction · 0.85
freeFunction · 0.85

Tested by

no test coverage detected