Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New Constructor with the parameter 'timeout' added to support Socket …

…Timeout value.

New methods setSocketTimeOut and getSocketTimeOut are added to set and get the socket connect timeouts respectively.
Small fix for thread synch done
  • Loading branch information...
commit 67eaccb042b53a952b35f212f9e1632f4c91ecfa 1 parent 05d75e0
Sunil Kumar authored
Showing with 88 additions and 7 deletions.
  1. +88 −7 com/novell/ldap/Connection.java
View
95 com/novell/ldap/Connection.java
@@ -19,6 +19,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
import com.novell.ldap.asn1.*;
@@ -110,6 +112,8 @@
static private LDAPSocketFactory socketFactory = null;
// The LDAPSocketFactory used for this connection
private LDAPSocketFactory mySocketFactory;
+
+ private int myTimeOut = 0;
private String host = null;
private int port = 0;
// Number of clones in addition to original LDAPConnection using this
@@ -160,7 +164,6 @@
}
return;
}
-
/**
* Copy this Connection object.
*
@@ -184,6 +187,48 @@ Object copy()
}
/**
+ * Create a new Connection object
+ *
+ * @param timeout specifies the socket timeout to be used when the server is stalled.
+ */
+
+ Connection( int timeout)
+ {
+ myTimeOut = timeout;
+
+ if( Debug.LDAP_DEBUG) {
+ synchronized(nameLock) {
+ name = "Connection(" + ++connNum + "): ";
+ }
+ Debug.trace( Debug.messages, name + "Created");
+ }
+ return;
+ }
+
+ /**
+ * Copy this Connection object.
+ *
+ * <p>This is not a true clone, but creates a new object encapsulating
+ * part of the connection information from the original object.
+ * The new object will have the same default socket factory,
+ * designated socket factory, host, port, and protocol version
+ * as the original object.
+ * The new object is NOT be connected to the host.</p>
+ *
+ * @return a shallow copy of this object
+ */
+ /* package */
+ Object copy_timeout()
+ {
+ Connection c = new Connection(this.myTimeOut);
+ c.host = this.host;
+ c.port = this.port;
+ c.protocol = this.protocol;
+ return c;
+ }
+
+
+ /**
* Acquire a simple counting semaphore that synchronizes state affecting
* bind. This method generates an ephemeral message id (negative number).
*
@@ -408,9 +453,14 @@ private void connect(String host, int port, int semaphoreId)
}
socket = mySocketFactory.createSocket(host, port);
} else {
- socket = new Socket(host, port);
+ socket = new Socket(host, port);
+ if(myTimeOut > 0)
+ {
+ socket.setSoTimeout(myTimeOut);
+ }
}
-
+
+
in = socket.getInputStream();
out = socket.getOutputStream();
} else {
@@ -418,8 +468,8 @@ private void connect(String host, int port, int semaphoreId)
Debug.trace( Debug.messages, name +
"connect(input/out Stream specified)");
}
- }
- } catch(IOException ioe) {
+ }
+ }catch(IOException ioe) {
// Unable to connect to server host:port
freeWriteSemaphore(semId);
throw new LDAPException(
@@ -617,7 +667,35 @@ void clearBindSemId()
bindSemaphoreId = 0;
return;
}
-
+
+ /**
+ * Gets SocketTimeOut value set.
+ *
+ * If not set, returns 0.
+ *
+ */
+
+ final int getSocketTimeOut()
+ {
+ return myTimeOut;
+ }
+
+ /**
+ * Sets the SocketTimeOut value.
+ *
+ */
+
+ final void setSocketTimeOut(int timeout)
+ {
+ try
+ {
+ socket.setSoTimeout(timeout);
+ myTimeOut = timeout;
+ } catch(SocketException e) {}
+ return;
+ }
+
+
/**
* checks if the writeSemaphore id used for active bind operation is clear
*/
@@ -904,7 +982,10 @@ private void shutdown( String reason, int semaphoreId, InterThreadException noti
// wait until reader threads stops completely
try {
- reader.join();
+ if (reader!= Thread.currentThread())
+ reader.join();
+
+// reader.join();
reader=null;
}
catch(InterruptedException iex) {
Please sign in to comment.
Something went wrong with that request. Please try again.