Mercurial > dropbear
comparison packet.c @ 531:164b7c2cd5df
disapproval of revision 'a101cbd046507cf723e6362a49196dbd4b924042'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 26 Feb 2009 13:20:53 +0000 |
parents | da6340a60039 |
children | c67c8c0c6c35 |
comparison
equal
deleted
inserted
replaced
529:da6340a60039 | 531:164b7c2cd5df |
---|---|
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. Returns | 49 /* non-blocking function writing out a current encrypted packet */ |
50 * DROPBEAR_SUCCESS if entire packet was written, DROPBEAR_FAILURE | 50 void write_packet() { |
51 * otherwise */ | |
52 static int write_packet() { | |
53 | 51 |
54 int len, written; | 52 int len, written; |
55 int ret = DROPBEAR_FAILURE; | |
56 buffer * writebuf = NULL; | 53 buffer * writebuf = NULL; |
57 | 54 |
58 TRACE(("enter write_packet")) | 55 TRACE(("enter write_packet")) |
56 dropbear_assert(!isempty(&ses.writequeue)); | |
59 | 57 |
60 /* Get the next buffer in the queue of encrypted packets to write*/ | 58 /* Get the next buffer in the queue of encrypted packets to write*/ |
61 writebuf = (buffer*)examine(&ses.writequeue); | 59 writebuf = (buffer*)examine(&ses.writequeue); |
62 | 60 |
63 len = writebuf->len - writebuf->pos; | 61 len = writebuf->len - writebuf->pos; |
84 if (written == len) { | 82 if (written == len) { |
85 /* We've finished with the packet, free it */ | 83 /* We've finished with the packet, free it */ |
86 dequeue(&ses.writequeue); | 84 dequeue(&ses.writequeue); |
87 buf_free(writebuf); | 85 buf_free(writebuf); |
88 writebuf = NULL; | 86 writebuf = NULL; |
89 ret = DROPBEAR_SUCCESS; | |
90 } else { | 87 } else { |
91 /* More packet left to write, leave it in the queue for later */ | 88 /* More packet left to write, leave it in the queue for later */ |
92 buf_incrpos(writebuf, written); | 89 buf_incrpos(writebuf, written); |
93 } | 90 } |
94 | 91 |
95 TRACE(("leave write_packet")) | 92 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) {} | |
102 } | 93 } |
103 | 94 |
104 /* Non-blocking function reading available portion of a packet into the | 95 /* Non-blocking function reading available portion of a packet into the |
105 * ses's buffer, decrypting the length if encrypted, decrypting the | 96 * ses's buffer, decrypting the length if encrypted, decrypting the |
106 * full portion if possible */ | 97 * full portion if possible */ |