comparison packet.c @ 1072:686cd3e8e13e

avoid malloc for iovec
author Matt Johnston <matt@ucc.asn.au>
date Fri, 20 Mar 2015 22:53:32 +0800
parents 16584026a1f0
children 10f198d4a308
comparison
equal deleted inserted replaced
1067:ce21d0bfaf98 1072:686cd3e8e13e
56 /* non-blocking function writing out a current encrypted packet */ 56 /* non-blocking function writing out a current encrypted packet */
57 void write_packet() { 57 void write_packet() {
58 58
59 ssize_t written; 59 ssize_t written;
60 #ifdef HAVE_WRITEV 60 #ifdef HAVE_WRITEV
61 struct iovec *iov = NULL; 61 /* 50 is somewhat arbitrary */
62 int iov_count; 62 int iov_count = 50;
63 struct iovec iov[50];
63 #endif 64 #endif
64 65
65 TRACE2(("enter write_packet")) 66 TRACE2(("enter write_packet"))
66 dropbear_assert(!isempty(&ses.writequeue)); 67 dropbear_assert(!isempty(&ses.writequeue));
67 68
68 #if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV)) 69 #if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
69 70
70 iov = packet_queue_to_iovec(&ses.writequeue, &iov_count); 71 packet_queue_to_iovec(&ses.writequeue, iov, &iov_count);
71 /* This may return EAGAIN. The main loop sometimes 72 /* This may return EAGAIN. The main loop sometimes
72 calls write_packet() without bothering to test with select() since 73 calls write_packet() without bothering to test with select() since
73 it's likely to be necessary */ 74 it's likely to be necessary */
74 written = writev(ses.sock_out, iov, iov_count); 75 written = writev(ses.sock_out, iov, iov_count);
75 if (written < 0) { 76 if (written < 0) {
76 if (errno == EINTR || errno == EAGAIN) { 77 if (errno == EINTR || errno == EAGAIN) {
77 TRACE2(("leave write_packet: EINTR")) 78 TRACE2(("leave write_packet: EINTR"))
78 m_free(iov);
79 return; 79 return;
80 } else { 80 } else {
81 dropbear_exit("Error writing: %s", strerror(errno)); 81 dropbear_exit("Error writing: %s", strerror(errno));
82 } 82 }
83 } 83 }
84 m_free(iov);
85 84
86 packet_queue_consume(&ses.writequeue, written); 85 packet_queue_consume(&ses.writequeue, written);
87 86
88 if (written == 0) { 87 if (written == 0) {
89 ses.remoteclosed(); 88 ses.remoteclosed();