Java 类java.nio.channels.WritePendingException 实例源码

项目:tomcat7    文件:WsSession.java   
private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
        // PROTOCOL_ERROR is probably better than GOING_AWAY here
        msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
        msg.putShort((short) closeCode.getCode());
    }

    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
        appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
        wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
        handleCloseException(ioe, closeCode);
    } catch (WritePendingException wpe) {
        handleCloseException(wpe, closeCode);
    } finally {
        webSocketContainer.unregisterSession(localEndpoint, this);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:WsSession.java   
private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
        // PROTOCOL_ERROR is probably better than GOING_AWAY here
        msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
        msg.putShort((short) closeCode.getCode());
    }

    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
        appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
        wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
        handleCloseException(ioe, closeCode);
    } catch (WritePendingException wpe) {
        handleCloseException(wpe, closeCode);
    } finally {
        webSocketContainer.unregisterSession(localEndpoint, this);
    }
}
项目:lazycat    文件:WsSession.java   
private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
        // PROTOCOL_ERROR is probably better than GOING_AWAY here
        msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
        msg.putShort((short) closeCode.getCode());
    }

    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
        appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
        wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
        handleCloseException(ioe, closeCode);
    } catch (WritePendingException wpe) {
        handleCloseException(wpe, closeCode);
    } finally {
        webSocketContainer.unregisterSession(localEndpoint, this);
    }
}
项目:waterwave    文件:ProxyAioDataDealer.java   
private final void writeToServer0(ByteBuffer buffer) {
    try {
        buffer.flip();
        sc.write(buffer);
    } catch (WritePendingException e) {
        e.printStackTrace();
        buffer.position(buffer.limit());
        sq.add(buffer);
        writeServerFromQueue();
    }
}
项目:waterwave    文件:ProxyAioDataDealer.java   
private final void writeToClient0(ByteBuffer buffer) {
    try {
        buffer.flip();
        cc.write(buffer);
    } catch (WritePendingException e) {
        e.printStackTrace();
        buffer.position(buffer.limit());
        cq.add(buffer);
        writeClientFromQueue();
    }
}