summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Ma <xiaom@google.com>2022-06-10 04:07:45 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-06-10 04:07:45 +0000
commit5014bdb07ca3341a97003099a0f65fe6e17b4963 (patch)
tree10bd664575abb2e6d4b13fc4b1e162b350842e95
parenta42ee4d17cdde71b65456d3569ed0004aebc34af (diff)
parentbecbc679e655085454efc9a16fddf665773433cb (diff)
downloadnet-5014bdb07ca3341a97003099a0f65fe6e17b4963.tar.gz
Add handlePacketReadError method in FdEventsReader. am: becbc679e6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/libs/net/+/18815967 Change-Id: Ic2a3aea66ad4c7e2c4c33c63a39ad81bd9e2780c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--common/device/com/android/net/module/util/FdEventsReader.java21
1 files changed, 18 insertions, 3 deletions
diff --git a/common/device/com/android/net/module/util/FdEventsReader.java b/common/device/com/android/net/module/util/FdEventsReader.java
index ecf8e77c..4825992f 100644
--- a/common/device/com/android/net/module/util/FdEventsReader.java
+++ b/common/device/com/android/net/module/util/FdEventsReader.java
@@ -69,6 +69,7 @@ import java.io.IOException;
* @param <BufferType> the type of the buffer used to read data.
*/
public abstract class FdEventsReader<BufferType> {
+ private static final String TAG = FdEventsReader.class.getSimpleName();
private static final int FD_EVENTS = EVENT_INPUT | EVENT_ERROR;
private static final int UNREGISTER_THIS_FD = 0;
@@ -167,6 +168,18 @@ public abstract class FdEventsReader<BufferType> {
protected void handlePacket(@NonNull BufferType recvbuf, int length) {}
/**
+ * Called by the subclasses of FdEventsReader, decide whether it should stop reading packet or
+ * just ignore the specific error other than EAGAIN or EINTR.
+ *
+ * @return {@code true} if this FdEventsReader should stop reading from the socket.
+ * {@code false} if it should continue.
+ */
+ protected boolean handleReadError(@NonNull ErrnoException e) {
+ logError("readPacket error: ", e);
+ return true; // by default, stop reading on any error.
+ }
+
+ /**
* Called by the main loop to log errors. In some cases |e| may be null.
*/
protected void logError(@NonNull String msg, @Nullable Exception e) {}
@@ -234,8 +247,10 @@ public abstract class FdEventsReader<BufferType> {
} else if (e.errno == OsConstants.EINTR) {
continue;
} else {
- if (isRunning()) logError("readPacket error: ", e);
- break;
+ if (!isRunning()) break;
+ final boolean shouldStop = handleReadError(e);
+ if (shouldStop) break;
+ continue;
}
} catch (Exception e) {
if (isRunning()) logError("readPacket error: ", e);
@@ -246,7 +261,7 @@ public abstract class FdEventsReader<BufferType> {
handlePacket(mBuffer, bytesRead);
} catch (Exception e) {
logError("handlePacket error: ", e);
- Log.wtf(FdEventsReader.class.getSimpleName(), "Error handling packet", e);
+ Log.wtf(TAG, "Error handling packet", e);
}
}