cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [2/2] git commit: updated refs/heads/master to 8a13f44
Date Thu, 18 Sep 2014 14:03:31 GMT
Fix a stupid bug i introduced


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d1d8009c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d1d8009c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d1d8009c

Branch: refs/heads/master
Commit: d1d8009c68fd870598cf0db2de4d2cb6b47edc72
Parents: 4e07dd1
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Thu Sep 18 12:37:35 2014 +0200
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Thu Sep 18 16:02:26 2014 +0200

----------------------------------------------------------------------
 utils/src/com/cloud/utils/nio/NioClient.java | 35 ++++++++++++++++-------
 1 file changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1d8009c/utils/src/com/cloud/utils/nio/NioClient.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/nio/NioClient.java b/utils/src/com/cloud/utils/nio/NioClient.java
index f4b1029..5b00105 100755
--- a/utils/src/com/cloud/utils/nio/NioClient.java
+++ b/utils/src/com/cloud/utils/nio/NioClient.java
@@ -36,6 +36,7 @@ public class NioClient extends NioConnection {
 
     protected String _host;
     protected String _bindAddress;
+    protected SocketChannel _clientConnection;
 
     public NioClient(String name, String host, int port, int workers, HandlerFactory factory)
{
         super(name, port, workers, factory);
@@ -51,47 +52,50 @@ public class NioClient extends NioConnection {
         _selector = Selector.open();
         Task task = null;
 
-        try (SocketChannel sch = SocketChannel.open()) {
-            sch.configureBlocking(true);
+        try {
+            _clientConnection = SocketChannel.open();
+            _clientConnection.configureBlocking(true);
             s_logger.info("Connecting to " + _host + ":" + _port);
 
             if (_bindAddress != null) {
                 s_logger.info("Binding outbound interface at " + _bindAddress);
 
                 InetSocketAddress bindAddr = new InetSocketAddress(_bindAddress, 0);
-                sch.socket().bind(bindAddr);
+                _clientConnection.socket().bind(bindAddr);
             }
 
             InetSocketAddress peerAddr = new InetSocketAddress(_host, _port);
-            sch.connect(peerAddr);
+            _clientConnection.connect(peerAddr);
 
             SSLEngine sslEngine = null;
             // Begin SSL handshake in BLOCKING mode
-            sch.configureBlocking(true);
+            _clientConnection.configureBlocking(true);
 
             SSLContext sslContext = Link.initSSLContext(true);
             sslEngine = sslContext.createSSLEngine(_host, _port);
             sslEngine.setUseClientMode(true);
 
-            Link.doHandshake(sch, sslEngine, true);
+            Link.doHandshake(_clientConnection, sslEngine, true);
             s_logger.info("SSL: Handshake done");
             s_logger.info("Connected to " + _host + ":" + _port);
 
-
-            sch.configureBlocking(false);
+            _clientConnection.configureBlocking(false);
             Link link = new Link(peerAddr, this);
             link.setSSLEngine(sslEngine);
-            SelectionKey key = sch.register(_selector, SelectionKey.OP_READ);
+            SelectionKey key = _clientConnection.register(_selector, SelectionKey.OP_READ);
             link.setKey(key);
             key.attach(link);
             // Notice we've already connected due to the handshake, so let's get the
             // remaining task done
             task = _factory.create(Task.Type.CONNECT, link, null);
         } catch (GeneralSecurityException e) {
+            _selector.close();
             throw new IOException("Failed to initialise security", e);
-        } finally {
+        } catch (IOException e) {
             _selector.close();
+            throw e;
         }
+
         _executor.execute(task);
     }
 
@@ -104,4 +108,15 @@ public class NioClient extends NioConnection {
     protected void unregisterLink(InetSocketAddress saddr) {
         // don't do anything.
     }
+
+    @Override
+    public void cleanUp() throws IOException {
+        super.cleanUp();
+        if (_clientConnection != null) {
+            _clientConnection.close();
+        }
+        s_logger.info("NioClient connection closed");
+
+    }
+
 }


Mime
View raw message