+ xfree(h);
+}
+
+static void do_close(association *a, int reason, char *message)
+{
+ Z_APDU apdu;
+ Z_Close *cls = zget_Close(a->encode);
+ request *req = request_get();
+
+ /* Purge request queue */
+ while (request_deq(&a->incoming));
+ while (request_deq(&a->outgoing));
+ if (a->version >= 3)
+ {
+ logf(LOG_LOG, "Sending Close PDU, reason=%d, message=%s",
+ reason, message ? message : "none");
+ apdu.which = Z_APDU_close;
+ apdu.u.close = cls;
+ *cls->closeReason = reason;
+ cls->diagnosticInformation = message;
+ process_response(a, req, &apdu);
+ iochan_settimeout(a->client_chan, 60);
+ }
+ else
+ {
+ logf(LOG_DEBUG, "v2 client. No Close PDU");
+ iochan_setevent(a->client_chan, EVENT_TIMEOUT); /* force imm close */
+ }
+ a->state = ASSOC_DEAD;