Skip to content

Commit

Permalink
fix: wait for channel reregistration if possible
Browse files Browse the repository at this point in the history
Fixes #62
  • Loading branch information
ishland committed May 1, 2024
1 parent 1c4579f commit b8d8a18
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MixinClientConnection {

@Shadow private volatile @Nullable PacketListener packetListener;

@Inject(method = "setPacketListener", at = @At(value = "RETURN"))
@Inject(method = "transitionInbound", at = @At(value = "RETURN"))
private void onSetState(NetworkState<?> state, PacketListener listener, CallbackInfo ci) {
// if (this.channel.config() == instance) {
// final EventLoopGroup group = VMPEventLoops.getEventLoopGroup(this.channel, state);
Expand All @@ -40,7 +40,7 @@ private void onSetState(NetworkState<?> state, PacketListener listener, Callback
// }
final EventLoopGroup group = VMPEventLoops.getEventLoopGroup(this.channel, state.id());
if (group != null) {
reregister(group);
vmp$reregister(group);
}
}

Expand All @@ -50,7 +50,8 @@ private void onSetState(NetworkState<?> state, PacketListener listener, Callback
@Unique
private EventLoopGroup pendingReregistration = null;

private synchronized void reregister(EventLoopGroup group) {
@Unique
private synchronized void vmp$reregister(EventLoopGroup group) {
if (isReregistering) {
pendingReregistration = group;
return;
Expand All @@ -69,18 +70,23 @@ private synchronized void reregister(EventLoopGroup group) {
}
});
promise.addListener(future -> {
isReregistering = false;
if (future.isSuccess()) {
synchronized (this) {
isReregistering = false;
if (future.isSuccess()) {
// System.out.println("Reregistered " + this.channel);
this.channel.config().setAutoRead(true);
} else {
this.channel.pipeline().fireExceptionCaught(future.cause());
}
if (pendingReregistration != null) {
reregister(pendingReregistration);
pendingReregistration = null;
this.channel.config().setAutoRead(true);
} else {
this.channel.pipeline().fireExceptionCaught(future.cause());
}
if (pendingReregistration != null) {
vmp$reregister(pendingReregistration);
pendingReregistration = null;
}
}
});
if (!promise.channel().eventLoop().inEventLoop()) {
promise.syncUninterruptibly();
}
}

}

0 comments on commit b8d8a18

Please sign in to comment.