Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a838a68 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Move FdEventsReader to the shared area."

parents f89a1cfd 0bf364d9
Loading
Loading
Loading
Loading
+18 −6
Original line number Original line Diff line number Diff line
@@ -14,10 +14,10 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


package android.net.util;
package android.net.shared;


import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_INPUT;
import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_ERROR;
import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_ERROR;
import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_INPUT;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -63,6 +63,7 @@ import java.io.FileDescriptor;
 * All public methods MUST only be called from the same thread with which
 * All public methods MUST only be called from the same thread with which
 * the Handler constructor argument is associated.
 * the Handler constructor argument is associated.
 *
 *
 * @param <BufferType> the type of the buffer used to read data.
 * @hide
 * @hide
 */
 */
public abstract class FdEventsReader<BufferType> {
public abstract class FdEventsReader<BufferType> {
@@ -89,6 +90,7 @@ public abstract class FdEventsReader<BufferType> {
        mBuffer = buffer;
        mBuffer = buffer;
    }
    }


    /** Start this FdEventsReader. */
    public void start() {
    public void start() {
        if (onCorrectThread()) {
        if (onCorrectThread()) {
            createAndRegisterFd();
            createAndRegisterFd();
@@ -100,6 +102,7 @@ public abstract class FdEventsReader<BufferType> {
        }
        }
    }
    }


    /** Stop this FdEventsReader and destroy the file descriptor. */
    public void stop() {
    public void stop() {
        if (onCorrectThread()) {
        if (onCorrectThread()) {
            unregisterAndDestroyFd();
            unregisterAndDestroyFd();
@@ -112,18 +115,25 @@ public abstract class FdEventsReader<BufferType> {
    }
    }


    @NonNull
    @NonNull
    public Handler getHandler() { return mHandler; }
    public Handler getHandler() {
        return mHandler;
    }


    protected abstract int recvBufSize(@NonNull BufferType buffer);
    protected abstract int recvBufSize(@NonNull BufferType buffer);


    public int recvBufSize() { return recvBufSize(mBuffer); }
    /** Returns the size of the receive buffer. */
    public int recvBufSize() {
        return recvBufSize(mBuffer);
    }


    /**
    /**
     * Get the number of successful calls to {@link #readPacket(FileDescriptor, Object)}.
     * Get the number of successful calls to {@link #readPacket(FileDescriptor, Object)}.
     *
     *
     * <p>A call was successful if {@link #readPacket(FileDescriptor, Object)} returned a value > 0.
     * <p>A call was successful if {@link #readPacket(FileDescriptor, Object)} returned a value > 0.
     */
     */
    public final long numPacketsReceived() { return mPacketsReceived; }
    public final long numPacketsReceived() {
        return mPacketsReceived;
    }


    /**
    /**
     * Subclasses MUST create the listening socket here, including setting
     * Subclasses MUST create the listening socket here, including setting
@@ -199,7 +209,9 @@ public abstract class FdEventsReader<BufferType> {
        onStart();
        onStart();
    }
    }


    private boolean isRunning() { return (mFd != null) && mFd.valid(); }
    private boolean isRunning() {
        return (mFd != null) && mFd.valid();
    }


    // Keep trying to read until we get EAGAIN/EWOULDBLOCK or some fatal error.
    // Keep trying to read until we get EAGAIN/EWOULDBLOCK or some fatal error.
    private boolean handleInput() {
    private boolean handleInput() {
+1 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ package android.net.dhcp;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.net.util.FdEventsReader;
import android.net.shared.FdEventsReader;
import android.os.Handler;
import android.os.Handler;
import android.system.Os;
import android.system.Os;


+1 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net.util;


import static java.lang.Math.max;
import static java.lang.Math.max;


import android.net.shared.FdEventsReader;
import android.os.Handler;
import android.os.Handler;
import android.system.Os;
import android.system.Os;