src/main/java/org/beykery/jkcp/Kcp.java
public int send(ByteBuf buffer) {
        if (buffer.readableBytes() == 0) {
            return -1;
        }
        // append to previous segment in streaming mode (if possible)
        if (this.stream && !this.snd_queue.isEmpty()) {
            Segment seg = snd_queue.getLast();
            if (seg.data != null && seg.data.readableBytes() < mss) {
                int capacity = mss - seg.data.readableBytes();
                int extend = Math.min(buffer.readableBytes(), capacity);
                seg.data.writeBytes(buffer, extend);
                if (buffer.readableBytes() == 0) {
                    return 0;
                }
            }
        }
        int count;
        if (buffer.readableBytes() <= mss) {
            count = 1;
        } else {
            count = (buffer.readableBytes() + mss - 1) / mss;
        }
        if (count > 255) {
            return -2;
        }
        if (count == 0) {
            count = 1;
        }
        //fragment
        for (int i = 0; i < count; i++) {
            int size = Math.min(buffer.readableBytes(), mss);
            Segment seg = new Segment(size);
            seg.data.writeBytes(buffer, size);
            seg.frg = this.stream ? 0 : count - i - 1;
            snd_queue.add(seg);
        }
        buffer.release();
        return 0;
    }
/**
     * user/upper level send, returns below zero for error
     *
     * @param buffer
     * @return
     */
user/upper level send, returns below zero for error
@param buffer
@return
user / upper level send returns below zero for error @param buffer @return
public int send(ByteBuf buffer) {
        if (buffer.readableBytes() == 0) {
            return -1;
        }
        if (this.stream && !this.snd_queue.isEmpty()) {
            Segment seg = snd_queue.getLast();
            if (seg.data != null && seg.data.readableBytes() < mss) {
                int capacity = mss - seg.data.readableBytes();
                int extend = Math.min(buffer.readableBytes(), capacity);
                seg.data.writeBytes(buffer, extend);
                if (buffer.readableBytes() == 0) {
                    return 0;
                }
            }
        }
        int count;
        if (buffer.readableBytes() <= mss) {
            count = 1;
        } else {
            count = (buffer.readableBytes() + mss - 1) / mss;
        }
        if (count > 255) {
            return -2;
        }
        if (count == 0) {
            count = 1;
        }
        for (int i = 0; i < count; i++) {
            int size = Math.min(buffer.readableBytes(), mss);
            Segment seg = new Segment(size);
            seg.data.writeBytes(buffer, size);
            seg.frg = this.stream ? 0 : count - i - 1;
            snd_queue.add(seg);
        }
        buffer.release();
        return 0;
    }
public int send ( ByteBuf buffer ) { if ( buffer . readableBytes ( ) == 0 ) { return - 1 ; } if ( this . stream && ! this . snd_queue . isEmpty ( ) ) { Segment seg = snd_queue . getLast ( ) ; if ( seg . data != null && seg . data . readableBytes ( ) < mss ) { int capacity = mss - seg . data . readableBytes ( ) ; int extend = Math . min ( buffer . readableBytes ( ) , capacity ) ; seg . data . writeBytes ( buffer , extend ) ; if ( buffer . readableBytes ( ) == 0 ) { return 0 ; } } } int count ; if ( buffer . readableBytes ( ) <= mss ) { count = 1 ; } else { count = ( buffer . readableBytes ( ) + mss - 1 ) / mss ; } if ( count > 255 ) { return - 2 ; } if ( count == 0 ) { count = 1 ; } for ( int i = 0 ; i < count ; i ++ ) { int size = Math . min ( buffer . readableBytes ( ) , mss ) ; Segment seg = new Segment ( size ) ; seg . data . writeBytes ( buffer , size ) ; seg . frg = this . stream ? 0 : count - i - 1 ; snd_queue . add ( seg ) ; } buffer . release ( ) ; return 0 ; }
user/upper level send, returns below zero for error
 @param buffer
 @return
user / upper level send returns below zero for error @param buffer @return
// append to previous segment in streaming mode (if possible) //fragment