Merge "Improve keepalive offload documentation and error handling" am: a0b880c9e8 am: 4a91c73e67

am: a820236f47

Change-Id: If13af1a50c9bb12c85559c9c7a83d0e861d76d09
This commit is contained in:
Junyu Lai
2019-03-11 22:40:00 -07:00
committed by android-build-merger
3 changed files with 17 additions and 9 deletions

View File

@@ -239,7 +239,12 @@ public class KeepaliveTracker {
.sendMessage(CMD_START_SOCKET_KEEPALIVE, slot, mInterval, mPacket);
break;
case TYPE_TCP:
mTcpController.startSocketMonitor(mFd, this, mSlot);
try {
mTcpController.startSocketMonitor(mFd, this, mSlot);
} catch (InvalidSocketException e) {
handleStopKeepalive(mNai, mSlot, ERROR_INVALID_SOCKET);
return;
}
mNai.asyncChannel
.sendMessage(CMD_ADD_KEEPALIVE_PACKET_FILTER, slot, 0 /* Unused */,
mPacket);

View File

@@ -215,18 +215,20 @@ public class TcpKeepaliveController {
* Start monitoring incoming packets.
*
* @param fd socket fd to monitor.
* @param messenger a callback to notify socket status.
* @param ki a {@link KeepaliveInfo} that tracks information about a socket keepalive.
* @param slot keepalive slot.
*/
public void startSocketMonitor(@NonNull final FileDescriptor fd,
@NonNull final KeepaliveInfo ki, final int slot) {
@NonNull final KeepaliveInfo ki, final int slot)
throws IllegalArgumentException, InvalidSocketException {
synchronized (mListeners) {
if (null != mListeners.get(slot)) {
throw new IllegalArgumentException("This slot is already taken");
}
for (int i = 0; i < mListeners.size(); ++i) {
if (fd.equals(mListeners.valueAt(i))) {
throw new IllegalArgumentException("This fd is already registered");
Log.e(TAG, "This fd is already registered.");
throw new InvalidSocketException(ERROR_INVALID_SOCKET);
}
}
mFdHandlerQueue.addOnFileDescriptorEventListener(fd, FD_EVENTS, (readyFd, events) -> {