Mercurial > dropbear
comparison packet.c @ 934:68723d66dec6
Be more careful in case a platform doesn't define UIO_MAXIOV nor IOV_MAX
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 20 May 2014 21:21:02 +0800 |
parents | c919dbb39395 |
children | a0819ecfee0b |
comparison
equal
deleted
inserted
replaced
933:c919dbb39395 | 934:68723d66dec6 |
---|---|
68 #endif | 68 #endif |
69 | 69 |
70 TRACE2(("enter write_packet")) | 70 TRACE2(("enter write_packet")) |
71 dropbear_assert(!isempty(&ses.writequeue)); | 71 dropbear_assert(!isempty(&ses.writequeue)); |
72 | 72 |
73 #ifdef HAVE_WRITEV | 73 #if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV)) |
74 | 74 |
75 #ifndef IOV_MAX | 75 #ifndef IOV_MAX |
76 #define IOV_MAX UIO_MAXIOV | 76 #define IOV_MAX UIO_MAXIOV |
77 #endif | 77 #endif |
78 | 78 |
79 /* Make sure the size of the iov is below the maximum allowed by the OS. */ | 79 /* Make sure the size of the iov is below the maximum allowed by the OS. */ |
80 iov_max_count = ses.writequeue.count; | 80 iov_max_count = ses.writequeue.count; |
81 if (iov_max_count > IOV_MAX) | 81 if (iov_max_count > IOV_MAX) |
82 { | |
82 iov_max_count = IOV_MAX; | 83 iov_max_count = IOV_MAX; |
84 } | |
83 | 85 |
84 iov = m_malloc(sizeof(*iov) * iov_max_count); | 86 iov = m_malloc(sizeof(*iov) * iov_max_count); |
85 for (l = ses.writequeue.head, i = 0; l; l = l->link, i++) | 87 for (l = ses.writequeue.head, i = 0; l; l = l->link, i++) |
86 { | 88 { |
87 writebuf = (buffer*)l->item; | 89 writebuf = (buffer*)l->item; |
122 buf_free(writebuf); | 124 buf_free(writebuf); |
123 } | 125 } |
124 } | 126 } |
125 | 127 |
126 m_free(iov); | 128 m_free(iov); |
127 | 129 #else /* No writev () */ |
128 #else | |
129 /* Get the next buffer in the queue of encrypted packets to write*/ | 130 /* Get the next buffer in the queue of encrypted packets to write*/ |
130 writebuf = (buffer*)examine(&ses.writequeue); | 131 writebuf = (buffer*)examine(&ses.writequeue); |
131 | 132 |
132 /* The last byte of the buffer is not to be transmitted, but is | 133 /* The last byte of the buffer is not to be transmitted, but is |
133 * a cleartext packet_type indicator */ | 134 * a cleartext packet_type indicator */ |
158 writebuf = NULL; | 159 writebuf = NULL; |
159 } else { | 160 } else { |
160 /* More packet left to write, leave it in the queue for later */ | 161 /* More packet left to write, leave it in the queue for later */ |
161 buf_incrpos(writebuf, written); | 162 buf_incrpos(writebuf, written); |
162 } | 163 } |
163 | 164 #endif /* writev */ |
164 #endif | 165 |
165 now = monotonic_now(); | 166 now = monotonic_now(); |
166 ses.last_trx_packet_time = now; | 167 ses.last_trx_packet_time = now; |
167 | 168 |
168 if (!all_ignore) { | 169 if (!all_ignore) { |
169 ses.last_packet_time = now; | 170 ses.last_packet_time = now; |