summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2009-02-26 12:18:11 +0000
committerMatt Johnston <matt@ucc.asn.au>2009-02-26 12:18:11 +0000
commit7ff61b411f5a8e5e9073e2520908ce58d7fc3508 (patch)
tree238ffb11b54ad55ed3708d52fb0b7f59865788f5
parent60a4ac6e822bb1dc388a50045a98230b899c7092 (diff)
downloaddropbear-7ff61b411f5a8e5e9073e2520908ce58d7fc3508.tar.gz
- Try to write out as much as we can
-rw-r--r--common-session.c2
-rw-r--r--packet.c15
-rw-r--r--packet.h2
3 files changed, 14 insertions, 5 deletions
diff --git a/common-session.c b/common-session.c
index b48d210..d1545e6 100644
--- a/common-session.c
+++ b/common-session.c
@@ -189,7 +189,7 @@ void session_loop(void(*loophandler)()) {
/* process session socket's incoming/outgoing data */
if (ses.sock_out != -1) {
if (FD_ISSET(ses.sock_out, &writefd) && !isempty(&ses.writequeue)) {
- write_packet();
+ write_packets();
}
}
diff --git a/packet.c b/packet.c
index 870d5d8..4e2eedf 100644
--- a/packet.c
+++ b/packet.c
@@ -46,14 +46,16 @@ static buffer* buf_decompress(buffer* buf, unsigned int len);
static void buf_compress(buffer * dest, buffer * src, unsigned int len);
#endif
-/* non-blocking function writing out a current encrypted packet */
-void write_packet() {
+/* non-blocking function writing out a current encrypted packet. Returns
+ * DROPBEAR_SUCCESS if entire packet was written, DROPBEAR_FAILURE
+ * otherwise */
+static int write_packet() {
int len, written;
+ int ret = DROPBEAR_FAILURE;
buffer * writebuf = NULL;
TRACE(("enter write_packet"))
- dropbear_assert(!isempty(&ses.writequeue));
/* Get the next buffer in the queue of encrypted packets to write*/
writebuf = (buffer*)examine(&ses.writequeue);
@@ -84,12 +86,19 @@ void write_packet() {
dequeue(&ses.writequeue);
buf_free(writebuf);
writebuf = NULL;
+ ret = DROPBEAR_SUCCESS;
} else {
/* More packet left to write, leave it in the queue for later */
buf_incrpos(writebuf, written);
}
TRACE(("leave write_packet"))
+ return ret;
+}
+
+void write_packets() {
+ /* keep writing packets while we can. */
+ while (!isempty(&ses.writequeue) && write_packet() == DROPBEAR_SUCCESS) {}
}
/* Non-blocking function reading available portion of a packet into the
diff --git a/packet.h b/packet.h
index 8fadeb3..db203d3 100644
--- a/packet.h
+++ b/packet.h
@@ -28,7 +28,7 @@
#include "includes.h"
-void write_packet();
+void write_packets();
void read_packet();
void decrypt_packet();
void encrypt_packet();