⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssh2transportpdupool.java

📁 一个非常好的ssh客户端实现
💻 JAVA
字号:
/****************************************************************************** * * Copyright (c) 1999-2003 AppGate Network Security AB. All Rights Reserved. *  * This file contains Original Code and/or Modifications of Original Code as * defined in and that are subject to the MindTerm Public Source License, * Version 2.0, (the 'License'). You may not use this file except in compliance * with the License. *  * You should have received a copy of the MindTerm Public Source License * along with this software; see the file LICENSE.  If not, write to * AppGate Network Security AB, Otterhallegatan 2, SE-41118 Goteborg, SWEDEN * *****************************************************************************/package com.mindbright.ssh2;/** * Implements a pool of PDUs which can be reused. This class holds a * pool of PDUs and tries to reuse them whenever possible. */public class SSH2TransportPDUPool extends SSH2TransportPDU {    static int POOL_SIZE = 32;    protected class InPDU extends SSH2TransportPDU {	protected InPDU(int pktType, int bufSize) {	    super(pktType, bufSize);	}	public void release() {	    this.reset();	    this.pktSize = 0;	    releaseIn(this);	}    }    protected class OutPDU extends SSH2TransportPDU {	protected OutPDU(int pktType, int bufSize) {	    super(pktType, bufSize);	}	public void release() {	    this.reset();	    this.pktSize = 0;	    releaseOut(this);	}    }    int inCnt;    int outCnt;    int defInSz;    int defOutSz;    SSH2TransportPDU[] inPool;    SSH2TransportPDU[] outPool;    protected SSH2TransportPDUPool() {	inPool   = new SSH2TransportPDU[POOL_SIZE];	outPool  = new SSH2TransportPDU[POOL_SIZE];	inCnt    = POOL_SIZE;	outCnt   = POOL_SIZE;	defInSz  = pktDefaultSize;	defOutSz = ((pktDefaultSize * 3) / 2);	for(int i = 0; i < POOL_SIZE; i++) {	    inPool[i]  = new InPDU(0, defInSz);	    outPool[i] = new OutPDU(0, defOutSz);	}    }    protected SSH2TransportPDU createInPDU(int bufSize) {	synchronized(inPool) {	    if(inCnt == 0 || bufSize > defInSz) {		return new InPDU(0, bufSize);	    } else {		return inPool[--inCnt];	    }	}    }    protected SSH2TransportPDU createOutPDU(int pktType, int bufSize) {	SSH2TransportPDU pdu = null;	synchronized(outPool) {	    if(outCnt == 0 || bufSize > defOutSz) {		return new OutPDU(pktType, bufSize);	    } else {		pdu = outPool[--outCnt];	    }	}	pdu.pktType = pktType;	return pdu;    }    /**     * Internal class which releases an incoming PDU.     */    protected void releaseIn(InPDU pdu) {	synchronized(inPool) {	    if(inCnt < inPool.length && pdu.data.length >= defInSz) {		inPool[inCnt++] = pdu;	    } else {		/* stat */	    }	}    }    /**     * Internal class which releases an outgoing PDU.     */    protected void releaseOut(OutPDU pdu) {	synchronized(outPool) {	    if(outCnt < outPool.length && pdu.data.length >= defOutSz) {		outPool[outCnt++] = pdu;	    } else {		/* stat */	    }	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -