diff options
author | djm <djm> | 2005-05-26 02:23:44 +0000 |
---|---|---|
committer | djm <djm> | 2005-05-26 02:23:44 +0000 |
commit | c720f30a5a83f139c56b7742197b67b1f7f76712 (patch) | |
tree | aca3c31741bd62bd32f4214ed7537d2c95a64cd0 /sftp-client.c | |
parent | c70cf4f100b16906f050f7334fbcfaed42e97b8d (diff) | |
download | openssh-c720f30a5a83f139c56b7742197b67b1f7f76712.tar.gz |
- avsm@cvs.openbsd.org 2005/05/24 17:32:44
[atomicio.c atomicio.h authfd.c monitor_wrap.c msg.c scp.c sftp-client.c]
[ssh-keyscan.c sshconnect.c]
Switch atomicio to use a simpler interface; it now returns a size_t
(containing number of bytes read/written), and indicates error by
returning 0. EOF is signalled by errno==EPIPE.
Typical use now becomes:
if (atomicio(read, ..., len) != len)
err(1,"read");
ok deraadt@, cloder@, djm@
Diffstat (limited to 'sftp-client.c')
-rw-r--r-- | sftp-client.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/sftp-client.c b/sftp-client.c index 92df4275..47297898 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -20,7 +20,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.53 2005/03/10 22:01:05 deraadt Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.54 2005/05/24 17:32:44 avsm Exp $"); #include "openbsd-compat/sys-queue.h" @@ -64,10 +64,10 @@ send_msg(int fd, Buffer *m) /* Send length first */ PUT_32BIT(mlen, buffer_len(m)); - if (atomicio(vwrite, fd, mlen, sizeof(mlen)) <= 0) + if (atomicio(vwrite, fd, mlen, sizeof(mlen)) != sizeof(mlen)) fatal("Couldn't send packet: %s", strerror(errno)); - if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) <= 0) + if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) != buffer_len(m)) fatal("Couldn't send packet: %s", strerror(errno)); buffer_clear(m); @@ -76,26 +76,27 @@ send_msg(int fd, Buffer *m) static void get_msg(int fd, Buffer *m) { - ssize_t len; u_int msg_len; buffer_append_space(m, 4); - len = atomicio(read, fd, buffer_ptr(m), 4); - if (len == 0) - fatal("Connection closed"); - else if (len == -1) - fatal("Couldn't read packet: %s", strerror(errno)); + if (atomicio(read, fd, buffer_ptr(m), 4) != 4) { + if (errno == EPIPE) + fatal("Connection closed"); + else + fatal("Couldn't read packet: %s", strerror(errno)); + } msg_len = buffer_get_int(m); if (msg_len > MAX_MSG_LENGTH) fatal("Received message too long %u", msg_len); buffer_append_space(m, msg_len); - len = atomicio(read, fd, buffer_ptr(m), msg_len); - if (len == 0) - fatal("Connection closed"); - else if (len == -1) - fatal("Read packet: %s", strerror(errno)); + if (atomicio(read, fd, buffer_ptr(m), msg_len) != msg_len) { + if (errno == EPIPE) + fatal("Connection closed"); + else + fatal("Read packet: %s", strerror(errno)); + } } static void |