diff options
| author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-11 01:19:38 +0000 |
|---|---|---|
| committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-11 01:19:38 +0000 |
| commit | 8a3c9f20f6a7fa8e7e536fbd4b9897b140dd25c2 (patch) | |
| tree | 10bd664575abb2e6d4b13fc4b1e162b350842e95 | |
| parent | 6dc7f2a9992535a0079edcbfe669cceaef6aa781 (diff) | |
| parent | 5014bdb07ca3341a97003099a0f65fe6e17b4963 (diff) | |
Snap for 8710303 from 5014bdb07ca3341a97003099a0f65fe6e17b4963 to tm-d1-release
Change-Id: Icf049284b45331eda22a34de7a31b2a52d00b6e3
| -rw-r--r-- | common/device/com/android/net/module/util/FdEventsReader.java | 21 |
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 ecf8e77..4825992 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); } } |
