Skip to content

Commit e863800

Browse files
committed
CDRIVER-770: Return how much we did write since its OK to return short writes
When we can't finish writing our entire buffered iovec, we must still return how much we have successfully written so far, in case any of the previous buffers finished. Then we can regroup and recalculate from where we left off and retry in case of an [WSA]EWOULDBLOCK or friends.
1 parent b95d5df commit e863800

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/mongoc/mongoc-stream-tls.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ _mongoc_stream_tls_writev (mongoc_stream_t *stream,
579579
BSON_ASSERT (tls);
580580
BSON_ASSERT (iov);
581581
BSON_ASSERT (iovcnt);
582+
ENTRY;
582583

583584
tls->timeout_msec = timeout_msec;
584585

@@ -624,18 +625,22 @@ _mongoc_stream_tls_writev (mongoc_stream_t *stream,
624625
* if we didn't buffer and have to send out of the iovec */
625626

626627
child_ret = _mongoc_stream_tls_write (tls, to_write, to_write_len);
628+
if (child_ret != to_write_len) {
629+
MONGOC_DEBUG("Got child_ret: %ld while to_write_len is: %ld",
630+
child_ret, to_write_len);
631+
}
627632

628633
if (child_ret < 0) {
629-
/* Buffer write failed, just return the error */
630-
return child_ret;
634+
TRACE("Returning what I had (%ld) as apposed to the error (%ld, errno:%d)", ret, child_ret, errno);
635+
RETURN (ret);
631636
}
632637

633638
ret += child_ret;
634639

635640
if (child_ret < to_write_len) {
636641
/* we timed out, so send back what we could send */
637642

638-
return ret;
643+
RETURN (ret);
639644
}
640645

641646
to_write = NULL;
@@ -646,10 +651,12 @@ _mongoc_stream_tls_writev (mongoc_stream_t *stream,
646651
if (buf_head != buf_tail) {
647652
/* If we have any bytes buffered, send */
648653

654+
TRACE("buffered writing %ld", buf_tail - buf_head);
649655
child_ret = _mongoc_stream_tls_write (tls, buf_head, buf_tail - buf_head);
656+
TRACE("Got %ld written", child_ret);
650657

651658
if (child_ret < 0) {
652-
return child_ret;
659+
RETURN (child_ret);
653660
}
654661

655662
ret += child_ret;
@@ -659,7 +666,7 @@ _mongoc_stream_tls_writev (mongoc_stream_t *stream,
659666
mongoc_counter_streams_egress_add (ret);
660667
}
661668

662-
return ret;
669+
RETURN (ret);
663670
}
664671

665672

0 commit comments

Comments
 (0)