// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/core/BlinkDelivery.java
// public interface BlinkDelivery extends Disposable {
//     /**
//      * On Socket Disconnect Post CallBack
//      */
//     void postBlinkDisconnect();
// }
// 
// Path: Java/Blink/library/src/net/qiujuer/blink/core/Receiver.java
// public interface Receiver extends Disposable {
//     /**
//      * Get receive buffer size
//      *
//      * @return Buffer Size
//      */
//     int getReceiveBufferSize();
// 
//     /**
//      * Async receive same data to buffer
//      *
//      * @param e SocketAsyncEventArgs
//      * @return Status
//      */
//     boolean receiveAsync(IoEventArgs e);
// }
// 
// Path: Java/Blink/library/src/net/qiujuer/blink/core/Sender.java
// public interface Sender extends Disposable {
//     /**
//      * Get socket send buffer size
//      *
//      * @return Buffer Size
//      */
//     int getSendBufferSize();
// 
//     /**
//      * Async send same byte
//      *
//      * @param e SocketAsyncEventArgs
//      * @return Status
//      */
//     boolean sendAsync(IoEventArgs e);
// }


import net.qiujuer.blink.core.BlinkDelivery;
import net.qiujuer.blink.core.Receiver;
import net.qiujuer.blink.core.Sender;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.concurrent.atomic.AtomicBoolean;
    @Override
    public int getSendBufferSize() {
        return mBufferSize;
    }


    @Override
    public boolean receiveAsync(AsyncEventArgs buffer) {
        mReceiveArgs = buffer;
        try {
            return HandleSelector.getInstance().registerReceive(mChannel, this) != null;
        } catch (ClosedChannelException e) {
            return false;
        }
    }

    @Override
    public boolean sendAsync(AsyncEventArgs buffer) {
        mSendArgs = buffer;
        try {
            return HandleSelector.getInstance().registerSend(mChannel, this) != null;
        } catch (ClosedChannelException e) {
            return false;
        }
    }

    @Override
    public void dispose() {
        if (mDisposed.compareAndSet(false, true)) {
            HandleSelector.getInstance().unRegister(mChannel);
// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/core/BlinkDelivery.java
// public interface BlinkDelivery extends Disposable {
//     /**
//      * On Socket Disconnect Post CallBack
//      */
//     void postBlinkDisconnect();
// }
// 
// Path: Java/Blink/library/src/net/qiujuer/blink/core/Receiver.java
// public interface Receiver extends Disposable {
//     /**
//      * Get receive buffer size
//      *
//      * @return Buffer Size
//      */
//     int getReceiveBufferSize();
// 
//     /**
//      * Async receive same data to buffer
//      *
//      * @param e SocketAsyncEventArgs
//      * @return Status
//      */
//     boolean receiveAsync(IoEventArgs e);
// }
// 
// Path: Java/Blink/library/src/net/qiujuer/blink/core/Sender.java
// public interface Sender extends Disposable {
//     /**
//      * Get socket send buffer size
//      *
//      * @return Buffer Size
//      */
//     int getSendBufferSize();
// 
//     /**
//      * Async send same byte
//      *
//      * @param e SocketAsyncEventArgs
//      * @return Status
//      */
//     boolean sendAsync(IoEventArgs e);
// }


// Path: Android/Blink/library/src/main/java/net/qiujuer/blink/async/AsyncSocketAdapter.java
import net.qiujuer.blink.core.BlinkDelivery;
import net.qiujuer.blink.core.Receiver;
import net.qiujuer.blink.core.Sender;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.concurrent.atomic.AtomicBoolean;

    @Override
    public int getSendBufferSize() {
        return mBufferSize;
    }


    @Override
    public boolean receiveAsync(AsyncEventArgs buffer) {
        mReceiveArgs = buffer;
        try {
            return HandleSelector.getInstance().registerReceive(mChannel, this) != null;
        } catch (ClosedChannelException e) {
            return false;
        }
    }

    @Override
    public boolean sendAsync(AsyncEventArgs buffer) {
        mSendArgs = buffer;
        try {
            return HandleSelector.getInstance().registerSend(mChannel, this) != null;
        } catch (ClosedChannelException e) {
            return false;
        }
    }

    @Override
    public void dispose() {
        if (mDisposed.compareAndSet(false, true)) {
            HandleSelector.getInstance().unRegister(mChannel);
            mSendArgs = null;