418
}
419
420
// TCP window is open and we have data to transmit.
421
-void attempt_to_send(struct sender_state *s, char *chunk, size_t outstanding) {
421
+void attempt_to_send(struct sender_state *s) {
422
+
423
rrdpush_send_labels(s->host);
424
424
- struct circular_buffer *cb = s->host->sender->buffer;
425
- debug(D_STREAM, "STREAM: Sending data. Buffer r=%zu w=%zu s=%zu, next chunk=%zu", cb->read, cb->write, cb->size, outstanding);
425
+ struct circular_buffer *cb = s->buffer;
426
427
netdata_thread_disable_cancelability();
428
- netdata_mutex_lock(&s->host->sender->mutex);
429
-
428
+ netdata_mutex_lock(&s->mutex);
429
+ char *chunk;
430
+ size_t outstanding = cbuffer_next_unsafe(s->buffer, &chunk);
431
+ debug(D_STREAM, "STREAM: Sending data. Buffer r=%zu w=%zu s=%zu, next chunk=%zu", cb->read, cb->write, cb->size, outstanding);
432
ssize_t ret;
433
#ifdef ENABLE_HTTPS
434
SSL *conn = s->host->ssl.conn ;
441
ret = send(s->host->rrdpush_sender_socket, chunk, outstanding, MSG_DONTWAIT);
442
#endif
443
if (likely(ret > 0)) {
442
- cbuffer_remove_unsafe(s->host->sender->buffer, ret);
444
+ cbuffer_remove_unsafe(s->buffer, ret);
445
s->sent_bytes_on_this_connection += ret;
446
s->sent_bytes += ret;
447
debug(D_STREAM, "STREAM %s [send to %s]: Sent %zd bytes", s->host->hostname, s->connected_to, ret);
459
debug(D_STREAM, "STREAM: send() returned 0 -> no error but no transmission");
460
}
461
460
- netdata_mutex_unlock(&s->host->sender->mutex);
462
+ netdata_mutex_unlock(&s->mutex);
463
netdata_thread_enable_cancelability();
464
}
465
637
fds[Socket].revents = 0;
638
fds[Socket].fd = s->host->rrdpush_sender_socket;
639
640
+ netdata_mutex_lock(&s->mutex);
641
char *chunk;
642
size_t outstanding = cbuffer_next_unsafe(s->host->sender->buffer, &chunk);
643
+ chunk = NULL; // Do not cache pointer outside of region - could be invalidated
644
+ netdata_mutex_unlock(&s->mutex);
645
if(outstanding) {
646
s->send_attempts++;
647
fds[Socket].events = POLLIN | POLLOUT;
684
685
// If we have data and have seen the TCP window open then try to close it by a transmission.
686
if (outstanding && fds[Socket].revents & POLLOUT)
682
- attempt_to_send(s, chunk, outstanding);
687
+ attempt_to_send(s);
688
689
// TODO-GAPS - why do we only check this on the socket, not the pipe?
690
if (outstanding) {