diff options
author | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2005-05-24 17:32:45 +0000 |
---|---|---|
committer | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2005-05-24 17:32:45 +0000 |
commit | 8d70480c583a93f537beb6ba10177b405033e6d2 (patch) | |
tree | af6655f91ee72626175bd38e315fcdef4cb74ff3 /usr.bin/ssh/msg.c | |
parent | e4259f82cd9c63cff5f23fc9d63da9a4a294e389 (diff) |
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 'usr.bin/ssh/msg.c')
-rw-r--r-- | usr.bin/ssh/msg.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/usr.bin/ssh/msg.c b/usr.bin/ssh/msg.c index 30bc3f10763..3e4c2882c5f 100644 --- a/usr.bin/ssh/msg.c +++ b/usr.bin/ssh/msg.c @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" -RCSID("$OpenBSD: msg.c,v 1.7 2003/11/17 09:45:39 djm Exp $"); +RCSID("$OpenBSD: msg.c,v 1.8 2005/05/24 17:32:43 avsm Exp $"); #include "buffer.h" #include "getput.h" @@ -55,15 +55,13 @@ int ssh_msg_recv(int fd, Buffer *m) { u_char buf[4]; - ssize_t res; u_int msg_len; debug3("ssh_msg_recv entering"); - res = atomicio(read, fd, buf, sizeof(buf)); - if (res != sizeof(buf)) { - if (res != 0) - error("ssh_msg_recv: read: header %ld", (long)res); + if (atomicio(read, fd, buf, sizeof(buf)) != sizeof(buf)) { + if (errno != EPIPE) + error("ssh_msg_recv: read: header"); return (-1); } msg_len = GET_32BIT(buf); @@ -73,9 +71,8 @@ ssh_msg_recv(int fd, Buffer *m) } buffer_clear(m); buffer_append_space(m, msg_len); - res = atomicio(read, fd, buffer_ptr(m), msg_len); - if (res != msg_len) { - error("ssh_msg_recv: read: %ld != msg_len", (long)res); + if (atomicio(read, fd, buffer_ptr(m), msg_len) != msg_len) { + error("ssh_msg_recv: read: %s", strerror(errno)); return (-1); } return (0); |