streams: handle short writes only in generic stream Now that the function `git_stream__write_full` exists and callers of `git_stream_write` have been adjusted, we can lift logic for short writes out of the stream implementations. Instead, this is now handled either by `git_stream__write_full` or by callers of `git_stream_write` directly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/src/streams/mbedtls.c b/src/streams/mbedtls.c
index 7ca3aa6..3a440e3 100644
--- a/src/streams/mbedtls.c
+++ b/src/streams/mbedtls.c
@@ -303,20 +303,15 @@ static int mbedtls_set_proxy(git_stream *stream, const git_proxy_options *proxy_
return git_stream_set_proxy(st->io, proxy_options);
}
-static ssize_t mbedtls_stream_write(git_stream *stream, const char *data, size_t data_len, int flags)
+static ssize_t mbedtls_stream_write(git_stream *stream, const char *data, size_t len, int flags)
{
- ssize_t written = 0, len = min(data_len, SSIZE_MAX);
mbedtls_stream *st = (mbedtls_stream *) stream;
+ int written;
GIT_UNUSED(flags);
- do {
- int error = mbedtls_ssl_write(st->ssl, (const unsigned char *)data + written, len - written);
- if (error <= 0) {
- return ssl_set_error(st->ssl, error);
- }
- written += error;
- } while (written < len);
+ if ((written = mbedtls_ssl_write(st->ssl, (const unsigned char *)data, len)) <= 0)
+ return ssl_set_error(st->ssl, written);
return written;
}
diff --git a/src/streams/socket.c b/src/streams/socket.c
index 7134db4..066580f 100644
--- a/src/streams/socket.c
+++ b/src/streams/socket.c
@@ -130,23 +130,19 @@ static int socket_connect(git_stream *stream)
return 0;
}
-static ssize_t socket_write(git_stream *stream, const char *data, size_t data_len, int flags)
+static ssize_t socket_write(git_stream *stream, const char *data, size_t len, int flags)
{
- ssize_t ret, off = 0, len = min(data_len, SSIZE_MAX);
git_socket_stream *st = (git_socket_stream *) stream;
+ ssize_t written;
- while (off < len) {
- errno = 0;
- ret = p_send(st->s, data + off, len - off, flags);
- if (ret < 0) {
- net_set_error("Error sending data");
- return -1;
- }
+ errno = 0;
- off += ret;
+ if ((written = p_send(st->s, data, len, flags)) < 0) {
+ net_set_error("Error sending data");
+ return -1;
}
- return off;
+ return written;
}
static ssize_t socket_read(git_stream *stream, void *data, size_t len)