Skip to content

Commit

Permalink
Use an enum for the internal state (#656)
Browse files Browse the repository at this point in the history
Motivation:

To make it easier to inspect the state of the QuicheQuicChannel it makes
sense to use an enum for the internal state of the channel

Modifications:

Replace int by enum

Result:

Cleanup
  • Loading branch information
normanmaurer authored Feb 4, 2024
1 parent 41a7537 commit 73fc4e3
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ enum StreamRecvResult {
OK
}

private enum ChannelState {
OPEN,
ACTIVE,
CLOSED
}

private static final class CloseData implements ChannelFutureListener {
final boolean applicationClose;
final int err;
Expand Down Expand Up @@ -159,10 +165,7 @@ public void operationComplete(ChannelFuture channelFuture) {
private static final int IN_HANDLE_WRITABLE_STREAMS = 1 << 3;
private static final int IN_FORCE_CLOSE = 1 << 4;

private static final int CLOSED = 0;
private static final int OPEN = 1;
private static final int ACTIVE = 2;
private volatile int state;
private volatile ChannelState state = ChannelState.OPEN;
private volatile boolean timedOut;
private volatile String traceId;
private volatile QuicheQuicConnection connection;
Expand All @@ -188,7 +191,6 @@ private QuicheQuicChannel(Channel parent, boolean server, ByteBuffer key, InetSo
if (key != null) {
this.sourceConnectionIds.add(key);
}
state = OPEN;

this.supportsDatagram = supportsDatagram;
this.local = local;
Expand Down Expand Up @@ -434,7 +436,7 @@ void forceClose() {
statsAtClose = collectStats0(conn, eventLoop().newPromise());
try {
failPendingConnectPromise();
state = CLOSED;
state = ChannelState.CLOSED;
timedOut = Quiche.quiche_conn_is_timed_out(conn.address());

closeStreams();
Expand All @@ -443,7 +445,6 @@ void forceClose() {
finBuffer.release();
finBuffer = null;
}
state = CLOSED;

timeoutHandler.cancel();
} finally {
Expand Down Expand Up @@ -563,7 +564,7 @@ protected void doDisconnect() throws Exception {

@Override
protected void doClose() throws Exception {
state = CLOSED;
state = ChannelState.CLOSED;

final boolean app;
final int err;
Expand Down Expand Up @@ -699,12 +700,12 @@ public QuicChannelConfig config() {

@Override
public boolean isOpen() {
return state >= OPEN;
return state != ChannelState.CLOSED;
}

@Override
public boolean isActive() {
return state == ACTIVE;
return state == ChannelState.ACTIVE;
}

@Override
Expand Down Expand Up @@ -1787,9 +1788,9 @@ private void recvDatagram() {
private boolean handlePendingChannelActive() {
long connAddr = connection.address();
if (server) {
if (state == OPEN && Quiche.quiche_conn_is_established(connAddr)) {
if (state == ChannelState.OPEN && Quiche.quiche_conn_is_established(connAddr)) {
// We didn't notify before about channelActive... Update state and fire the event.
state = ACTIVE;
state = ChannelState.ACTIVE;

pipeline().fireChannelActive();
notifyAboutHandshakeCompletionIfNeeded(null);
Expand All @@ -1798,7 +1799,7 @@ private boolean handlePendingChannelActive() {
} else if (connectPromise != null && Quiche.quiche_conn_is_established(connAddr)) {
ChannelPromise promise = connectPromise;
connectPromise = null;
state = ACTIVE;
state = ChannelState.ACTIVE;

boolean promiseSet = promise.trySuccess();
pipeline().fireChannelActive();
Expand Down

0 comments on commit 73fc4e3

Please sign in to comment.