1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-25 16:01:38 +03:00

extract a method

This commit is contained in:
lingming.yb
2013-12-23 17:02:52 +08:00
parent 13c06879f4
commit 35ead0f5d1

View File

@@ -107,12 +107,7 @@ public final class Connection implements Closeable {
upgradeToTls(tunnelRequest);
}
else{
// Use MTU-sized buffers to send fewer packets.
int mtu = Platform.get().getMtu(socket);
if (mtu < 1024) mtu = 1024;
if (mtu > 8192) mtu = 8192;
in = new BufferedInputStream(in, mtu);
out = new BufferedOutputStream(out, mtu);
streamWrapper();
}
}
@@ -153,13 +148,7 @@ public final class Connection implements Closeable {
out = sslSocket.getOutputStream();
in = sslSocket.getInputStream();
// Use MTU-sized buffers to send fewer packets.
int mtu = Platform.get().getMtu(socket);
if (mtu < 1024) mtu = 1024;
if (mtu > 8192) mtu = 8192;
in = new BufferedInputStream(in, mtu);
out = new BufferedOutputStream(out, mtu);
streamWrapper();
byte[] selectedProtocol;
if (useNpn && (selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null) {
@@ -340,4 +329,13 @@ public final class Connection implements Closeable {
}
}
}
private void streamWrapper(){
//Use MTU-sized buffers to send fewer packets.
int mtu = Platform.get().getMtu(socket);
if (mtu < 1024) mtu = 1024;
if (mtu > 8192) mtu = 8192;
in = new BufferedInputStream(in, mtu);
out = new BufferedOutputStream(out, mtu);
}
}