From bc825f37f327005ce417c8bda658b591e5bca35a Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Tue, 13 Mar 2007 21:01:59 +0000
Subject: [PATCH] Update the LDAPConnection object and the classes that use it to ensure that it can perform an unbind before closing the connection.

---
 opends/src/server/org/opends/server/tools/LDAPConnection.java |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/LDAPConnection.java b/opends/src/server/org/opends/server/tools/LDAPConnection.java
index c5cd8c8..738f174 100644
--- a/opends/src/server/org/opends/server/tools/LDAPConnection.java
+++ b/opends/src/server/org/opends/server/tools/LDAPConnection.java
@@ -45,6 +45,7 @@
 import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
 import org.opends.server.protocols.ldap.LDAPControl;
 import org.opends.server.protocols.ldap.LDAPMessage;
+import org.opends.server.protocols.ldap.UnbindRequestProtocolOp;
 import org.opends.server.types.Control;
 import org.opends.server.types.DebugLogLevel;
 
@@ -418,13 +419,28 @@
   }
 
   /**
-   * Close the underlying ASN1 reader and writer.
+   * Close the underlying ASN1 reader and writer, optionally sending an unbind
+   * request before disconnecting.
    *
+   * @param  nextMessageID  The message ID counter that should be used for
+   *                        the unbind request, or {@code null} if the
+   *                        connection should be closed without an unbind
+   *                        request.
    */
-  public void close()
+  public void close(AtomicInteger nextMessageID)
   {
     if(asn1Writer != null)
     {
+      if (nextMessageID != null)
+      {
+        try
+        {
+          LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(),
+                                                new UnbindRequestProtocolOp());
+          asn1Writer.writeElement(message.encode());
+        } catch (Exception e) {}
+      }
+
       asn1Writer.close();
     }
     if(asn1Reader != null)

--
Gitblit v1.10.0