From 6049ffd43fecdac617243e25560a2cbbd9330866 Mon Sep 17 00:00:00 2001 From: "lingming.yb" Date: Thu, 9 Jan 2014 11:10:39 +0800 Subject: [PATCH] Connected after everything is initialized (cherry picked from commit ed2ee02570bac36b89bd93836e200840cb8fa59d) Conflicts: okhttp/src/main/java/com/squareup/okhttp/Connection.java --- okhttp/src/main/java/com/squareup/okhttp/Connection.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/okhttp/src/main/java/com/squareup/okhttp/Connection.java b/okhttp/src/main/java/com/squareup/okhttp/Connection.java index a46bb31a8..6bb9cb3a9 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/Connection.java +++ b/okhttp/src/main/java/com/squareup/okhttp/Connection.java @@ -93,10 +93,8 @@ public final class Connection implements Closeable { public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest) throws IOException { - if (connected) { - throw new IllegalStateException("already connected"); - } - connected = true; + if (connected) throw new IllegalStateException("already connected"); + socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket(); Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout); socket.setSoTimeout(readTimeout); @@ -108,6 +106,7 @@ public final class Connection implements Closeable { } else { streamWrapper(); } + connected = true; } /**