mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Fix potential latency issue with on-demand and login writes, constantly writing and flushing is an expensive syscall and should only be done when the channel has been fully read, other instant flushes such as for the game session or initializing HTTP requests must remain untouched as it will potentially block the entire server (and it's nice to have in-game actions done instantly anyway).
This commit is contained in:
@@ -100,4 +100,9 @@ public final class ApolloHandler extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||
ctx.flush();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import java.nio.charset.Charset;
|
||||
import org.apollo.net.codec.jaggrab.JagGrabRequestDecoder;
|
||||
import org.apollo.net.codec.jaggrab.JagGrabResponseEncoder;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
/**
|
||||
* A {@link ChannelInitializer} for the JAGGRAB protocol.
|
||||
*
|
||||
@@ -29,7 +31,7 @@ public final class JagGrabChannelInitializer extends ChannelInitializer<SocketCh
|
||||
/**
|
||||
* The character set used in the request.
|
||||
*/
|
||||
private static final Charset JAGGRAB_CHARSET = Charset.forName("US-ASCII");
|
||||
private static final Charset JAGGRAB_CHARSET = Charsets.US_ASCII;
|
||||
|
||||
/**
|
||||
* The maximum length of a request, in bytes.
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
response.writeByte(LoginConstants.STATUS_EXCHANGE_DATA);
|
||||
response.writeLong(0);
|
||||
response.writeLong(serverSeed);
|
||||
ctx.channel().writeAndFlush(response);
|
||||
ctx.channel().write(response);
|
||||
|
||||
setState(LoginDecoderState.LOGIN_HEADER);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
ByteBuf buffer = ctx.alloc().buffer(1);
|
||||
buffer.writeByte(response);
|
||||
|
||||
ctx.writeAndFlush(buffer).addListener(ChannelFutureListener.CLOSE);
|
||||
ctx.write(buffer).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public final class LoginSession extends Session {
|
||||
}
|
||||
}
|
||||
|
||||
ChannelFuture future = channel.writeAndFlush(new LoginResponse(status, rights, flagged));
|
||||
ChannelFuture future = channel.write(new LoginResponse(status, rights, flagged));
|
||||
|
||||
destroy();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class OnDemandRequestWorker extends RequestWorker<OnDemandRequest,
|
||||
ByteBuf chunkData = Unpooled.wrappedBuffer(tmp, 0, chunkSize);
|
||||
|
||||
OnDemandResponse response = new OnDemandResponse(desc, length, chunk, chunkData);
|
||||
channel.writeAndFlush(response);
|
||||
channel.write(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user