Merge "Return not supported if no necessary socket option"
This commit is contained in:
@@ -16,10 +16,12 @@
|
|||||||
package com.android.server.connectivity;
|
package com.android.server.connectivity;
|
||||||
|
|
||||||
import static android.net.SocketKeepalive.DATA_RECEIVED;
|
import static android.net.SocketKeepalive.DATA_RECEIVED;
|
||||||
|
import static android.net.SocketKeepalive.ERROR_HARDWARE_UNSUPPORTED;
|
||||||
import static android.net.SocketKeepalive.ERROR_INVALID_SOCKET;
|
import static android.net.SocketKeepalive.ERROR_INVALID_SOCKET;
|
||||||
import static android.net.SocketKeepalive.ERROR_SOCKET_NOT_IDLE;
|
import static android.net.SocketKeepalive.ERROR_SOCKET_NOT_IDLE;
|
||||||
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 static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_INPUT;
|
||||||
|
import static android.system.OsConstants.ENOPROTOOPT;
|
||||||
import static android.system.OsConstants.FIONREAD;
|
import static android.system.OsConstants.FIONREAD;
|
||||||
import static android.system.OsConstants.IPPROTO_TCP;
|
import static android.system.OsConstants.IPPROTO_TCP;
|
||||||
import static android.system.OsConstants.TIOCOUTQ;
|
import static android.system.OsConstants.TIOCOUTQ;
|
||||||
@@ -179,12 +181,13 @@ public class TcpKeepaliveController {
|
|||||||
trw = NetworkUtils.getTcpRepairWindow(fd);
|
trw = NetworkUtils.getTcpRepairWindow(fd);
|
||||||
} catch (ErrnoException e) {
|
} catch (ErrnoException e) {
|
||||||
Log.e(TAG, "Exception reading TCP state from socket", e);
|
Log.e(TAG, "Exception reading TCP state from socket", e);
|
||||||
try {
|
if (e.errno == ENOPROTOOPT) {
|
||||||
Os.setsockoptInt(fd, IPPROTO_TCP, TCP_REPAIR, TCP_REPAIR_OFF);
|
// ENOPROTOOPT may happen in kernel version lower than 4.8.
|
||||||
} catch (ErrnoException ex) {
|
// Treat it as ERROR_HARDWARE_UNSUPPORTED.
|
||||||
Log.e(TAG, "Exception while turning off repair mode due to exception", ex);
|
throw new InvalidSocketException(ERROR_HARDWARE_UNSUPPORTED, e);
|
||||||
}
|
} else {
|
||||||
throw new InvalidSocketException(ERROR_INVALID_SOCKET, e);
|
throw new InvalidSocketException(ERROR_INVALID_SOCKET, e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
dropAllIncomingPackets(fd, false);
|
dropAllIncomingPackets(fd, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user