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


Java Status.CLOSED属性代码示例

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


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

示例1: sendData

/**
 * send the data in the given ByteBuffer. If a handshake is needed
 * then this is handled within this method. When this call returns,
 * all of the given user data has been sent and any handshake has been
 * completed. Caller should check if engine has been closed.
 */
WrapperResult sendData (ByteBuffer[] src, int offset, int len) throws IOException {
    WrapperResult r = WrapperResult.createOK();
    while (countBytes(src, offset, len) > 0) {
        r = wrapper.wrapAndSend(src, offset, len, false);
        Status status = r.result.getStatus();
        if (status == Status.CLOSED) {
            doClosure ();
            return r;
        }
        HandshakeStatus hs_status = r.result.getHandshakeStatus();
        if (hs_status != HandshakeStatus.FINISHED &&
            hs_status != HandshakeStatus.NOT_HANDSHAKING)
        {
            doHandshake(hs_status);
        }
    }
    return r;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:SSLDelegate.java

示例2: recvData

/**
 * read data thru the engine into the given ByteBuffer. If the
 * given buffer was not large enough, a new one is allocated
 * and returned. This call handles handshaking automatically.
 * Caller should check if engine has been closed.
 */
WrapperResult recvData (ByteBuffer dst) throws IOException {
    /* we wait until some user data arrives */
    int mark = dst.position();
    WrapperResult r = null;
    int pos = dst.position();
    while (dst.position() == pos) {
        r = wrapper.recvAndUnwrap (dst);
        dst = (r.buf != dst) ? r.buf: dst;
        Status status = r.result.getStatus();
        if (status == Status.CLOSED) {
            doClosure ();
            return r;
        }

        HandshakeStatus hs_status = r.result.getHandshakeStatus();
        if (hs_status != HandshakeStatus.FINISHED &&
            hs_status != HandshakeStatus.NOT_HANDSHAKING)
        {
            doHandshake (hs_status);
        }
    }
    Utils.flipToMark(dst, mark);
    return r;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:SSLDelegate.java

示例3: unwrap

/**
 * performs the unwrap operation by unwrapping from {@link #inCrypt} to {@link #inData}
 **/
private synchronized ByteBuffer unwrap() throws SSLException {
	int rem;
	//There are some ssl test suites, which get around the selector.select() call, which cause an infinite unwrap and 100% cpu usage (see #459 and #458)
	if(readEngineResult.getStatus() == Status.CLOSED && sslEngine.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING){
		try {
			close();
		} catch (IOException e) {
			//Not really interesting
		}
	}
	do {
		rem = inData.remaining();
		readEngineResult = sslEngine.unwrap( inCrypt, inData );
	} while ( readEngineResult.getStatus() == Status.OK && ( rem != inData.remaining() || sslEngine.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP ) );
	inData.flip();
	return inData;
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:20,代码来源:SSLSocketChannel2.java

示例4: write

public int write( ByteBuffer src ) throws IOException {
	if( !isHandShakeComplete() ) {
		processHandshake();
		return 0;
	}
	// assert ( bufferallocations > 1 ); //see #190
	//if( bufferallocations <= 1 ) {
	//	createBuffers( sslEngine.getSession() );
	//}
	int num = socketChannel.write( wrap( src ) );
       if (writeEngineResult.getStatus() == Status.CLOSED) {
           throw new EOFException("Connection is closed");
       }
	return num;

}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:16,代码来源:SSLSocketChannel2.java

示例5: readRemaining

/**
 * {@link #read(ByteBuffer)} may not be to leave all buffers(inData, inCrypt)
 **/
private int readRemaining( ByteBuffer dst ) throws SSLException {
	if( inData.hasRemaining() ) {
		return transfereTo( inData, dst );
	}
	if( !inData.hasRemaining() )
		inData.clear();
	// test if some bytes left from last read (e.key. BUFFER_UNDERFLOW)
	if( inCrypt.hasRemaining() ) {
		unwrap();
		int amount = transfereTo( inData, dst );
           if (readEngineResult.getStatus() == Status.CLOSED) {
               return -1;
           }
		if( amount > 0 )
			return amount;
	}
	return 0;
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:21,代码来源:SSLSocketChannel2.java

示例6: getStatus

/**
 * Returns the current status for this TLSHandler.
 *
 * @return the current TLSStatus
 */
public TLSStatus getStatus() {
    if (tlsEngineResult != null && tlsEngineResult.getStatus() == Status.BUFFER_UNDERFLOW) {
        return TLSStatus.UNDERFLOW;
    } else {
        if (tlsEngineResult != null && tlsEngineResult.getStatus() == Status.CLOSED) {
            return TLSStatus.CLOSED;
        } else {
            switch (tlsEngine.getHandshakeStatus()) {
            case NEED_WRAP:
                return TLSStatus.NEED_WRITE;
            case NEED_UNWRAP:
                return TLSStatus.NEED_READ;
            default:
                return TLSStatus.OK;
            }
        }
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:23,代码来源:TLSWrapper.java

示例7: getStatus

/**
 * Returns the current status for this TLSHandler.
 *
 * @return the current TLSStatus
 */
public TLSStatus getStatus() {
    TLSStatus status = null;
    if (tlsEngineResult != null && tlsEngineResult.getStatus() == Status.BUFFER_UNDERFLOW) {
        status = TLSStatus.UNDERFLOW;
    } else {
        if (tlsEngineResult != null && tlsEngineResult.getStatus() == Status.CLOSED) {
            status = TLSStatus.CLOSED;
        } else {
            switch (tlsEngine.getHandshakeStatus()) {
            case NEED_WRAP:
                status = TLSStatus.NEED_WRITE;
                break;
            case NEED_UNWRAP:
                status = TLSStatus.NEED_READ;
                break;
            default:
                status = TLSStatus.OK;
                break;
            }
        }
    }
    return status;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:28,代码来源:TLSWrapper.java

示例8: closeOutbound

/**
 * Start SSL shutdown process.
 *
 * @return <tt>true</tt> if shutdown process is started.
 *         <tt>false</tt> if shutdown process is already finished.
 * @throws SSLException on errors
 */
boolean closeOutbound() throws SSLException {
	if (sslEngine == null || sslEngine.isOutboundDone()) {
		return false;
	}

	sslEngine.closeOutbound();

	createOutNetBuffer(0);

	for (;;) {
		SSLEngineResult result = sslEngine.wrap(SimpleBufferAllocator.emptyBuffer.buf(), outNetBuffer.buf());
		if (result.getStatus() != Status.BUFFER_OVERFLOW) {
			if (result.getStatus() != Status.CLOSED) {
				throw new SSLException("Improper close state: " + result);
			}
			break;
		}
		outNetBuffer = IoBuffer.reallocate(outNetBuffer, outNetBuffer.capacity() << 1);
		outNetBuffer.limit(outNetBuffer.capacity());
	}

	outNetBuffer.flip();

	return true;
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:32,代码来源:SslHandler.java

示例9: shutdown

public void shutdown() throws IOException {

		//if (!shutdown) {
		//            sslEngine.closeOutbound();
		//  shutdown = true;
		//}

		if (outNetBB.hasRemaining() && tryFlush(outNetBB)) {
			//return false;
		}

		/*
		 * By RFC 2616, we can "fire and forget" our close_notify
		 * message, so that's what we'll do here.
		 */
		for(int i = 0; i<3 && !engine.isInboundDone(); i++){ //3 retry

			engine.closeOutbound();
			outNetBB.clear();
			SSLEngineResult result = engine.wrap(hsBB, outNetBB);
			if (result.getStatus() != Status.CLOSED) {
				throw new SSLException("Improper close state");
			}
			outNetBB.flip();

			/*
			 * We won't wait for a select here, but if this doesn't work,
			 * we'll cycle back through on the next select.
			 */
			if (outNetBB.hasRemaining()) {
				tryFlush(outNetBB);
			}
		}
		conn.setTLS(null);

	}
 
开发者ID:Anoncheg1,项目名称:dibd,代码行数:36,代码来源:TLS.java

示例10: write

/**
* Writes a sequence of bytes to this channel from the given buffer.
*
* @param src The buffer from which bytes are to be retrieved
* @return The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
* @throws IOException If some other I/O error occurs
*/
@Override
public int write(ByteBuffer src) throws IOException {
    int written = 0;
    if (closing) throw new IllegalStateException("Channel is in closing state");
    if (!handshakeComplete) return written;

    if (!flush(netWriteBuffer))
        return written;

    netWriteBuffer.clear();
    SSLEngineResult wrapResult = sslEngine.wrap(src, netWriteBuffer);
    netWriteBuffer.flip();

    //handle ssl renegotiation
    if (wrapResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && wrapResult.getStatus() == Status.OK) {
        renegotiate();
        return written;
    }

    if (wrapResult.getStatus() == Status.OK) {
        written = wrapResult.bytesConsumed();
        flush(netWriteBuffer);
    } else if (wrapResult.getStatus() == Status.BUFFER_OVERFLOW) {
        int currentNetWriteBufferSize = netWriteBufferSize();
        netWriteBuffer.compact();
        netWriteBuffer = Utils.ensureCapacity(netWriteBuffer, currentNetWriteBufferSize);
        netWriteBuffer.flip();
        if (netWriteBuffer.limit() >= currentNetWriteBufferSize)
            throw new IllegalStateException("SSL BUFFER_OVERFLOW when available data size (" + netWriteBuffer.limit() + ") >= network buffer size (" + currentNetWriteBufferSize + ")");
    } else if (wrapResult.getStatus() == Status.BUFFER_UNDERFLOW) {
        throw new IllegalStateException("SSL BUFFER_UNDERFLOW during write");
    } else if (wrapResult.getStatus() == Status.CLOSED) {
        throw new EOFException();
    }
    return written;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:43,代码来源:SslTransportLayer.java

示例11: write

@Override
long write(ByteBuffer[] buffers, int start, int number) throws IOException {
    //debugPrint("Send", buffers, start, number);
    long l = countBytes(buffers, start, number);
    WrapperResult r = sslDelegate.sendData(buffers, start, number);
    if (r.result.getStatus() == Status.CLOSED) {
        if (l > 0) {
            throw new IOException("SSLHttpConnection closed");
        }
    }
    return l;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:SSLConnection.java

示例12: doClosure

void doClosure () throws IOException {
    try {
        handshaking.lock();
        ByteBuffer tmp = allocate(BufType.APPLICATION);
        WrapperResult r;
        do {
            tmp.clear();
            tmp.flip ();
            r = wrapper.wrapAndSend(tmp, true);
        } while (r.result.getStatus() != Status.CLOSED);
    } finally {
        handshaking.unlock();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:SSLDelegate.java

示例13: write

@Override public void write(byte[] buf, int off, int len) throws IOException
{
  if (!initialHandshakeDone
      || engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING)
    {
      doHandshake();
      if (handshakeException != null)
        throw handshakeException;
    }

  int k = 0;
  while (k < len)
    {
      synchronized (engine)
        {
          int l = Math.min(len-k, getSession().getApplicationBufferSize());
          ByteBuffer in = ByteBuffer.wrap(buf, off+k, l);
          SSLEngineResult result = engine.wrap(in, buffer);
          if (result.getStatus() == Status.CLOSED)
            return;
          if (result.getStatus() != Status.OK)
            throw new SSLException("unexpected SSL state " + result.getStatus());
          buffer.flip();
          out.write(buffer.array(), 0, buffer.limit());
          k += result.bytesConsumed();
          buffer.clear();
        }
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:29,代码来源:SSLSocketImpl.java

示例14: read

@Override public int read(byte[] buf, int off, int len) throws IOException
{
  if (!initialHandshakeDone ||
      engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING)
    {
      doHandshake();
      if (handshakeException != null)
        throw handshakeException;
    }

  if (!appBuffer.hasRemaining())
    {
      int x = in.read();
      if (x == -1)
        return -1;
      inBuffer.clear();
      inBuffer.put((byte) x);
      inBuffer.putInt(in.readInt());
      int reclen = inBuffer.getShort(3) & 0xFFFF;
      in.readFully(inBuffer.array(), 5, reclen);
      inBuffer.position(0).limit(reclen + 5);
      synchronized (engine)
        {
          appBuffer.clear();
          SSLEngineResult result = engine.unwrap(inBuffer, appBuffer);
          Status status = result.getStatus();
          if (status == Status.CLOSED && result.bytesProduced() == 0)
            return -1;
        }
      inBuffer.compact();
      appBuffer.flip();
    }
  int l = Math.min(len, appBuffer.remaining());
  appBuffer.get(buf, off, l);
  return l;
}
 
开发者ID:vilie,项目名称:javify,代码行数:36,代码来源:SSLSocketImpl.java

示例15: handshakeWrapLogic

public static void handshakeWrapLogic(SSLConnection cc, Pipe<NetPayloadSchema> target, ByteBuffer buffer, boolean isServer, long arrivalTime) {
    
	try {

		do {
			if (!Pipe.hasRoomForWrite(target)) {
				return; //unable to complete, try again later
			}
			
			final ByteBuffer[] targetBuffers = Pipe.wrappedWritingBuffers(Pipe.storeBlobWorkingHeadPosition(target), target);
			final Status status = SSLUtil.wrapResultStatusState(target, buffer, cc, noDatas, targetBuffers, isServer, arrivalTime);
			
			if (Status.OK == status) {
				
				Pipe.confirmLowLevelWrite(target, Pipe.sizeOf(target, NetPayloadSchema.MSG_ENCRYPTED_200));
				Pipe.publishWrites(target);
				
			} else {
				//connection was closed before handshake completed 
				//already closed, NOTE we should release this from reserved pipe pools
				//no need to cancel wrapped buffer it was already done by wrapResultStatusState
				cc.close();
			    if (Status.CLOSED != status) {
			    	//not expected case so log this
			    	logger.warn("HANDSHAKE unable to wrap {} {} {} ",status, cc.getClass().getSimpleName(), cc.getEngine(), new Exception());	
			    }
			    return;
			}
		} while(cc.getEngine().getHandshakeStatus() == HandshakeStatus.NEED_WRAP); 
		
				
	} catch (SSLException e) {
		//logger.error("unable to wrap ", e);
		
		Pipe.unstoreBlobWorkingHeadPosition(target);
	}	
    
}
 
开发者ID:oci-pronghorn,项目名称:Pronghorn,代码行数:38,代码来源:SSLUtil.java


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