Skip to content

Commit 8796788

Browse files
committed
CDRIVER-756: Sprinkle, sprinkle, little trace,
How I wonder what you do! Up above the code so high, Like a diamond in the sky.
1 parent 7c985ce commit 8796788

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/mongoc/mongoc-socket.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ _mongoc_socket_try_sendv (mongoc_socket_t *sock, /* IN */
10321032
# endif
10331033
#endif
10341034

1035+
TRACE("Send %ld out of %ld bytes (errno=%d)", ret, iov->iov_len, errno);
10351036
/*
10361037
* Check to see if we have sent an iovec too large for sendmsg to
10371038
* complete. If so, we need to fallback to the slow path of multiple
@@ -1096,6 +1097,7 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
10961097

10971098
for (;;) {
10981099
sent = _mongoc_socket_try_sendv (sock, &iov [cur], iovcnt - cur);
1100+
TRACE("Sent %ld (of %ld) out of iovcnt=%ld", sent, iov[cur].iov_len, iovcnt);
10991101

11001102
/*
11011103
* If we failed with anything other than EAGAIN or EWOULDBLOCK,
@@ -1120,6 +1122,7 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
11201122
* Subtract the sent amount from what we still need to send.
11211123
*/
11221124
while ((cur < iovcnt) && (sent >= (ssize_t)iov [cur].iov_len)) {
1125+
TRACE("still got bytes left: sent -= iov_len: %ld -= %ld", sent, iov[cur+1].iov_len);
11231126
sent -= iov [cur++].iov_len;
11241127
}
11251128

@@ -1128,15 +1131,19 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
11281131
* sending data over the socket.
11291132
*/
11301133
if (cur == iovcnt) {
1134+
TRACE("%s", "Finished the iovecs");
11311135
break;
11321136
}
11331137

11341138
/*
11351139
* Increment the current iovec buffer to its proper offset and adjust
11361140
* the number of bytes to write.
11371141
*/
1142+
TRACE("Seeked io_base+%ld", sent);
1143+
TRACE("Subtracting iov_len -= sent; %ld -= %ld", iov[cur].iov_len, sent);
11381144
iov [cur].iov_base = ((char *)iov [cur].iov_base) + sent;
11391145
iov [cur].iov_len -= sent;
1146+
TRACE("iov_len remaining %ld", iov[cur].iov_len);
11401147

11411148
BSON_ASSERT (iovcnt - cur);
11421149
BSON_ASSERT (iov [cur].iov_len);

src/mongoc/mongoc-stream-tls.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,29 +252,38 @@ _mongoc_stream_tls_bio_write (BIO *b,
252252
mongoc_stream_tls_t *tls;
253253
mongoc_iovec_t iov;
254254
int ret;
255+
ENTRY;
255256

256257
BSON_ASSERT (b);
257258
BSON_ASSERT (buf);
258259

259260
tls = (mongoc_stream_tls_t *)b->ptr;
260261

261262
if (!tls) {
262-
return -1;
263+
RETURN (-1);
263264
}
264265

265266
iov.iov_base = (void *)buf;
266267
iov.iov_len = len;
267268

268269
errno = 0;
270+
TRACE("mongoc_stream_writev is expected to write: %d", len);
269271
ret = (int)mongoc_stream_writev (tls->base_stream, &iov, 1,
270272
tls->timeout_msec);
271273
BIO_clear_retry_flags (b);
272274

273-
if ((ret <= 0) && MONGOC_ERRNO_IS_AGAIN (errno)) {
275+
if (len > ret) {
276+
TRACE("Returned short write: %d of %d", ret, len);
277+
} else {
278+
TRACE("Completed the %d", ret);
279+
}
280+
if (ret <= 0 && MONGOC_ERRNO_IS_AGAIN (errno)) {
281+
TRACE("%s", "Requesting a retry");
274282
BIO_set_retry_write (b);
275283
}
276284

277-
return ret;
285+
286+
RETURN (ret);
278287
}
279288

280289

@@ -446,10 +455,13 @@ static int
446455
_mongoc_stream_tls_close (mongoc_stream_t *stream)
447456
{
448457
mongoc_stream_tls_t *tls = (mongoc_stream_tls_t *)stream;
458+
int ret = 0;
459+
ENTRY;
449460

450461
BSON_ASSERT (tls);
451462

452-
return mongoc_stream_close (tls->base_stream);
463+
ret = mongoc_stream_close (tls->base_stream);
464+
RETURN (ret);
453465
}
454466

455467

@@ -489,6 +501,7 @@ _mongoc_stream_tls_write (mongoc_stream_tls_t *tls,
489501

490502
int64_t now;
491503
int64_t expire = 0;
504+
ENTRY;
492505

493506
BSON_ASSERT (tls);
494507
BSON_ASSERT (buf);
@@ -499,7 +512,9 @@ _mongoc_stream_tls_write (mongoc_stream_tls_t *tls,
499512
}
500513

501514
ret = BIO_write (tls->bio, buf, buf_len);
515+
TRACE("BIO_write returned %ld", ret);
502516

517+
TRACE("I got ret: %ld and retry: %d", ret, BIO_should_retry (tls->bio));
503518
if (ret <= 0) {
504519
return ret;
505520
}
@@ -518,7 +533,13 @@ _mongoc_stream_tls_write (mongoc_stream_tls_t *tls,
518533
}
519534
}
520535

521-
return ret;
536+
if (ret <= 0 && BIO_should_retry (tls->bio)) {
537+
if (tls->timeout_msec > 0) {
538+
TRACE("I do have %dmsec left", tls->timeout_msec);
539+
}
540+
}
541+
542+
RETURN (ret);
522543
}
523544

524545
/*
@@ -697,6 +718,7 @@ _mongoc_stream_tls_readv (mongoc_stream_t *stream,
697718
size_t iov_pos = 0;
698719
int64_t now;
699720
int64_t expire = 0;
721+
ENTRY;
700722

701723
BSON_ASSERT (tls);
702724
BSON_ASSERT (iov);
@@ -738,7 +760,7 @@ _mongoc_stream_tls_readv (mongoc_stream_t *stream,
738760
#else
739761
errno = ETIMEDOUT;
740762
#endif
741-
return -1;
763+
RETURN (-1);
742764
}
743765

744766
tls->timeout_msec = 0;
@@ -751,7 +773,7 @@ _mongoc_stream_tls_readv (mongoc_stream_t *stream,
751773

752774
if ((size_t)ret >= min_bytes) {
753775
mongoc_counter_streams_ingress_add(ret);
754-
return ret;
776+
RETURN (ret);
755777
}
756778

757779
iov_pos += read_ret;
@@ -762,7 +784,7 @@ _mongoc_stream_tls_readv (mongoc_stream_t *stream,
762784
mongoc_counter_streams_ingress_add(ret);
763785
}
764786

765-
return ret;
787+
RETURN (ret);
766788
}
767789

768790

0 commit comments

Comments
 (0)