comparison packet.c @ 529:da6340a60039

- Try to write out as much as we can
author Matt Johnston <matt@ucc.asn.au>
date Thu, 26 Feb 2009 12:18:11 +0000
parents a3748e54273c
children 22a0d8355c2c 164b7c2cd5df
comparison
equal deleted inserted replaced
518:ce104c8b0be1 529:da6340a60039
44 #ifndef DISABLE_ZLIB 44 #ifndef DISABLE_ZLIB
45 static buffer* buf_decompress(buffer* buf, unsigned int len); 45 static buffer* buf_decompress(buffer* buf, unsigned int len);
46 static void buf_compress(buffer * dest, buffer * src, unsigned int len); 46 static void buf_compress(buffer * dest, buffer * src, unsigned int len);
47 #endif 47 #endif
48 48
49 /* non-blocking function writing out a current encrypted packet */ 49 /* non-blocking function writing out a current encrypted packet. Returns
50 void write_packet() { 50 * DROPBEAR_SUCCESS if entire packet was written, DROPBEAR_FAILURE
51 * otherwise */
52 static int write_packet() {
51 53
52 int len, written; 54 int len, written;
55 int ret = DROPBEAR_FAILURE;
53 buffer * writebuf = NULL; 56 buffer * writebuf = NULL;
54 57
55 TRACE(("enter write_packet")) 58 TRACE(("enter write_packet"))
56 dropbear_assert(!isempty(&ses.writequeue));
57 59
58 /* Get the next buffer in the queue of encrypted packets to write*/ 60 /* Get the next buffer in the queue of encrypted packets to write*/
59 writebuf = (buffer*)examine(&ses.writequeue); 61 writebuf = (buffer*)examine(&ses.writequeue);
60 62
61 len = writebuf->len - writebuf->pos; 63 len = writebuf->len - writebuf->pos;
82 if (written == len) { 84 if (written == len) {
83 /* We've finished with the packet, free it */ 85 /* We've finished with the packet, free it */
84 dequeue(&ses.writequeue); 86 dequeue(&ses.writequeue);
85 buf_free(writebuf); 87 buf_free(writebuf);
86 writebuf = NULL; 88 writebuf = NULL;
89 ret = DROPBEAR_SUCCESS;
87 } else { 90 } else {
88 /* More packet left to write, leave it in the queue for later */ 91 /* More packet left to write, leave it in the queue for later */
89 buf_incrpos(writebuf, written); 92 buf_incrpos(writebuf, written);
90 } 93 }
91 94
92 TRACE(("leave write_packet")) 95 TRACE(("leave write_packet"))
96 return ret;
97 }
98
99 void write_packets() {
100 /* keep writing packets while we can. */
101 while (!isempty(&ses.writequeue) && write_packet() == DROPBEAR_SUCCESS) {}
93 } 102 }
94 103
95 /* Non-blocking function reading available portion of a packet into the 104 /* Non-blocking function reading available portion of a packet into the
96 * ses's buffer, decrypting the length if encrypted, decrypting the 105 * ses's buffer, decrypting the length if encrypted, decrypting the
97 * full portion if possible */ 106 * full portion if possible */