@@ -1722,85 +1722,95 @@ 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+ }
1739+ else if (c -> datagram ) {
1740+ buf = data = buffer_get_string (& c -> output , & dlen );
1741+ }
1742+ else {
1743+ buf = data = buffer_ptr (& c -> output );
1744+ dlen = buffer_len (& c -> output );
1745+ }
17441746
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- }
1747+ if (c -> datagram ) {
1748+ /* ignore truncated writes, datagrams might get lost */
1749+ len = write (c -> wfd , buf , dlen );
1750+ free (data );
1751+ if (len < 0 && (errno == EINTR || errno == EAGAIN ||
1752+ errno == EWOULDBLOCK ))
1753+ return 1 ;
1754+ if (len <= 0 ) {
1755+ if (c -> type != SSH_CHANNEL_OPEN )
1756+ chan_mark_dead (c );
1757+ else
1758+ chan_write_failed (c );
1759+ return -1 ;
1760+ }
1761+ goto out ;
1762+ }
17611763#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 );
1764+ /* XXX: Later AIX versions can't push as much data to tty */
1765+ if (compat20 && c -> wfd_isatty )
1766+ dlen = MIN (dlen , 8 * 1024 );
1767+ #endif
1768+ #ifdef WIN32_FIXME /* TODO - Fix this - on windows we somehow end up with dlen = 0*/
1769+ if (dlen > 0 ) {
17651770#endif
17661771
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- }
1772+ len = write (c -> wfd , buf , dlen );
1773+ if (len < 0 &&
1774+ (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK ))
1775+ return 1 ;
1776+ if (len <= 0 ) {
1777+ if (c -> type != SSH_CHANNEL_OPEN ) {
1778+ debug2 ("channel %d: not open" , c -> self );
1779+ chan_mark_dead (c );
1780+ return -1 ;
1781+ }
1782+ else if (compat13 ) {
1783+ buffer_clear (& c -> output );
1784+ debug2 ("channel %d: input draining." , c -> self );
1785+ c -> type = SSH_CHANNEL_INPUT_DRAINING ;
1786+ }
1787+ else {
1788+ chan_write_failed (c );
1789+ }
1790+ return -1 ;
1791+ }
17851792#ifndef WIN32_FIXME //R
17861793#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- }
1794+ if (compat20 && c -> isatty && dlen >= 1 && buf [0 ] != '\r' ) {
1795+ if (tcgetattr (c -> wfd , & tio ) == 0 &&
1796+ !(tio .c_lflag & ECHO ) && (tio .c_lflag & ICANON )) {
1797+ /*
1798+ * Simulate echo to reduce the impact of
1799+ * traffic analysis. We need to match the
1800+ * size of a SSH2_MSG_CHANNEL_DATA message
1801+ * (4 byte channel id + buf)
1802+ */
1803+ packet_send_ignore (4 + len );
1804+ packet_send ();
1805+ }
1806+ }
18001807#endif
18011808#endif
1802- buffer_consume (& c -> output , len );
1803- }
1809+ buffer_consume (& c -> output , len );
1810+ }
1811+ #ifdef WIN32_FIXME /* for if (dlen > 0) */
1812+ }
1813+ #endif
18041814 out :
18051815 if (compat20 && olen > 0 )
18061816 c -> local_consumed += olen - buffer_len (& c -> output );
0 commit comments