Skip to content

Commit 8e74520

Browse files
committed
fix a bug in socket_sendv
We didn't handle EAGAIN/EWOULDBLOCK/... appropriately in socket_sendv. Now we check for and handle it
1 parent ae06979 commit 8e74520

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/mongoc/mongoc-socket.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,31 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
975975
if (sent > 0) {
976976
ret += sent;
977977
mongoc_counter_streams_egress_add (sent);
978+
979+
/*
980+
* Subtract the sent amount from what we still need to send.
981+
*/
982+
while ((cur < iovcnt) && (sent >= (ssize_t)iov [cur].iov_len)) {
983+
sent -= iov [cur++].iov_len;
984+
}
985+
986+
/*
987+
* Check if that made us finish all of the iovecs. If so, we are done
988+
* sending data over the socket.
989+
*/
990+
if (cur == iovcnt) {
991+
break;
992+
}
993+
994+
/*
995+
* Increment the current iovec buffer to its proper offset and adjust
996+
* the number of bytes to write.
997+
*/
998+
iov [cur].iov_base = ((char *)iov [cur].iov_base) + sent;
999+
iov [cur].iov_len -= sent;
1000+
1001+
BSON_ASSERT (iovcnt - cur);
1002+
BSON_ASSERT (iov [cur].iov_len);
9781003
} else if (OPERATION_EXPIRED (expire_at)) {
9791004
#ifdef _WIN32
9801005
errno = WSAETIMEDOUT;
@@ -984,31 +1009,6 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
9841009
RETURN (ret ? ret : -1);
9851010
}
9861011

987-
/*
988-
* Subtract the sent amount from what we still need to send.
989-
*/
990-
while ((cur < iovcnt) && (sent >= (ssize_t)iov [cur].iov_len)) {
991-
sent -= iov [cur++].iov_len;
992-
}
993-
994-
/*
995-
* Check if that made us finish all of the iovecs. If so, we are done
996-
* sending data over the socket.
997-
*/
998-
if (cur == iovcnt) {
999-
break;
1000-
}
1001-
1002-
/*
1003-
* Increment the current iovec buffer to its proper offset and adjust
1004-
* the number of bytes to write.
1005-
*/
1006-
iov [cur].iov_base = ((char *)iov [cur].iov_base) + sent;
1007-
iov [cur].iov_len -= sent;
1008-
1009-
BSON_ASSERT (iovcnt - cur);
1010-
BSON_ASSERT (iov [cur].iov_len);
1011-
10121012
/*
10131013
* Block on poll() until our desired condition is met.
10141014
*/

0 commit comments

Comments
 (0)