예제 #1
0
  @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) {
      nioData = data.nioBuffer();
    } else {
      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;
  }
예제 #2
0
 @Override
 public long transferTo(SctpChannel ch) throws IOException {
   final MessageInfo messageInfo = MessageInfo.createOutgoing(ch.association(), null, streamNo);
   messageInfo.payloadProtocolID(protocolId);
   messageInfo.streamNumber(streamNo);
   ch.send(buffer, messageInfo);
   return writtenBytes();
 }
예제 #3
0
 /**
  * Essential data that is being carried within SCTP Data Chunk
  *
  * @param msgInfo the {@link MessageInfo}
  * @param payloadBuffer channel buffer
  */
 public SctpMessage(MessageInfo msgInfo, ByteBuf payloadBuffer) {
   super(payloadBuffer);
   if (msgInfo == null) {
     throw new NullPointerException("msgInfo");
   }
   this.msgInfo = msgInfo;
   streamIdentifier = msgInfo.streamNumber();
   protocolIdentifier = msgInfo.payloadProtocolID();
   unordered = msgInfo.isUnordered();
 }