summaryrefslogtreecommitdiff
path: root/sftp-client.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2006-04-23 12:06:35 +1000
committerDamien Miller <djm@mindrot.org>2006-04-23 12:06:35 +1000
commit58ca98bfe12b65f4d445dc05b422f672c51caa4b (patch)
treece42acb4be05592c9aef3c0a1d8c396a28095f46 /sftp-client.c
parent6aa139c41ff22f9c91a934a73013265ea0a64afc (diff)
- djm@cvs.openbsd.org 2006/04/16 00:54:10
[sftp-client.c] avoid making a tiny 4-byte write to send the packet length of sftp commands, which would result in a separate tiny packet on the wire by using atomiciov(writev, ...) to write the length and the command in one pass; ok deraadt@
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/sftp-client.c b/sftp-client.c
index c71c66f33..8778439b9 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.c,v 1.64 2006/03/30 09:58:16 djm Exp $ */ 1/* $OpenBSD: sftp-client.c,v 1.65 2006/04/16 00:54:10 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -61,16 +61,19 @@ static void
61send_msg(int fd, Buffer *m) 61send_msg(int fd, Buffer *m)
62{ 62{
63 u_char mlen[4]; 63 u_char mlen[4];
64 struct iovec iov[2];
64 65
65 if (buffer_len(m) > SFTP_MAX_MSG_LENGTH) 66 if (buffer_len(m) > SFTP_MAX_MSG_LENGTH)
66 fatal("Outbound message too long %u", buffer_len(m)); 67 fatal("Outbound message too long %u", buffer_len(m));
67 68
68 /* Send length first */ 69 /* Send length first */
69 put_u32(mlen, buffer_len(m)); 70 put_u32(mlen, buffer_len(m));
70 if (atomicio(vwrite, fd, mlen, sizeof(mlen)) != sizeof(mlen)) 71 iov[0].iov_base = mlen;
71 fatal("Couldn't send packet: %s", strerror(errno)); 72 iov[0].iov_len = sizeof(mlen);
72 73 iov[1].iov_base = buffer_ptr(m);
73 if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) != buffer_len(m)) 74 iov[1].iov_len = buffer_len(m);
75
76 if (atomiciov(writev, fd, iov, 2) != buffer_len(m) + sizeof(mlen))
74 fatal("Couldn't send packet: %s", strerror(errno)); 77 fatal("Couldn't send packet: %s", strerror(errno));
75 78
76 buffer_clear(m); 79 buffer_clear(m);