GP-1976: Accept only the first GADP connection

This commit is contained in:
Dan 2023-03-16 14:51:26 -04:00
parent 738e662e82
commit 9774aa9f0e
3 changed files with 28 additions and 1 deletions

View File

@ -89,7 +89,7 @@ public class GdbGadpDebuggerModelFactory extends AbstractGadpLocalDebuggerModelF
if (!existing && gdbCmdLine.size() >= 2) {
cmd.addAll(gdbCmdLine.subList(1, gdbCmdLine.size()));
}
cmd.add("--gadp-args");
cmd.add("--agent-args");
cmd.addAll(List.of("-H", host));
cmd.addAll(List.of("-p", Integer.toString(port))); // Available ephemeral port
if (!existing && gdbCmdLine.size() >= 1) {

View File

@ -61,9 +61,27 @@ public abstract class AbstractGadpServer
@Override
protected GadpClientHandler newHandler(AsynchronousSocketChannel sock) {
try {
// Accept only the first connection
closeServerSocket();
}
catch (IOException e) {
Msg.error(this, "Could not close server socket", e);
}
return new GadpClientHandler(this, sock);
}
@Override
protected void removeHandler(GadpClientHandler handler) {
super.removeHandler(handler);
try {
terminate();
}
catch (IOException e) {
Msg.error(this, "Could not terminate upon disconnect");
}
}
protected AddressRange getAddressRange(Gadp.AddressRange range) {
AddressSpace space = model.getAddressSpace(range.getSpace());
if (space == null) {

View File

@ -129,6 +129,15 @@ public abstract class AbstractAsyncServer<S extends AbstractAsyncServer<S, H>, H
}
}
/**
* Accept no more connections, but continue servicing existing connections
*
* @throws IOException if an I/O error occurs
*/
protected void closeServerSocket() throws IOException {
ssock.close();
}
protected CompletableFuture<Void> allHandlers(Function<H, CompletableFuture<?>> action) {
AsyncFence fence = new AsyncFence();
for (H h : handlers) {