From 13c06879f4e98c86436bdca765046ef815e34838 Mon Sep 17 00:00:00 2001 From: "lingming.yb" Date: Sun, 22 Dec 2013 11:22:12 +0800 Subject: [PATCH] Buffered Stream wrapper should be taken place before SpdyConnection build. --- .../java/com/squareup/okhttp/Connection.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/okhttp/src/main/java/com/squareup/okhttp/Connection.java b/okhttp/src/main/java/com/squareup/okhttp/Connection.java index a6b798da9..95a644311 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/Connection.java +++ b/okhttp/src/main/java/com/squareup/okhttp/Connection.java @@ -106,13 +106,14 @@ public final class Connection implements Closeable { if (route.address.sslSocketFactory != null) { upgradeToTls(tunnelRequest); } - - // 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); + 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); + } } /** @@ -152,6 +153,13 @@ 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); byte[] selectedProtocol; if (useNpn && (selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null) {