Commit 7613086d by Patrick Steinhardt Committed by Edward Thomson

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.
parent 5265b31c
......@@ -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;
}
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment