Skip to content

Commit 7613086

Browse files
pks-tethomson
authored andcommitted
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 parent 5265b31 commit 7613086

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/streams/mbedtls.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,20 +303,15 @@ static int mbedtls_set_proxy(git_stream *stream, const git_proxy_options *proxy_
303303
return git_stream_set_proxy(st->io, proxy_options);
304304
}
305305

306-
static ssize_t mbedtls_stream_write(git_stream *stream, const char *data, size_t data_len, int flags)
306+
static ssize_t mbedtls_stream_write(git_stream *stream, const char *data, size_t len, int flags)
307307
{
308-
ssize_t written = 0, len = min(data_len, SSIZE_MAX);
309308
mbedtls_stream *st = (mbedtls_stream *) stream;
309+
int written;
310310

311311
GIT_UNUSED(flags);
312312

313-
do {
314-
int error = mbedtls_ssl_write(st->ssl, (const unsigned char *)data + written, len - written);
315-
if (error <= 0) {
316-
return ssl_set_error(st->ssl, error);
317-
}
318-
written += error;
319-
} while (written < len);
313+
if ((written = mbedtls_ssl_write(st->ssl, (const unsigned char *)data, len)) <= 0)
314+
return ssl_set_error(st->ssl, written);
320315

321316
return written;
322317
}

src/streams/socket.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,19 @@ static int socket_connect(git_stream *stream)
130130
return 0;
131131
}
132132

133-
static ssize_t socket_write(git_stream *stream, const char *data, size_t data_len, int flags)
133+
static ssize_t socket_write(git_stream *stream, const char *data, size_t len, int flags)
134134
{
135-
ssize_t ret, off = 0, len = min(data_len, SSIZE_MAX);
136135
git_socket_stream *st = (git_socket_stream *) stream;
136+
ssize_t written;
137137

138-
while (off < len) {
139-
errno = 0;
140-
ret = p_send(st->s, data + off, len - off, flags);
141-
if (ret < 0) {
142-
net_set_error("Error sending data");
143-
return -1;
144-
}
138+
errno = 0;
145139

146-
off += ret;
140+
if ((written = p_send(st->s, data, len, flags)) < 0) {
141+
net_set_error("Error sending data");
142+
return -1;
147143
}
148144

149-
return off;
145+
return written;
150146
}
151147

152148
static ssize_t socket_read(git_stream *stream, void *data, size_t len)

0 commit comments

Comments
 (0)