Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add trivial implementation of ServerConnector#close #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/src/main/java/net/luminis/quic/QuicConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import java.time.Duration;
import java.util.function.Consumer;


public interface QuicConnection {
public interface QuicConnection extends AutoCloseable {

enum QuicVersion {
V1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public void registerAdditionalConnectionId(byte[] currentConnectionId, byte[] ne

@Override
public void deregisterConnectionId(byte[] connectionId) {}

@Override
public void close() {}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import net.luminis.quic.server.impl.ServerConnectionProxy;

public interface ServerConnectionRegistry {
public interface ServerConnectionRegistry extends AutoCloseable {

void registerConnection(ServerConnectionProxy connection, byte[] connectionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Listens for QUIC connections on a given port. Requires server certificate and corresponding private key.
*/
public interface ServerConnector {
public interface ServerConnector extends AutoCloseable {

void registerApplicationProtocol(String protocol, ApplicationProtocolConnectionFactory protocolConnectionFactory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.nio.ByteBuffer;
import java.time.Instant;


public interface ServerConnectionProxy {

byte[] getOriginalDestinationConnectionId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ boolean isEmpty() {
}

/**
* Logs the entire connection table. For debugging purposed only.
* Logs the entire connection table. For debugging purposes only.
*/
void logConnectionTable() {
log.info("Connection table: \n" +
Expand All @@ -114,4 +114,11 @@ public int compare(Map.Entry<ConnectionSource, ServerConnectionProxy> o1, Map.En
.collect(Collectors.joining("\n")));

}

@Override
public void close() {
for (ServerConnectionProxy proxy : currentConnections.values()) {
proxy.dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -323,12 +324,28 @@ private void sendVersionNegotiationPacket(InetSocketAddress clientAddress, ByteB
}
}
}


@Override
public void close() throws InterruptedException {
sharedScheduledExecutor.shutdown();
sharedExecutor.shutdown();

connectionRegistry.close();
serverSocket.close();

if (!sharedScheduledExecutor.awaitTermination(10, TimeUnit.SECONDS)) {
sharedScheduledExecutor.shutdownNow();
}
if (!sharedExecutor.awaitTermination(10, TimeUnit.SECONDS)) {
sharedExecutor.shutdownNow();
}
}

private void closed(ServerConnectionImpl connection) {
ServerConnectionProxy removedConnection = connectionRegistry.removeConnection(connection);
removedConnection.dispose();
}

private class ServerConnectorContext implements Context {

@Override
Expand Down