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_ ...@@ -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); 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; mbedtls_stream *st = (mbedtls_stream *) stream;
int written;
GIT_UNUSED(flags); GIT_UNUSED(flags);
do { if ((written = mbedtls_ssl_write(st->ssl, (const unsigned char *)data, len)) <= 0)
int error = mbedtls_ssl_write(st->ssl, (const unsigned char *)data + written, len - written); return ssl_set_error(st->ssl, written);
if (error <= 0) {
return ssl_set_error(st->ssl, error);
}
written += error;
} while (written < len);
return written; return written;
} }
......
...@@ -130,23 +130,19 @@ static int socket_connect(git_stream *stream) ...@@ -130,23 +130,19 @@ static int socket_connect(git_stream *stream)
return 0; 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; git_socket_stream *st = (git_socket_stream *) stream;
ssize_t written;
while (off < len) {
errno = 0; errno = 0;
ret = p_send(st->s, data + off, len - off, flags);
if (ret < 0) { if ((written = p_send(st->s, data, len, flags)) < 0) {
net_set_error("Error sending data"); net_set_error("Error sending data");
return -1; return -1;
} }
off += ret; return written;
}
return off;
} }
static ssize_t socket_read(git_stream *stream, void *data, size_t len) 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