Browse Source

minor optimization. #200

master
Nikita 10 years ago
parent
commit
800128dd0b
  1. 7
      src/main/java/com/corundumstudio/socketio/SocketIOChannelInitializer.java
  2. 17
      src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java

7
src/main/java/com/corundumstudio/socketio/SocketIOChannelInitializer.java

@ -22,7 +22,6 @@ import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator;
import io.netty.handler.ssl.SslHandler;
import java.security.KeyStore;
@ -45,16 +44,16 @@ import com.corundumstudio.socketio.handler.InPacketHandler;
import com.corundumstudio.socketio.handler.PacketListener;
import com.corundumstudio.socketio.handler.WrongUrlHandler;
import com.corundumstudio.socketio.namespace.NamespacesHub;
import com.corundumstudio.socketio.protocol.JsonSupport;
import com.corundumstudio.socketio.protocol.PacketDecoder;
import com.corundumstudio.socketio.protocol.PacketEncoder;
import com.corundumstudio.socketio.protocol.JsonSupport;
import com.corundumstudio.socketio.scheduler.CancelableScheduler;
import com.corundumstudio.socketio.scheduler.HashedWheelScheduler;
import com.corundumstudio.socketio.store.StoreFactory;
import com.corundumstudio.socketio.store.pubsub.DisconnectMessage;
import com.corundumstudio.socketio.store.pubsub.PubSubStore;
import com.corundumstudio.socketio.transport.WebSocketTransport;
import com.corundumstudio.socketio.transport.PollingTransport;
import com.corundumstudio.socketio.transport.WebSocketTransport;
public class SocketIOChannelInitializer extends ChannelInitializer<Channel> implements DisconnectableHub {
@ -101,7 +100,7 @@ public class SocketIOChannelInitializer extends ChannelInitializer<Channel> impl
JsonSupport jsonSupport = configuration.getJsonSupport();
PacketEncoder encoder = new PacketEncoder(configuration, jsonSupport);
PacketDecoder decoder = new PacketDecoder(jsonSupport, namespacesHub, ackManager);
PacketDecoder decoder = new PacketDecoder(jsonSupport, ackManager);
String connectPath = configuration.getContext() + "/";

17
src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java

@ -29,7 +29,6 @@ import java.util.UUID;
import com.corundumstudio.socketio.AckCallback;
import com.corundumstudio.socketio.ack.AckManager;
import com.corundumstudio.socketio.handler.ClientHead;
import com.corundumstudio.socketio.namespace.NamespacesHub;
public class PacketDecoder {
@ -37,12 +36,10 @@ public class PacketDecoder {
private final JsonSupport jsonSupport;
private final AckManager ackManager;
private final NamespacesHub nspHub;
public PacketDecoder(JsonSupport jsonSupport, NamespacesHub nspHub, AckManager ackManager) {
public PacketDecoder(JsonSupport jsonSupport, AckManager ackManager) {
this.jsonSupport = jsonSupport;
this.ackManager = ackManager;
this.nspHub = nspHub;
}
private boolean isStringPacket(ByteBuf content) {
@ -104,16 +101,14 @@ public class PacketDecoder {
}
private boolean hasLengthHeader(ByteBuf buffer) {
int lengthEndIndex = buffer.bytesBefore(Math.min(buffer.readableBytes(), 10), (byte)':');
if (lengthEndIndex >= 1 && lengthEndIndex <= 10) {
for (int i = 0; i < lengthEndIndex; i++) {
for (int i = 0; i < Math.min(buffer.readableBytes(), 10); i++) {
byte b = buffer.getByte(buffer.readerIndex() + i);
int digit = ((int)b & 0xF);
if (digit > 9 || digit < 0) {
return false;
if (b == (byte)':' && i > 0) {
return true;
}
if (b > 57 || b < 48) {
return false;
}
return true;
}
return false;
}

Loading…
Cancel
Save