Explicitly disable socket keep-alive

pull/184/head
M66B 5 years ago
parent cff6d1a8a2
commit 0cd4903f70

@ -38,6 +38,7 @@ import java.net.InetAddress;
import java.net.InterfaceAddress; import java.net.InterfaceAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.KeyStore; import java.security.KeyStore;
@ -738,8 +739,8 @@ public class EmailService implements AutoCloseable {
return configure(factory.createSocket(address, port, localAddress, localPort)); return configure(factory.createSocket(address, port, localAddress, localPort));
} }
private Socket configure(Socket socket) { private Socket configure(Socket socket) throws SocketException {
Log.i("Socket type=" + socket.getClass()); configureSocketOptions(socket);
return socket; return socket;
} }
} }
@ -878,7 +879,9 @@ public class EmailService implements AutoCloseable {
throw new IOException("createSocket"); throw new IOException("createSocket");
} }
private Socket configure(Socket socket) { private Socket configure(Socket socket) throws SocketException {
configureSocketOptions(socket);
if (socket instanceof SSLSocket) { if (socket instanceof SSLSocket) {
SSLSocket sslSocket = (SSLSocket) socket; SSLSocket sslSocket = (SSLSocket) socket;
@ -1021,6 +1024,18 @@ public class EmailService implements AutoCloseable {
} }
} }
private static void configureSocketOptions(Socket socket) throws SocketException {
Log.i("Socket type=" + socket.getClass() +
" timeout=" + socket.getSoTimeout() +
" linger=" + socket.getSoLinger() +
" keepalive=" + socket.getKeepAlive());
if (socket.getKeepAlive()) {
Log.e("Socket keep-alive");
socket.setKeepAlive(false);
}
}
class UntrustedException extends MessagingException { class UntrustedException extends MessagingException {
private String fingerprint; private String fingerprint;

Loading…
Cancel
Save