package com.jscape.util.net.connection;

/**
 * @author Alex Usun
 */
public interface AsyncRawConnection
        extends RawConnection {

    void start(Listener listener)
            throws ConnectionException;

    interface Listener {

        Listener NULL = new Listener() {
            @Override
            public void onData(AsyncRawConnection connection, byte[] data, int offset, int length) {
            }

            @Override
            public void onEof(AsyncRawConnection connection) {
            }

            @Override
            public void onError(AsyncRawConnection connection, Throwable error) {
            }

            @Override
            public void onClosed(AsyncRawConnection connection) {
            }

            @Override
            public void onIdle(AsyncRawConnection connection) {
            }
        };

        void onData(AsyncRawConnection connection, byte[] data, int offset, int length);

        void onEof(AsyncRawConnection connection);

        void onError(AsyncRawConnection connection, Throwable error);

        void onClosed(AsyncRawConnection connection);

        void onIdle(AsyncRawConnection connection);
    }

}
