db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r481574 - /db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Date Sat, 02 Dec 2006 16:14:48 GMT
Author: djd
Date: Sat Dec  2 08:14:48 2006
New Revision: 481574

URL: http://svn.apache.org/viewvc?view=rev&rev=481574
Log:
DERBY-1965 Ensure sockets opened by NetworkServerControlImpl are explicitly closed.

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?view=diff&rev=481574&r1=481573&r2=481574
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Sat Dec  2 08:14:48 2006
@@ -794,6 +794,7 @@
 		writeCommandHeader(COMMAND_SHUTDOWN);
 		send();
 		readResult();
+        closeSocket();
 		// Wait up to 10 seconds for things to really shut down
 		// need a quiet ping so temporarily disable the logwriter
 		PrintWriter savWriter = logWriter;
@@ -869,6 +870,7 @@
 			writeLDString(password);
 			send();
 			readResult();
+            closeSocket();
 
 	}
 
@@ -904,6 +906,7 @@
 		send();
 		readResult();
 		consoleTraceMessage(connNum, on);
+        closeSocket();
 	}
 
 	/**
@@ -943,6 +946,7 @@
 		writeByte(on ? 1 : 0);
 		send();
 		readResult();
+        closeSocket();
 	}
 
 	/**
@@ -956,6 +960,7 @@
 		writeLDString(traceDirectory);
 		send();
 		readResult();
+        closeSocket();
 	}
 
 	/**
@@ -964,10 +969,14 @@
 	public String sysinfo()
 		throws Exception
 	{
-		setUpSocket();
-		writeCommandHeader(COMMAND_SYSINFO);
-		send();
-		return readStringReply("DRDA_SysInfoError.S");
+		try {
+            setUpSocket();
+            writeCommandHeader(COMMAND_SYSINFO);
+            send();
+            return readStringReply("DRDA_SysInfoError.S");
+        } finally {
+            closeSocket();
+        }
 	}
 
 	/**
@@ -976,10 +985,14 @@
 	public String runtimeInfo()
 	throws Exception 
 	{
-		setUpSocket();
-		writeCommandHeader(COMMAND_RUNTIME_INFO);
-		send();
-		return readStringReply("DRDA_RuntimeInfoError.S");
+		try {
+            setUpSocket();
+            writeCommandHeader(COMMAND_RUNTIME_INFO);
+            send();
+            return readStringReply("DRDA_RuntimeInfoError.S");
+        } finally {
+            closeSocket();
+        }
 	}
 
 	/**
@@ -1013,6 +1026,7 @@
 		int newval = readInt();
 		consolePropertyMessage("DRDA_MaxThreadsChange.I", 
  					new Integer(newval).toString());
+        closeSocket();
 	}
 
 	/**
@@ -1034,6 +1048,7 @@
 		int newval = readInt();
 		consolePropertyMessage("DRDA_TimeSliceChange.I", 
 									   new Integer(newval).toString());
+        closeSocket();
 	}
 
 	/**
@@ -1049,6 +1064,7 @@
 		writeCommandHeader(COMMAND_PROPERTIES);
 		send();
 		byte [] val = readBytesReply("DRDA_PropertyError.S");
+        closeSocket();
 		Properties p = new Properties();
 		try {
 			ByteArrayInputStream bs = new ByteArrayInputStream(val);
@@ -2046,6 +2062,26 @@
 			consolePropertyMessage("DRDA_OnOffValue.U", arg);
 		return false;
 	}
+    
+    /**
+     * Close the resources associated with the opened socket.
+     * @throws IOException
+     */
+    private void closeSocket() throws IOException
+    {
+        try {
+            if (clientIs != null)
+                clientIs.close();
+            if (clientOs != null)
+                clientOs.close();
+            if (clientSocket != null)
+                clientSocket.close();
+        } finally {
+            clientIs = null;
+            clientOs = null;
+            clientSocket = null;
+        }
+    }
 
 	/**
 	 * Set up client socket to send a command to the network server



Mime
View raw message