From 42e19382d28d06eda0ffbcda01fbfed5c3538dd8 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 19 Jul 2013 10:47:56 -0400
Subject: [PATCH] Merge pull request #98 from simonharrer/close-resources-correctly
---
src/main/java/com/gitblit/git/GitDaemon.java | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/gitblit/git/GitDaemon.java b/src/main/java/com/gitblit/git/GitDaemon.java
index 7050f87..b760fbc 100644
--- a/src/main/java/com/gitblit/git/GitDaemon.java
+++ b/src/main/java/com/gitblit/git/GitDaemon.java
@@ -177,6 +177,20 @@
}
} };
}
+
+ public int getPort() {
+ return myAddress.getPort();
+ }
+
+ public String formatUrl(String servername, String repository) {
+ if (getPort() == 9418) {
+ // standard port
+ return MessageFormat.format("git://{0}/{1}", servername, repository);
+ } else {
+ // non-standard port
+ return MessageFormat.format("git://{0}:{1,number,0}/{2}", servername, getPort(), repository);
+ }
+ }
/** @return timeout (in seconds) before aborting an IO operation. */
public int getTimeout() {
@@ -231,8 +245,8 @@
//
} finally {
acceptSocket = null;
- acceptThread = null;
}
+
}
};
acceptThread.start();
@@ -247,9 +261,9 @@
/** Stop this daemon. */
public synchronized void stop() {
- if (acceptThread != null) {
- logger.info("Git Daemon stopping...");
+ if (isRunning() && acceptThread != null) {
run.set(false);
+ logger.info("Git Daemon stopping...");
try {
// close the accept socket
// this throws a SocketException in the accept thread
@@ -262,6 +276,8 @@
logger.info("Git Daemon stopped.");
} catch (InterruptedException e) {
logger.error("Accept thread join interrupted", e);
+ } finally {
+ acceptThread = null;
}
}
}
--
Gitblit v1.9.1