aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2022-01-27 19:06:22 +0000
committerEd Maste <emaste@FreeBSD.org>2022-01-27 19:06:37 +0000
commit286e87a9a5df818251c6932d8980d10b9aecb523 (patch)
tree0616837ba876b62386fad9bc21eb6a09fb0b8270
parent16a84834c2798d54c29d4794ef87472c9afd943e (diff)
downloadsrc-vendor/dma.tar.gz
src-vendor/dma.zip
dma: import 2022-01-27 git snapshot edb7c61b6463vendor/dma/2022-01-27vendor/dma
-rw-r--r--net.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/net.c b/net.c
index e8e2634a9386..0079875a22e0 100644
--- a/net.c
+++ b/net.c
@@ -95,25 +95,29 @@ send_remote_command(int fd, const char* fmt, ...)
strcat(cmd, "\r\n");
len = strlen(cmd);
- if (((config.features & SECURETRANSFER) != 0) &&
- ((config.features & NOSSL) == 0)) {
- while ((s = SSL_write(config.ssl, (const char*)cmd, len)) <= 0) {
- s = SSL_get_error(config.ssl, s);
- if (s != SSL_ERROR_WANT_READ &&
- s != SSL_ERROR_WANT_WRITE) {
- strlcpy(neterr, ssl_errstr(), sizeof(neterr));
- return (-1);
+ pos = 0;
+ while (pos < len) {
+ if (((config.features & SECURETRANSFER) != 0) &&
+ ((config.features & NOSSL) == 0)) {
+ if ((n = SSL_write(config.ssl, (const char*)(cmd + pos), len - pos)) <= 0) {
+ s = SSL_get_error(config.ssl, n);
+ if (s == SSL_ERROR_ZERO_RETURN ||
+ s == SSL_ERROR_SYSCALL ||
+ s == SSL_ERROR_SSL) {
+ strlcpy(neterr, ssl_errstr(), sizeof(neterr));
+ return (-1);
+ }
+ n = 0;
}
- }
- }
- else {
- pos = 0;
- while (pos < len) {
+ } else {
n = write(fd, cmd + pos, len - pos);
- if (n < 0)
- return (-1);
- pos += n;
+ if (n < 0) {
+ if ((errno != EAGAIN) && (errno != EINTR))
+ return (-1);
+ n = 0;
+ }
}
+ pos += n;
}
return (len);
@@ -150,9 +154,18 @@ read_remote(int fd, int extbufsize, char *extbuf)
pos = 0;
if (((config.features & SECURETRANSFER) != 0) &&
(config.features & NOSSL) == 0) {
- if ((rlen = SSL_read(config.ssl, buff + len, sizeof(buff) - len)) == -1) {
- strlcpy(neterr, ssl_errstr(), sizeof(neterr));
- goto error;
+ if ((rlen = SSL_read(config.ssl, buff + len, sizeof(buff) - len)) <= 0) {
+ switch (SSL_get_error(config.ssl, rlen)) {
+ case SSL_ERROR_ZERO_RETURN:
+ case SSL_ERROR_SYSCALL:
+ case SSL_ERROR_SSL:
+ strlcpy(neterr, ssl_errstr(), sizeof(neterr));
+ goto error;
+ default:
+ /* in case of recoverable error, retry after short sleep */
+ usleep(10000);
+ continue;
+ }
}
} else {
if ((rlen = read(fd, buff + len, sizeof(buff) - len)) == -1) {