sc_send_bin_buffer: Use write_nonblock() rather than write_all().
authorAndre Noll <maan@systemlinux.org>
Sun, 11 Dec 2011 19:27:27 +0000 (20:27 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 20 Jan 2012 21:57:07 +0000 (22:57 +0100)
The write_nonblock() variant is safer here as it allows to let the
callers deal with short writes.

Despite the name, write_nonblock() can be used for both blocking and
non-blocking fds. It will be renamed in a subsequent patch.

crypt.c
gcrypt.c

diff --git a/crypt.c b/crypt.c
index 7161e62..85ec091 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -298,7 +298,7 @@ int sc_send_bin_buffer(struct stream_cipher_context *scc, char *buf,
                memcpy(remainder, buf + l1, len - l1);
                RC4(&scc->send->key, len - l1, remainder, tmp + l1);
        }
-       ret = write_all(scc->fd, (char *)tmp, len);
+       ret = write_nonblock(scc->fd, (char *)tmp, len);
        free(tmp);
        return ret;
 }
index 467e739..1ce4587 100644 (file)
--- a/gcrypt.c
+++ b/gcrypt.c
@@ -951,7 +951,7 @@ int sc_send_bin_buffer(struct stream_cipher_context *scc, char *buf,
        gret = gcry_cipher_encrypt(scc->send->handle, tmp, size,
                (unsigned char *)buf, size);
        assert(gret == 0);
-       ret = write_all(scc->fd, (char *)tmp, size);
+       ret = write_nonblock(scc->fd, (char *)tmp, size);
        free(tmp);
        return ret;
 }