| line |
true |
false |
branch |
|
17
|
0 |
0 |
while ((e = ERR_get_error()) != 0) last = e; |
|
18
|
0 |
0 |
if (!last) return; |
|
21
|
0 |
0 |
CLEAR_STR(self->last_tls_error); |
|
35
|
0 |
0 |
self->protocol == PROTO_NATIVE ? "native" : "http"); |
|
43
|
0 |
0 |
if (ret != 0) { |
|
51
|
0 |
0 |
if (fd < 0) { |
|
60
|
0 |
0 |
if (fl < 0 || fcntl(fd, F_SETFL, fl | O_NONBLOCK) < 0) { |
|
|
0 |
0 |
if (fl < 0 || fcntl(fd, F_SETFL, fl | O_NONBLOCK) < 0) { |
|
80
|
0 |
0 |
if (ret == 0) { |
|
84
|
0 |
0 |
if (self->protocol != PROTO_NATIVE && !self->tls_enabled) |
|
|
0 |
0 |
if (self->protocol != PROTO_NATIVE && !self->tls_enabled) |
|
94
|
0 |
0 |
if (errno != EINPROGRESS) { |
|
112
|
0 |
0 |
if (self->connect_timeout > 0) { |
|
124
|
0 |
0 |
CLEAR_STR(self->last_tls_error); /* successful connect supersedes stale TLS error */ |
|
127
|
0 |
0 |
if (!ngx_queue_empty(&self->send_queue)) |
|
142
|
0 |
0 |
if (self->tls_enabled) { |
|
145
|
0 |
0 |
if (!self->ssl_ctx) { |
|
150
|
0 |
0 |
if (self->tls_skip_verify) |
|
154
|
0 |
0 |
if (self->tls_ca_file) { |
|
155
|
0 |
0 |
if (SSL_CTX_load_verify_locations(self->ssl_ctx, self->tls_ca_file, NULL) != 1) { |
|
164
|
0 |
0 |
if (self->tls_cert_file && self->tls_key_file) { |
|
|
0 |
0 |
if (self->tls_cert_file && self->tls_key_file) { |
|
165
|
0 |
0 |
if (SSL_CTX_use_certificate_chain_file(self->ssl_ctx, self->tls_cert_file) != 1) { |
|
170
|
0 |
0 |
if (SSL_CTX_use_PrivateKey_file(self->ssl_ctx, self->tls_key_file, SSL_FILETYPE_PEM) != 1) { |
|
175
|
0 |
0 |
if (SSL_CTX_check_private_key(self->ssl_ctx) != 1) { |
|
180
|
0 |
0 |
} else if (self->tls_cert_file || self->tls_key_file) { |
|
|
0 |
0 |
} else if (self->tls_cert_file || self->tls_key_file) { |
|
185
|
0 |
0 |
if (!self->ssl) { |
|
195
|
0 |
0 |
if (!host_is_ip) |
|
199
|
0 |
0 |
if (!self->tls_skip_verify) { |
|
202
|
0 |
0 |
if (host_is_ip) |
|
209
|
0 |
0 |
if (ret == 1) { |
|
214
|
0 |
0 |
if (err == SSL_ERROR_WANT_READ) { |
|
216
|
0 |
0 |
} else if (err == SSL_ERROR_WANT_WRITE) { |
|
230
|
0 |
0 |
if (self->protocol == PROTO_NATIVE) { |
|
249
|
0 |
0 |
while (self->send_pos < self->send_len) { |
|
252
|
0 |
0 |
if (n < 0) { |
|
253
|
0 |
0 |
if (errno == EAGAIN || errno == EWOULDBLOCK) { |
|
|
0 |
0 |
if (errno == EAGAIN || errno == EWOULDBLOCK) { |
|
259
|
0 |
0 |
if (n == 0) |
|
274
|
0 |
0 |
if (!ngx_queue_empty(&self->send_queue)) |
|
286
|
0 |
0 |
if (n < 0) { |
|
287
|
0 |
0 |
if (errno == EAGAIN || errno == EWOULDBLOCK) return; |
|
|
0 |
0 |
if (errno == EAGAIN || errno == EWOULDBLOCK) return; |
|
292
|
0 |
0 |
if (n == 0) { |
|
295
|
0 |
0 |
int had_inflight = (self->send_count > 0 || !self->connected); |
|
|
0 |
0 |
int had_inflight = (self->send_count > 0 || !self->connected); |
|
298
|
0 |
0 |
if (had_inflight) { |
|
301
|
0 |
0 |
if (check_destroyed(self)) return; |
|
302
|
0 |
0 |
if (self->connect_gen != gen) return; |
|
305
|
0 |
0 |
if (!self->auto_reconnect || !has_queued) { |
|
|
0 |
0 |
if (!self->auto_reconnect || !has_queued) { |
|
306
|
0 |
0 |
if (cancel_pending(self, "connection closed")) return; |
|
312
|
0 |
0 |
if (check_destroyed(self)) return; |
|
314
|
0 |
0 |
if (self->connect_gen != gen) return; |
|
316
|
0 |
0 |
if (cleanup_connection(self)) return; /* on_disconnect freed self */ |
|
319
|
0 |
0 |
if (self->auto_reconnect && self->host) { |
|
|
0 |
0 |
if (self->auto_reconnect && self->host) { |
|
332
|
0 |
0 |
if (self->max_recv_buffer > 0 && self->recv_len > self->max_recv_buffer) { |
|
|
0 |
0 |
if (self->max_recv_buffer > 0 && self->recv_len > self->max_recv_buffer) { |
|
342
|
0 |
0 |
if (self->protocol == PROTO_HTTP) { |
|
353
|
0 |
0 |
if (self == NULL || self->magic != EV_CH_MAGIC) return; |
|
|
0 |
0 |
if (self == NULL || self->magic != EV_CH_MAGIC) return; |
|
355
|
0 |
0 |
if (self->connecting) { |
|
365
|
0 |
0 |
if (getsockopt(self->fd, SOL_SOCKET, SO_ERROR, &err, &errlen) < 0) |
|
367
|
0 |
0 |
if (err != 0) { |
|
379
|
0 |
0 |
if (self->ssl && !self->connected && self->native_state != NATIVE_WAIT_HELLO |
|
|
0 |
0 |
if (self->ssl && !self->connected && self->native_state != NATIVE_WAIT_HELLO |
|
|
0 |
0 |
if (self->ssl && !self->connected && self->native_state != NATIVE_WAIT_HELLO |
|
380
|
0 |
0 |
&& self->native_state != NATIVE_WAIT_RESULT |
|
381
|
0 |
0 |
&& self->native_state != NATIVE_WAIT_INSERT_META) { |
|
384
|
0 |
0 |
if (ret == 1) { |
|
388
|
0 |
0 |
if (self->protocol == PROTO_NATIVE) { |
|
405
|
0 |
0 |
if (err == SSL_ERROR_WANT_READ) { |
|
407
|
0 |
0 |
} else if (err == SSL_ERROR_WANT_WRITE) { |
|
418
|
0 |
0 |
if (revents & EV_WRITE) { |
|
419
|
0 |
0 |
if (try_write(self)) return; |
|
420
|
0 |
0 |
if (self->fd < 0) return; |
|
421
|
0 |
0 |
if (self->pending_addendum_finish && self->send_pos >= self->send_len) { |
|
|
0 |
0 |
if (self->pending_addendum_finish && self->send_pos >= self->send_len) { |
|
424
|
0 |
0 |
if (finish_connect(self)) return; |
|
428
|
0 |
0 |
if (revents & EV_READ) { |
|
438
|
0 |
0 |
if (self == NULL || self->magic != EV_CH_MAGIC) return; |
|
|
0 |
0 |
if (self == NULL || self->magic != EV_CH_MAGIC) return; |
|
444
|
0 |
0 |
if (!self->connected) { |
|
449
|
0 |
0 |
CLEAR_SV(self->native_rows); |
|
450
|
0 |
0 |
CLEAR_SV(self->native_col_names); |
|
451
|
0 |
0 |
CLEAR_SV(self->native_col_types); |
|
452
|
0 |
0 |
CLEAR_SV(self->native_totals); |
|
453
|
0 |
0 |
CLEAR_SV(self->native_extremes); |
|
455
|
0 |
0 |
CLEAR_INSERT(self); |
|
|
0 |
0 |
CLEAR_INSERT(self); |
|
456
|
0 |
0 |
CLEAR_STR(self->insert_err); |
|
458
|
0 |
0 |
if (self->send_count > 0) self->send_count--; |
|
462
|
0 |
0 |
if (teardown_after_deliver(self, "query timeout", "query timeout")) return; |
|
463
|
0 |
0 |
if (self->connect_gen != gen) return; |
|
464
|
0 |
0 |
if (self->auto_reconnect && self->host) |
|
|
0 |
0 |
if (self->auto_reconnect && self->host) |
|
476
|
0 |
0 |
if (self->magic != EV_CH_MAGIC) return; |
|
477
|
0 |
0 |
if (!self->connected || self->send_count > 0) return; |
|
|
0 |
0 |
if (!self->connected || self->send_count > 0) return; |
|
481
|
0 |
0 |
if (self->protocol == PROTO_NATIVE) { |
|
505
|
0 |
0 |
if (self->keepalive > 0 && !self->ka_timing && self->connected) { |
|
|
0 |
0 |
if (self->keepalive > 0 && !self->ka_timing && self->connected) { |
|
|
0 |
0 |
if (self->keepalive > 0 && !self->ka_timing && self->connected) { |
|
513
|
0 |
0 |
if (self->ka_timing) { |
|
526
|
0 |
0 |
if (self->magic != EV_CH_MAGIC || self->connected || self->connecting) return; |
|
|
0 |
0 |
if (self->magic != EV_CH_MAGIC || self->connected || self->connecting) return; |
|
|
0 |
0 |
if (self->magic != EV_CH_MAGIC || self->connected || self->connecting) return; |
|
531
|
0 |
0 |
if (!self->auto_reconnect || !self->host || self->magic != EV_CH_MAGIC) return; |
|
|
0 |
0 |
if (!self->auto_reconnect || !self->host || self->magic != EV_CH_MAGIC) return; |
|
|
0 |
0 |
if (!self->auto_reconnect || !self->host || self->magic != EV_CH_MAGIC) return; |
|
532
|
0 |
0 |
if (self->reconnect_max_attempts > 0 |
|
533
|
0 |
0 |
&& self->reconnect_attempts >= self->reconnect_max_attempts) { |
|
539
|
0 |
0 |
if (check_destroyed(self)) return; |
|
547
|
0 |
0 |
double delay = self->reconnect_delay > 0 ? self->reconnect_delay : 0.0; |
|
549
|
0 |
0 |
for (i = 0; i < self->reconnect_attempts && i < 20; i++) |
|
|
0 |
0 |
for (i = 0; i < self->reconnect_attempts && i < 20; i++) |
|
551
|
0 |
0 |
if (self->reconnect_max_delay > 0 && delay > self->reconnect_max_delay) |
|
|
0 |
0 |
if (self->reconnect_max_delay > 0 && delay > self->reconnect_max_delay) |
|
556
|
0 |
0 |
if (self->reconnect_jitter > 0 && delay > 0) { |
|
|
0 |
0 |
if (self->reconnect_jitter > 0 && delay > 0) { |
|
559
|
0 |
0 |
if (self->reconnect_max_delay > 0 && delay > self->reconnect_max_delay) |
|
|
0 |
0 |
if (self->reconnect_max_delay > 0 && delay > self->reconnect_max_delay) |
|
563
|
0 |
0 |
if (self->reconnect_timing) { |
|
574
|
0 |
0 |
if (self->lc_dicts) { |
|
576
|
0 |
0 |
for (c = 0; c < self->lc_num_cols; c++) { |
|
577
|
0 |
0 |
if (self->lc_dicts[c]) { |
|
579
|
0 |
0 |
for (j = 0; j < self->lc_dict_sizes[c]; j++) |
|
597
|
0 |
0 |
if (!self->connected) return 0; |
|
599
|
0 |
0 |
if (self->send_count > 0) { |
|
605
|
0 |
0 |
if (ngx_queue_empty(&self->send_queue) && self->pending_count == 0 |
|
|
0 |
0 |
if (ngx_queue_empty(&self->send_queue) && self->pending_count == 0 |
|
606
|
0 |
0 |
&& self->on_drain) { |
|
609
|
0 |
0 |
if (fire_zero_arg_cb(self, drain_cb, "drain")) { |
|
619
|
0 |
0 |
if (check_destroyed(self)) return 1; |
|
624
|
0 |
0 |
if (ngx_queue_empty(&self->send_queue) && self->pending_count == 0) |
|
|
0 |
0 |
if (ngx_queue_empty(&self->send_queue) && self->pending_count == 0) |
|
628
|
0 |
0 |
if (!ngx_queue_empty(&self->send_queue)) { |
|
638
|
0 |
0 |
if (self->magic != EV_CH_MAGIC || !self->connected |
|
|
0 |
0 |
if (self->magic != EV_CH_MAGIC || !self->connected |
|
639
|
0 |
0 |
|| ngx_queue_empty(&self->send_queue)) |
|
657
|
0 |
0 |
CLEAR_SV(send->on_data); |
|
660
|
0 |
0 |
CLEAR_STR(self->last_query_id); |
|
661
|
0 |
0 |
if (send->query_id) { self->last_query_id = send->query_id; send->query_id = NULL; } |
|
667
|
0 |
0 |
if (self->on_query_start && !IS_KEEPALIVE_CB(dispatched_cb)) { |
|
|
0 |
0 |
if (self->on_query_start && !IS_KEEPALIVE_CB(dispatched_cb)) { |
|
|
0 |
0 |
if (self->on_query_start && !IS_KEEPALIVE_CB(dispatched_cb)) { |
|
669
|
0 |
0 |
ENTER; SAVETMPS; PUSHMARK(SP); |
|
670
|
0 |
0 |
EXTEND(SP, 1); |
|
671
|
0 |
0 |
PUSHs(self->last_query_id |
|
679
|
0 |
0 |
WARN_AND_CLEAR_ERRSV("on_query_start"); |
|
|
0 |
0 |
WARN_AND_CLEAR_ERRSV("on_query_start"); |
|
|
0 |
0 |
WARN_AND_CLEAR_ERRSV("on_query_start"); |
|
|
0 |
0 |
WARN_AND_CLEAR_ERRSV("on_query_start"); |
|
680
|
0 |
0 |
FREETMPS; LEAVE; |
|
691
|
0 |
0 |
if (destroyed || self->connect_gen != gen_before |
|
|
0 |
0 |
if (destroyed || self->connect_gen != gen_before |
|
692
|
0 |
0 |
|| !self->connected) { |
|
694
|
0 |
0 |
CLEAR_INSERT(send); |
|
|
0 |
0 |
CLEAR_INSERT(send); |
|
705
|
0 |
0 |
CLEAR_SV(self->native_col_names); |
|
706
|
0 |
0 |
CLEAR_SV(self->native_col_types); |
|
707
|
0 |
0 |
CLEAR_SV(self->native_totals); |
|
708
|
0 |
0 |
CLEAR_SV(self->native_extremes); |
|
713
|
0 |
0 |
if (self->progress_period > 0) { |
|
719
|
0 |
0 |
if (send->insert_data) { |
|
724
|
0 |
0 |
if (send->insert_av) { |
|
735
|
0 |
0 |
double timeout = qt > 0 ? qt : self->query_timeout; |
|
736
|
0 |
0 |
if (timeout > 0 && !self->timing) { |
|
|
0 |
0 |
if (timeout > 0 && !self->timing) { |
|
742
|
0 |
0 |
if (self->protocol == PROTO_NATIVE) { |
|
743
|
0 |
0 |
if (self->insert_data || self->insert_av) |
|
|
0 |
0 |
if (self->insert_data || self->insert_av) |