channel.getConfig().getReceiveBufferSizePredictor();
final int predictedRecvBufSize = predictor.nextReceiveBufferSize();
boolean messageReceived = false;
boolean failure = true;
MessageInfo messageInfo = null;
ByteBuffer bb = recvBufferPool.acquire(predictedRecvBufSize);
try {
messageInfo = channel.channel.receive(bb, null, notificationHandler);
if (messageInfo != null) {
messageReceived = true;
if (!messageInfo.isUnordered()) {
failure = false;
} else {
if (logger.isErrorEnabled()) {
logger.error("Received unordered SCTP Packet");
}
failure = true;
}
} else {
messageReceived = false;
failure = false;
}
} catch (ClosedChannelException e) {
// Can happen, and does not need a user attention.
} catch (Throwable t) {
fireExceptionCaught(channel, t);
}
if (messageReceived) {
bb.flip();
final ChannelBufferFactory bufferFactory =
channel.getConfig().getBufferFactory();
final int receivedBytes = bb.remaining();
final ChannelBuffer buffer = bufferFactory.getBuffer(receivedBytes);
buffer.setBytes(0, bb);
buffer.writerIndex(receivedBytes);
recvBufferPool.release(bb);
// Update the predictor.
predictor.previousReceiveBufferSize(receivedBytes);
// Fire the event.
fireMessageReceived(channel,
new SctpFrame(messageInfo, buffer),
messageInfo.address());
} else {
recvBufferPool.release(bb);
}
if (channel.channel.isBlocking() && !messageReceived || failure) {