use of org.webpieces.util.exceptions.NioClosedChannelException in project webpieces by deanhiller.
the class AsyncSSLEngine3Impl method feedPlainPacketImpl.
private XFuture<Void> feedPlainPacketImpl(ByteBuffer buffer) throws SSLException {
if (mem.getConnectionState() != ConnectionState.CONNECTED)
throw new NioClosedChannelException(mem + " SSLEngine is not connected right now");
else if (!buffer.hasRemaining())
throw new IllegalArgumentException("your buffer has no readable data");
SSLEngine sslEngine = mem.getEngine();
if (log.isTraceEnabled())
log.trace(mem + "feedPlainPacket [in-buffer] pos=" + buffer.position() + " lim=" + buffer.limit());
XFuture<Void> future = encryptionTracker.addBytesToTrack(buffer.remaining());
while (buffer.hasRemaining()) {
ByteBuffer engineToSocketData = pool.nextBuffer(sslEngine.getSession().getPacketBufferSize());
int remainBefore = buffer.remaining();
int numEncrypted;
SSLEngineResult result;
synchronized (wrapLock) {
circularBuffer.add(new Action(Thread.currentThread().getName(), ActionEnum.WRAP_START, sslEngine));
result = sslEngine.wrap(buffer, engineToSocketData);
circularBuffer.add(new Action(Thread.currentThread().getName(), ActionEnum.WRAP_END, sslEngine));
numEncrypted = remainBefore - buffer.remaining();
}
Status status = result.getStatus();
HandshakeStatus hsStatus = result.getHandshakeStatus();
if (status != Status.OK)
throw new RuntimeException("Bug, status=" + status + " instead of OK. hsStatus=" + hsStatus + " Something went wrong and we could not encrypt the data");
if (log.isTraceEnabled())
log.trace(mem + "SSLListener.packetEncrypted pos=" + engineToSocketData.position() + " lim=" + engineToSocketData.limit() + " hsStatus=" + hsStatus + " status=" + status);
engineToSocketData.flip();
metrics.recordEncryptedToSocket(engineToSocketData.remaining());
listener.packetEncrypted(engineToSocketData).handle((v, t) -> {
if (t != null) {
future.completeExceptionally(t);
}
encryptionTracker.ackBytes(numEncrypted);
return null;
});
}
pool.releaseBuffer(buffer);
return future;
}
use of org.webpieces.util.exceptions.NioClosedChannelException in project webpieces by deanhiller.
the class BasChannelImpl method unqueueAndFailWritesThenClose.
private void unqueueAndFailWritesThenClose(CloseRunnable action) {
List<XFuture<Void>> promises;
synchronized (this) {
// put here for emphasis that we are synchronizing here but not below
promises = failAllWritesInQueue();
}
// TODO: This should really be inlined now. It's a remnant of an old design since close didn't
// work well outside the selector thread previously
action.runDelayedAction();
// notify clients outside the synchronization block!!!
for (XFuture<Void> promise : promises) {
log.info("WRITES outstanding while close was called, notifying client through his failure method of the exception");
// we only incur the cost of Throwable.fillInStackTrace() if we will use this exception
// (it's called in the Throwable constructor) so we don't do this on every close channel
NioClosedChannelException closeExc = new NioClosedChannelException(this + "There are " + promises.size() + " writes that are not complete yet(you called write but " + "they did not call success back to the client).");
promise.completeExceptionally(closeExc);
}
}
Aggregations