comparison packet.c @ 957:c4f138dae2fd

Test for EAGAIN too
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Aug 2014 21:55:43 +0800
parents a0819ecfee0b
children e3614649b1f5
comparison
equal deleted inserted replaced
955:36eacc322e00 957:c4f138dae2fd
91 TRACE2(("write_packet writev #%d type %d len %d/%d", i, packet_type, 91 TRACE2(("write_packet writev #%d type %d len %d/%d", i, packet_type,
92 len, writebuf->len-1)) 92 len, writebuf->len-1))
93 iov[i].iov_base = buf_getptr(writebuf, len); 93 iov[i].iov_base = buf_getptr(writebuf, len);
94 iov[i].iov_len = len; 94 iov[i].iov_len = len;
95 } 95 }
96 /* This may return EAGAIN. The main loop sometimes
97 calls write_packet() without bothering to test with select() since
98 it's likely to be necessary */
96 written = writev(ses.sock_out, iov, iov_max_count); 99 written = writev(ses.sock_out, iov, iov_max_count);
97 if (written < 0) { 100 if (written < 0) {
98 if (errno == EINTR) { 101 if (errno == EINTR || errno == EAGAIN) {
99 m_free(iov); 102 m_free(iov);
100 TRACE2(("leave write_packet: EINTR")) 103 TRACE2(("leave write_packet: EINTR"))
101 return; 104 return;
102 } else { 105 } else {
103 dropbear_exit("Error writing: %s", strerror(errno)); 106 dropbear_exit("Error writing: %s", strerror(errno));
134 dropbear_assert(len > 0); 137 dropbear_assert(len > 0);
135 /* Try to write as much as possible */ 138 /* Try to write as much as possible */
136 written = write(ses.sock_out, buf_getptr(writebuf, len), len); 139 written = write(ses.sock_out, buf_getptr(writebuf, len), len);
137 140
138 if (written < 0) { 141 if (written < 0) {
139 if (errno == EINTR) { 142 if (errno == EINTR || errno == EAGAIN) {
140 TRACE2(("leave writepacket: EINTR")) 143 TRACE2(("leave writepacket: EINTR"))
141 return; 144 return;
142 } else { 145 } else {
143 dropbear_exit("Error writing: %s", strerror(errno)); 146 dropbear_exit("Error writing: %s", strerror(errno));
144 } 147 }
253 maxlen); 256 maxlen);
254 if (slen == 0) { 257 if (slen == 0) {
255 ses.remoteclosed(); 258 ses.remoteclosed();
256 } 259 }
257 if (slen < 0) { 260 if (slen < 0) {
258 if (errno == EINTR) { 261 if (errno == EINTR || errno == EAGAIN) {
259 TRACE2(("leave read_packet_init: EINTR")) 262 TRACE2(("leave read_packet_init: EINTR"))
260 return DROPBEAR_FAILURE; 263 return DROPBEAR_FAILURE;
261 } 264 }
262 dropbear_exit("Error reading: %s", strerror(errno)); 265 dropbear_exit("Error reading: %s", strerror(errno));
263 } 266 }