@@ -1722,85 +1722,91 @@ channel_handle_wfd(Channel *c, fd_set *readset, fd_set *writeset)
17221722 int len ;
17231723
17241724 /* Send buffered output data to the socket. */
1725- if (c -> wfd != -1 &&
1726- FD_ISSET (c -> wfd , writeset ) &&
1727- buffer_len (& c -> output ) > 0 ) {
1728- olen = buffer_len (& c -> output );
1729- if (c -> output_filter != NULL ) {
1730- if ((buf = c -> output_filter (c , & data , & dlen )) == NULL ) {
1731- debug2 ("channel %d: filter stops" , c -> self );
1732- if (c -> type != SSH_CHANNEL_OPEN )
1733- chan_mark_dead (c );
1734- else
1735- chan_write_failed (c );
1736- return -1 ;
1737- }
1738- } else if (c -> datagram ) {
1739- buf = data = buffer_get_string (& c -> output , & dlen );
1740- } else {
1741- buf = data = buffer_ptr (& c -> output );
1742- dlen = buffer_len (& c -> output );
1743- }
1725+ if (c -> wfd != -1 &&
1726+ FD_ISSET (c -> wfd , writeset ) &&
1727+ buffer_len (& c -> output ) > 0 ) {
1728+ olen = buffer_len (& c -> output );
1729+ if (c -> output_filter != NULL ) {
1730+ if ((buf = c -> output_filter (c , & data , & dlen )) == NULL ) {
1731+ debug2 ("channel %d: filter stops" , c -> self );
1732+ if (c -> type != SSH_CHANNEL_OPEN )
1733+ chan_mark_dead (c );
1734+ else
1735+ chan_write_failed (c );
1736+ return -1 ;
1737+ }
1738+ } else if (c -> datagram ) {
1739+ buf = data = buffer_get_string (& c -> output , & dlen );
1740+ } else {
1741+ buf = data = buffer_ptr (& c -> output );
1742+ dlen = buffer_len (& c -> output );
1743+ }
17441744
1745- if (c -> datagram ) {
1746- /* ignore truncated writes, datagrams might get lost */
1747- len = write (c -> wfd , buf , dlen );
1748- free (data );
1749- if (len < 0 && (errno == EINTR || errno == EAGAIN ||
1750- errno == EWOULDBLOCK ))
1751- return 1 ;
1752- if (len <= 0 ) {
1753- if (c -> type != SSH_CHANNEL_OPEN )
1754- chan_mark_dead (c );
1755- else
1756- chan_write_failed (c );
1757- return -1 ;
1758- }
1759- goto out ;
1760- }
1745+ if (c -> datagram ) {
1746+ /* ignore truncated writes, datagrams might get lost */
1747+ len = write (c -> wfd , buf , dlen );
1748+ free (data );
1749+ if (len < 0 && (errno == EINTR || errno == EAGAIN ||
1750+ errno == EWOULDBLOCK ))
1751+ return 1 ;
1752+ if (len <= 0 ) {
1753+ if (c -> type != SSH_CHANNEL_OPEN )
1754+ chan_mark_dead (c );
1755+ else
1756+ chan_write_failed (c );
1757+ return -1 ;
1758+ }
1759+ goto out ;
1760+ }
17611761#ifdef _AIX
1762- /* XXX: Later AIX versions can't push as much data to tty */
1763- if (compat20 && c -> wfd_isatty )
1764- dlen = MIN (dlen , 8 * 1024 );
1762+ /* XXX: Later AIX versions can't push as much data to tty */
1763+ if (compat20 && c -> wfd_isatty )
1764+ dlen = MIN (dlen , 8 * 1024 );
1765+ #endif
1766+ #ifdef WIN32_FIXME /* TODO - Fix this - on windows we somehow end up with dlen = 0*/
1767+ if (dlen > 0 ) {
17651768#endif
17661769
1767- len = write (c -> wfd , buf , dlen );
1768- if (len < 0 &&
1769- (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK ))
1770- return 1 ;
1771- if (len <= 0 ) {
1772- if (c -> type != SSH_CHANNEL_OPEN ) {
1773- debug2 ("channel %d: not open" , c -> self );
1774- chan_mark_dead (c );
1775- return -1 ;
1776- } else if (compat13 ) {
1777- buffer_clear (& c -> output );
1778- debug2 ("channel %d: input draining." , c -> self );
1779- c -> type = SSH_CHANNEL_INPUT_DRAINING ;
1780- } else {
1781- chan_write_failed (c );
1782- }
1783- return -1 ;
1784- }
1770+ len = write (c -> wfd , buf , dlen );
1771+ if (len < 0 &&
1772+ (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK ))
1773+ return 1 ;
1774+ if (len <= 0 ) {
1775+ if (c -> type != SSH_CHANNEL_OPEN ) {
1776+ debug2 ("channel %d: not open" , c -> self );
1777+ chan_mark_dead (c );
1778+ return -1 ;
1779+ } else if (compat13 ) {
1780+ buffer_clear (& c -> output );
1781+ debug2 ("channel %d: input draining." , c -> self );
1782+ c -> type = SSH_CHANNEL_INPUT_DRAINING ;
1783+ } else {
1784+ chan_write_failed (c );
1785+ }
1786+ return -1 ;
1787+ }
17851788#ifndef WIN32_FIXME //R
17861789#ifndef BROKEN_TCGETATTR_ICANON
1787- if (compat20 && c -> isatty && dlen >= 1 && buf [0 ] != '\r' ) {
1788- if (tcgetattr (c -> wfd , & tio ) == 0 &&
1789- !(tio .c_lflag & ECHO ) && (tio .c_lflag & ICANON )) {
1790- /*
1791- * Simulate echo to reduce the impact of
1792- * traffic analysis. We need to match the
1793- * size of a SSH2_MSG_CHANNEL_DATA message
1794- * (4 byte channel id + buf)
1795- */
1796- packet_send_ignore (4 + len );
1797- packet_send ();
1798- }
1799- }
1790+ if (compat20 && c -> isatty && dlen >= 1 && buf [0 ] != '\r' ) {
1791+ if (tcgetattr (c -> wfd , & tio ) == 0 &&
1792+ !(tio .c_lflag & ECHO ) && (tio .c_lflag & ICANON )) {
1793+ /*
1794+ * Simulate echo to reduce the impact of
1795+ * traffic analysis. We need to match the
1796+ * size of a SSH2_MSG_CHANNEL_DATA message
1797+ * (4 byte channel id + buf)
1798+ */
1799+ packet_send_ignore (4 + len );
1800+ packet_send ();
1801+ }
1802+ }
18001803#endif
18011804#endif
1802- buffer_consume (& c -> output , len );
1803- }
1805+ buffer_consume (& c -> output , len );
1806+ }
1807+ #ifdef WIN32_FIXME /* for if (dlen > 0) */
1808+ }
1809+ #endif
18041810 out :
18051811 if (compat20 && olen > 0 )
18061812 c -> local_consumed += olen - buffer_len (& c -> output );
0 commit comments