Refine search
ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes()); MessageInfo messageInfo = ch.receive(data, null, notificationHandler); if (messageInfo == null) { msgs.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead()))); free = false;
@Override protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception { SctpMessage packet = (SctpMessage) msg; ByteBuf data = packet.content(); int dataLen = data.readableBytes(); if (dataLen == 0) { return true; } ByteBufAllocator alloc = alloc(); boolean needsCopy = data.nioBufferCount() != 1; if (!needsCopy) { if (!data.isDirect() && alloc.isDirectBufferPooled()) { needsCopy = true; } } ByteBuffer nioData; if (needsCopy) { data = alloc.directBuffer(dataLen).writeBytes(data); } nioData = data.nioBuffer(); final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier()); mi.payloadProtocolID(packet.protocolIdentifier()); mi.streamNumber(packet.streamIdentifier()); mi.unordered(packet.isUnordered()); final int writtenBytes = javaChannel().send(nioData, mi); return writtenBytes > 0; }
@Override protected void decode(ChannelHandlerContext ctx, SctpMessage msg, List<Object> out) throws Exception { final ByteBuf byteBuf = msg.content(); final int protocolIdentifier = msg.protocolIdentifier(); final int streamIdentifier = msg.streamIdentifier(); final boolean isComplete = msg.isComplete(); final boolean isUnordered = msg.isUnordered(); if (isComplete && !frag.isReadable()) { } else if (!isComplete && frag.isReadable()) { } else if (isComplete && frag.isReadable()) { SctpMessage assembledMsg = new SctpMessage( protocolIdentifier, streamIdentifier,
protected boolean acceptInboundMessage(SctpMessage msg) { return msg.protocolIdentifier() == protocolIdentifier && msg.streamIdentifier() == streamIdentifier; }
@Override protected void decode(ChannelHandlerContext ctx, SctpMessage msg, List<Object> out) throws Exception { if (!msg.isComplete()) { throw new CodecException(String.format("Received SctpMessage is not complete, please add %s in the " + "pipeline before this handler", SctpMessageCompletionHandler.class.getSimpleName())); } out.add(msg.content().retain()); } }
@Override protected final Object filterOutboundMessage(Object msg) throws Exception { if (msg instanceof SctpMessage) { SctpMessage m = (SctpMessage) msg; ByteBuf buf = m.content(); if (buf.isDirect() && buf.nioBufferCount() == 1) { return m; } return new SctpMessage(m.protocolIdentifier(), m.streamIdentifier(), m.isUnordered(), newDirectBuffer(m, buf)); } throw new UnsupportedOperationException( "unsupported message type: " + StringUtil.simpleClassName(msg) + " (expected: " + StringUtil.simpleClassName(SctpMessage.class)); }
ByteBuf data = packet.content(); int dataLen = data.readableBytes(); ByteBuffer nioData; if (data.nioBufferCount() != -1) { nioData = data.nioBuffer(); } else { nioData = ByteBuffer.allocate(dataLen); final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier()); mi.payloadProtocolID(packet.protocolIdentifier()); mi.streamNumber(packet.streamIdentifier()); mi.unordered(packet.isUnordered());
@Override protected int doReadMessages(List<Object> buf) throws Exception { SctpChannel ch = javaChannel(); RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf buffer = allocHandle.allocate(config().getAllocator()); boolean free = true; try { ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes()); int pos = data.position(); MessageInfo messageInfo = ch.receive(data, null, notificationHandler); if (messageInfo == null) { return 0; } allocHandle.lastBytesRead(data.position() - pos); buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead()))); free = false; return 1; } catch (Throwable cause) { PlatformDependent.throwException(cause); return -1; } finally { if (free) { buffer.release(); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { // try { PayloadData payload; if (this.association.getIpChannelType() == IpChannelType.SCTP) { SctpMessage sctpMessage = (SctpMessage) msg; ByteBuf byteBuf = sctpMessage.content(); payload = new PayloadData(byteBuf.readableBytes(), byteBuf, sctpMessage.isComplete(), sctpMessage.isUnordered(), sctpMessage.protocolIdentifier(), sctpMessage.streamIdentifier()); } else { ByteBuf byteBuf = (ByteBuf) msg; payload = new PayloadData(byteBuf.readableBytes(), byteBuf, true, false, 0, 0); } if (logger.isDebugEnabled()) { logger.debug(String.format("Rx : Ass=%s %s", this.association.getName(), payload)); } this.association.read(payload); // } finally { // ReferenceCountUtil.release(msg); // } }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { out.add(new SctpMessage(protocolIdentifier, streamIdentifier, unordered, msg.retain())); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } SctpMessage sctpFrame = (SctpMessage) o; if (protocolIdentifier != sctpFrame.protocolIdentifier) { return false; } if (streamIdentifier != sctpFrame.streamIdentifier) { return false; } if (unordered != sctpFrame.unordered) { return false; } return content().equals(sctpFrame.content()); }
@Override public SctpMessage replace(ByteBuf content) { if (msgInfo == null) { return new SctpMessage(protocolIdentifier, streamIdentifier, unordered, content); } else { return new SctpMessage(msgInfo, content); } }
@Override public boolean acceptInboundMessage(Object msg) throws Exception { if (msg instanceof SctpMessage) { SctpMessage sctpMsg = (SctpMessage) msg; if (sctpMsg.isComplete()) { return true; } throw new CodecException(String.format("Received SctpMessage is not complete, please add %s in " + "the pipeline before this handler", SctpMessageCompletionHandler.class.getSimpleName())); } else { return false; } } }
@Override public String toString() { return "SctpFrame{" + "streamIdentifier=" + streamIdentifier + ", protocolIdentifier=" + protocolIdentifier + ", unordered=" + unordered + ", data=" + contentToString() + '}'; } }
ByteBuf data = packet.content(); int dataLen = data.readableBytes(); ByteBuffer nioData; if (data.nioBufferCount() != -1) { nioData = data.nioBuffer(); } else { nioData = ByteBuffer.allocate(dataLen); final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier()); mi.payloadProtocolID(packet.protocolIdentifier()); mi.streamNumber(packet.streamIdentifier()); mi.unordered(packet.isUnordered());
@Override protected int doReadMessages(List<Object> buf) throws Exception { SctpChannel ch = javaChannel(); RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf buffer = allocHandle.allocate(config().getAllocator()); boolean free = true; try { ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes()); int pos = data.position(); MessageInfo messageInfo = ch.receive(data, null, notificationHandler); if (messageInfo == null) { return 0; } allocHandle.lastBytesRead(data.position() - pos); buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead()))); free = false; return 1; } catch (Throwable cause) { PlatformDependent.throwException(cause); return -1; } finally { if (free) { buffer.release(); } } }
@Override protected void decode(ChannelHandlerContext ctx, SctpMessage msg, List<Object> out) throws Exception { if (!msg.isComplete()) { throw new CodecException(String.format("Received SctpMessage is not complete, please add %s in the " + "pipeline before this handler", SctpMessageCompletionHandler.class.getSimpleName())); } out.add(msg.content().retain()); } }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { out.add(new SctpMessage(protocolIdentifier, streamIdentifier, unordered, msg.retain())); } }
@Override protected final Object filterOutboundMessage(Object msg) throws Exception { if (msg instanceof SctpMessage) { SctpMessage m = (SctpMessage) msg; ByteBuf buf = m.content(); if (buf.isDirect() && buf.nioBufferCount() == 1) { return m; } return new SctpMessage(m.protocolIdentifier(), m.streamIdentifier(), m.isUnordered(), newDirectBuffer(m, buf)); } throw new UnsupportedOperationException( "unsupported message type: " + StringUtil.simpleClassName(msg) + " (expected: " + StringUtil.simpleClassName(SctpMessage.class)); }