当前位置: 首页>>代码示例>>Java>>正文


Java Packets.SSH_MSG_CHANNEL_DATA属性代码示例

本文整理汇总了Java中com.trilead.ssh2.packets.Packets.SSH_MSG_CHANNEL_DATA属性的典型用法代码示例。如果您正苦于以下问题:Java Packets.SSH_MSG_CHANNEL_DATA属性的具体用法?Java Packets.SSH_MSG_CHANNEL_DATA怎么用?Java Packets.SSH_MSG_CHANNEL_DATA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.trilead.ssh2.packets.Packets的用法示例。


在下文中一共展示了Packets.SSH_MSG_CHANNEL_DATA属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendData

public void sendData(Channel c, byte[] buffer, int pos, int len) throws IOException
{
	while (len > 0)
	{
		int thislen = 0;
		byte[] msg;

		synchronized (c)
		{
			while (true)
			{
				if (c.state == Channel.STATE_CLOSED)
					throw new IOException("SSH channel is closed. (" + c.getReasonClosed() + ")");

				if (c.state != Channel.STATE_OPEN)
					throw new IOException("SSH channel in strange state. (" + c.state + ")");

				if (c.remoteWindow != 0)
					break;

				try
				{
					c.wait();
				}
				catch (InterruptedException ignore)
				{
				}
			}

			/* len > 0, no sign extension can happen when comparing */

			thislen = (c.remoteWindow >= len) ? len : (int) c.remoteWindow;

			int estimatedMaxDataLen = c.remoteMaxPacketSize - (tm.getPacketOverheadEstimate() + 9);

			/* The worst case scenario =) a true bottleneck */

			if (estimatedMaxDataLen <= 0)
			{
				estimatedMaxDataLen = 1;
			}

			if (thislen > estimatedMaxDataLen)
				thislen = estimatedMaxDataLen;

			c.remoteWindow -= thislen;

			msg = new byte[1 + 8 + thislen];

			msg[0] = Packets.SSH_MSG_CHANNEL_DATA;
			msg[1] = (byte) (c.remoteID >> 24);
			msg[2] = (byte) (c.remoteID >> 16);
			msg[3] = (byte) (c.remoteID >> 8);
			msg[4] = (byte) (c.remoteID);
			msg[5] = (byte) (thislen >> 24);
			msg[6] = (byte) (thislen >> 16);
			msg[7] = (byte) (thislen >> 8);
			msg[8] = (byte) (thislen);

			System.arraycopy(buffer, pos, msg, 9, thislen);
		}

		synchronized (c.channelSendLock)
		{
			if (c.closeMessageSent == true)
				throw new IOException("SSH channel is closed. (" + c.getReasonClosed() + ")");

			tm.sendMessage(msg);
		}

		pos += thislen;
		len -= thislen;
	}
}
 
开发者ID:dragonlinux,项目名称:connectbot,代码行数:74,代码来源:ChannelManager.java

示例2: sendData

public void sendData(Channel c, byte[] buffer, int pos, int len)
		throws IOException {
	while (len > 0) {
		int thislen = 0;
		byte[] msg;

		synchronized (c) {
			while (true) {
				if (c.state == Channel.STATE_CLOSED)
					throw new IOException("SSH channel is closed. ("
							+ c.getReasonClosed() + ")");

				if (c.state != Channel.STATE_OPEN)
					throw new IOException("SSH channel in strange state. ("
							+ c.state + ")");

				if (c.remoteWindow != 0)
					break;

				try {
					c.wait();
				} catch (InterruptedException ignore) {
				}
			}

			/* len > 0, no sign extension can happen when comparing */

			thislen = (c.remoteWindow >= len) ? len : (int) c.remoteWindow;

			int estimatedMaxDataLen = c.remoteMaxPacketSize
					- (tm.getPacketOverheadEstimate() + 9);

			/* The worst case scenario =) a true bottleneck */

			if (estimatedMaxDataLen <= 0) {
				estimatedMaxDataLen = 1;
			}

			if (thislen > estimatedMaxDataLen)
				thislen = estimatedMaxDataLen;

			c.remoteWindow -= thislen;

			msg = new byte[1 + 8 + thislen];

			msg[0] = Packets.SSH_MSG_CHANNEL_DATA;
			msg[1] = (byte) (c.remoteID >> 24);
			msg[2] = (byte) (c.remoteID >> 16);
			msg[3] = (byte) (c.remoteID >> 8);
			msg[4] = (byte) (c.remoteID);
			msg[5] = (byte) (thislen >> 24);
			msg[6] = (byte) (thislen >> 16);
			msg[7] = (byte) (thislen >> 8);
			msg[8] = (byte) (thislen);

			System.arraycopy(buffer, pos, msg, 9, thislen);
		}

		synchronized (c.channelSendLock) {
			if (c.closeMessageSent == true)
				throw new IOException("SSH channel is closed. ("
						+ c.getReasonClosed() + ")");

			tm.sendMessage(msg);
		}

		pos += thislen;
		len -= thislen;
	}
}
 
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:70,代码来源:ChannelManager.java


注:本文中的com.trilead.ssh2.packets.Packets.SSH_MSG_CHANNEL_DATA属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。