Package io.netty.channel.sctp

Examples of io.netty.channel.sctp.SctpMessage


            if (messageInfo == null) {
                return 0;
            }

            data.flip();
            buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
            free = false;
            return 1;
        } catch (Throwable cause) {
            PlatformDependent.throwException(cause);
            return -1;
View Full Code Here


        }
    }

    @Override
    protected int doWriteMessages(MessageBuf<Object> buf, boolean lastSpin) throws Exception {
        SctpMessage packet = (SctpMessage) buf.peek();
        ByteBuf data = packet.data();
        int dataLen = data.readableBytes();
        ByteBuffer nioData;
        if (data.nioBufferCount() == 1) {
            nioData = data.nioBuffer();
        } else {
            nioData = ByteBuffer.allocate(dataLen);
            data.getBytes(data.readerIndex(), nioData);
            nioData.flip();
        }

        final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier());
        mi.payloadProtocolID(packet.protocolIdentifier());
        mi.streamNumber(packet.streamIdentifier());

        final int writtenBytes = javaChannel().send(nioData, mi);

        final SelectionKey key = selectionKey();
        final int interestOps = key.interestOps();
        if (writtenBytes <= 0 && dataLen > 0) {
            // Did not write a packet.
            // 1) If 'lastSpin' is false, the caller will call this method again real soon.
            //    - Do not update OP_WRITE.
            // 2) If 'lastSpin' is true, the caller will not retry.
            //    - Set OP_WRITE so that the event loop calls flushForcibly() later.
            if (lastSpin) {
                if ((interestOps & SelectionKey.OP_WRITE) == 0) {
                    key.interestOps(interestOps | SelectionKey.OP_WRITE);
                }
            }
            return 0;
        }

        // Wrote a packet.
        buf.remove();

        // packet was written free up buffer
        packet.release();

        if (buf.isEmpty()) {
            // Wrote the outbound buffer completely - clear OP_WRITE.
            if ((interestOps & SelectionKey.OP_WRITE) != 0) {
                key.interestOps(interestOps & ~SelectionKey.OP_WRITE);
View Full Code Here

                    if (messageInfo == null) {
                        return readMessages;
                    }

                    data.flip();
                    buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
                    free = false;
                    readMessages ++;
                } catch (Throwable cause) {
                    PlatformDependent.throwException(cause);
                finally {
View Full Code Here

        }
        final int selectedKeys = writeSelector.select(SO_TIMEOUT);
        if (selectedKeys > 0) {
            final Set<SelectionKey> writableKeys = writeSelector.selectedKeys();
            for (SelectionKey ignored : writableKeys) {
                SctpMessage packet = (SctpMessage) buf.poll();
                if (packet == null) {
                    return;
                }
                try {
                    ByteBuf data = packet.data();
                    int dataLen = data.readableBytes();
                    ByteBuffer nioData;

                    if (data.nioBufferCount() != -1) {
                        nioData = data.nioBuffer();
                    } else {
                        nioData = ByteBuffer.allocate(dataLen);
                        data.getBytes(data.readerIndex(), nioData);
                        nioData.flip();
                    }

                    final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier());
                    mi.payloadProtocolID(packet.protocolIdentifier());
                    mi.streamNumber(packet.streamIdentifier());

                    ch.send(nioData, mi);
                } finally {
                    packet.release();
                }
            }
            writableKeys.clear();
        }
    }
View Full Code Here

    protected void flush(ChannelHandlerContext ctx, ByteBuf in, ChannelPromise promise) throws Exception {
        try {
            MessageBuf<Object> out = ctx.nextOutboundMessageBuffer();
            ByteBuf payload = Unpooled.buffer(in.readableBytes());
            payload.writeBytes(in);
            out.add(new SctpMessage(streamIdentifier, protocolIdentifier, payload));
        } catch (Throwable t) {
            ctx.fireExceptionCaught(new EncoderException(t));
        }

        ctx.flush(promise);
View Full Code Here

            //more message to complete
            fragments.put(streamIdentifier, Unpooled.wrappedBuffer(frag, byteBuf));
        } else if (isComplete && frag.isReadable()) {
            //last message to complete
            fragments.remove(streamIdentifier);
            SctpMessage assembledMsg = new SctpMessage(
                    protocolIdentifier,
                    streamIdentifier,
                    Unpooled.wrappedBuffer(frag, byteBuf));
            handleAssembledMessage(ctx, assembledMsg);
        } else {
View Full Code Here

        }
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        ctx.write(new SctpMessage(0, 0, firstMessage));
    }
View Full Code Here

            MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
            if (messageInfo == null) {
                return 0;
            }
            buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.position() - pos)));
            free = false;
            return 1;
        } catch (Throwable cause) {
            PlatformDependent.throwException(cause);
            return -1;
View Full Code Here

        }
    }

    @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());

        final int writtenBytes = javaChannel().send(nioData, mi);
        return writtenBytes > 0;
    }
View Full Code Here

    }

    @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(), newDirectBuffer(m, buf));
        }

        throw new UnsupportedOperationException(
                "unsupported message type: " + StringUtil.simpleClassName(msg) +
                " (expected: " + StringUtil.simpleClassName(SctpMessage.class));
View Full Code Here

TOP

Related Classes of io.netty.channel.sctp.SctpMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.