- Try to write out as much as we can

--HG--
extra : convert_revision : a101cbd046507cf723e6362a49196dbd4b924042
This commit is contained in:
Matt Johnston 2009-02-26 12:18:11 +00:00
parent 3dbc707820
commit a60cb7dbaa
3 changed files with 14 additions and 5 deletions

View File

@ -189,7 +189,7 @@ void session_loop(void(*loophandler)()) {
/* process session socket's incoming/outgoing data */ /* process session socket's incoming/outgoing data */
if (ses.sock_out != -1) { if (ses.sock_out != -1) {
if (FD_ISSET(ses.sock_out, &writefd) && !isempty(&ses.writequeue)) { if (FD_ISSET(ses.sock_out, &writefd) && !isempty(&ses.writequeue)) {
write_packet(); write_packets();
} }
} }

View File

@ -46,14 +46,16 @@ static buffer* buf_decompress(buffer* buf, unsigned int len);
static void buf_compress(buffer * dest, buffer * src, unsigned int len); static void buf_compress(buffer * dest, buffer * src, unsigned int len);
#endif #endif
/* non-blocking function writing out a current encrypted packet */ /* non-blocking function writing out a current encrypted packet. Returns
void write_packet() { * DROPBEAR_SUCCESS if entire packet was written, DROPBEAR_FAILURE
* otherwise */
static int write_packet() {
int len, written; int len, written;
int ret = DROPBEAR_FAILURE;
buffer * writebuf = NULL; buffer * writebuf = NULL;
TRACE(("enter write_packet")) TRACE(("enter write_packet"))
dropbear_assert(!isempty(&ses.writequeue));
/* Get the next buffer in the queue of encrypted packets to write*/ /* Get the next buffer in the queue of encrypted packets to write*/
writebuf = (buffer*)examine(&ses.writequeue); writebuf = (buffer*)examine(&ses.writequeue);
@ -84,12 +86,19 @@ void write_packet() {
dequeue(&ses.writequeue); dequeue(&ses.writequeue);
buf_free(writebuf); buf_free(writebuf);
writebuf = NULL; writebuf = NULL;
ret = DROPBEAR_SUCCESS;
} else { } else {
/* More packet left to write, leave it in the queue for later */ /* More packet left to write, leave it in the queue for later */
buf_incrpos(writebuf, written); buf_incrpos(writebuf, written);
} }
TRACE(("leave write_packet")) 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 /* Non-blocking function reading available portion of a packet into the

View File

@ -28,7 +28,7 @@
#include "includes.h" #include "includes.h"
void write_packet(); void write_packets();
void read_packet(); void read_packet();
void decrypt_packet(); void decrypt_packet();
void encrypt_packet(); void encrypt_packet();