/** * @param channel * @param extendedType * @param data * @throws IOException */ public synchronized void sendChannelExtData(Channel channel, int extendedType, byte[] data) throws IOException { channel.getRemoteWindow().consumeWindowSpace(data.length); int sent = 0; int block; int remaining; long max; byte[] buffer; ChannelDataWindow window = channel.getRemoteWindow(); while (sent < data.length) { remaining = data.length - sent; max = ((window.getWindowSpace() < channel.getRemotePacketSize()) && (window.getWindowSpace() > 0)) ? window.getWindowSpace() : channel.getRemotePacketSize(); block = (max < remaining) ? (int) max : remaining; channel.remoteWindow.consumeWindowSpace(block); buffer = new byte[block]; System.arraycopy(data, sent, buffer, 0, block); SshMsgChannelExtendedData msg = new SshMsgChannelExtendedData(channel.getRemoteChannelId(), extendedType, buffer); transport.sendMessage(msg, this); /* if (type != null) { channel.sendChannelExtData(type.intValue(), buffer); } else { channel.sendChannelData(buffer); }*/ sent += block; } }
private void onMsgChannelWindowAdjust(SshMsgChannelWindowAdjust msg) throws IOException { Channel channel = getChannel(msg.getRecipientChannel()); if (channel == null) { throw new IOException( "Remote computer tried to increase " + "window space for non existent channel " + String.valueOf(msg.getRecipientChannel())); } channel.getRemoteWindow().increaseWindowSpace(msg.getBytesToAdd()); if (log.isDebugEnabled()) { log.debug(String.valueOf(msg.getBytesToAdd()) + " bytes added to remote window"); log.debug( "Remote window space is " + String.valueOf(channel.getRemoteWindow().getWindowSpace())); } }
/** * @param channel * @param data * @throws IOException */ public synchronized void sendChannelData(Channel channel, byte[] data) throws IOException { synchronized (channel.getState()) { if (log.isDebugEnabled()) { log.debug( "Sending " + String.valueOf(data.length) + " bytes for channel id " + String.valueOf(channel.getLocalChannelId())); } int sent = 0; int block; int remaining; long max; byte[] buffer; ChannelDataWindow window = channel.getRemoteWindow(); while (sent < data.length) { remaining = data.length - sent; max = ((window.getWindowSpace() < channel.getRemotePacketSize()) && (window.getWindowSpace() > 0)) ? window.getWindowSpace() : channel.getRemotePacketSize(); block = (max < remaining) ? (int) max : remaining; channel.remoteWindow.consumeWindowSpace(block); buffer = new byte[block]; System.arraycopy(data, sent, buffer, 0, block); SshMsgChannelData msg = new SshMsgChannelData(channel.getRemoteChannelId(), buffer); transport.sendMessage(msg, this); /* if (type != null) { channel.sendChannelExtData(type.intValue(), buffer); } else { channel.sendChannelData(buffer); }*/ sent += block; } } }