提交 e3269650 authored 作者: Thomas Mueller's avatar Thomas Mueller

Can now start a TCP server with port 0 (automatically select a port).

上级 ad836b86
......@@ -75,4 +75,12 @@ public interface Service {
* @return the type
*/
String getType();
/**
* Gets the port this service is listening on.
*
* @return the port
*/
int getPort();
}
......@@ -64,7 +64,6 @@ public class TcpServer implements Service {
private ServerSocket serverSocket;
private Set running = Collections.synchronizedSet(new HashSet());
private String baseDir;
private String url;
private boolean allowOthers;
private boolean ifExists;
private Connection managementDb;
......@@ -187,11 +186,14 @@ public class TcpServer implements Service {
}
}
org.h2.Driver.load();
url = (ssl ? "ssl" : "tcp") + "://" + NetUtils.getLocalAddress() + ":" + port;
}
public String getURL() {
return url;
return (ssl ? "ssl" : "tcp") + "://" + NetUtils.getLocalAddress() + ":" + port;
}
public int getPort() {
return port;
}
/**
......@@ -210,6 +212,7 @@ public class TcpServer implements Service {
public synchronized void start() throws SQLException {
serverSocket = NetUtils.createServerSocket(port, ssl);
port = serverSocket.getLocalPort();
initManagementDb();
}
......
......@@ -247,11 +247,16 @@ public class FtpServer implements Service {
return "ftp://" + NetUtils.getLocalAddress() + ":" + port;
}
public int getPort() {
return port;
}
public void start() throws SQLException {
fs = FileSystem.getInstance(root);
root = fs.normalize(root);
fs.mkdirs(root);
serverSocket = NetUtils.createServerSocket(port, false);
port = serverSocket.getLocalPort();
}
public void stop() {
......
......@@ -43,7 +43,6 @@ public class PgServer implements Service {
private ServerSocket serverSocket;
private Set running = Collections.synchronizedSet(new HashSet());
private String baseDir;
private String url;
private boolean allowOthers;
private boolean ifExists;
......@@ -77,8 +76,6 @@ public class PgServer implements Service {
}
}
org.h2.Driver.load();
url = "pg://" + NetUtils.getLocalAddress() + ":" + port;
// int testing;
// log = true;
}
......@@ -119,7 +116,11 @@ public class PgServer implements Service {
}
public String getURL() {
return url;
return "pg://" + NetUtils.getLocalAddress() + ":" + port;
}
public int getPort() {
return port;
}
private boolean allow(Socket socket) {
......
......@@ -464,7 +464,7 @@ public class WebServer implements Service {
return ssl;
}
int getPort() {
public int getPort() {
return port;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论