// 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;
/*
 * Copyright (C) 2014 Qiujuer <qiujuer@live.cn>
 * WebSite http://www.qiujuer.net
 * Created 04/16/2015
 * Changed 04/19/2015
 * Version 1.0.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.qiujuer.blink.async;



/**
 * Async socket adapter to send and receive byte
 */
public class AsyncSocketAdapter implements Sender, Receiver, HandleSelector.HandleCallback {
    private int mBufferSize;
    private AsyncEventArgs mSendArgs;
    private AsyncEventArgs mReceiveArgs;
    private SocketChannel mChannel;
    // Is Disposed
    protected final AtomicBoolean mDisposed = new AtomicBoolean(false);
    // Posting responses.
// 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;

/*
 * Copyright (C) 2014 Qiujuer <qiujuer@live.cn>
 * WebSite http://www.qiujuer.net
 * Created 04/16/2015
 * Changed 04/19/2015
 * Version 1.0.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.qiujuer.blink.async;



/**
 * Async socket adapter to send and receive byte
 */
public class AsyncSocketAdapter implements Sender, Receiver, HandleSelector.HandleCallback {
    private int mBufferSize;
    private AsyncEventArgs mSendArgs;
    private AsyncEventArgs mReceiveArgs;
    private SocketChannel mChannel;
    // Is Disposed
    protected final AtomicBoolean mDisposed = new AtomicBoolean(false);
    // Posting responses.
    private BlinkDelivery mBlinkDelivery;