Remove redundant 'else' branches.
This commit is contained in:
parent
361703b319
commit
aa7cd691df
@ -172,7 +172,8 @@ public final class ByteBufUtil {
|
|||||||
long vb = bufferB.getUnsignedInt(bIndex);
|
long vb = bufferB.getUnsignedInt(bIndex);
|
||||||
if (va > vb) {
|
if (va > vb) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (va < vb) {
|
}
|
||||||
|
if (va < vb) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
aIndex += 4;
|
aIndex += 4;
|
||||||
@ -184,7 +185,8 @@ public final class ByteBufUtil {
|
|||||||
long vb = swapInt(bufferB.getInt(bIndex)) & 0xFFFFFFFFL;
|
long vb = swapInt(bufferB.getInt(bIndex)) & 0xFFFFFFFFL;
|
||||||
if (va > vb) {
|
if (va > vb) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (va < vb) {
|
}
|
||||||
|
if (va < vb) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
aIndex += 4;
|
aIndex += 4;
|
||||||
@ -197,7 +199,8 @@ public final class ByteBufUtil {
|
|||||||
short vb = bufferB.getUnsignedByte(bIndex);
|
short vb = bufferB.getUnsignedByte(bIndex);
|
||||||
if (va > vb) {
|
if (va > vb) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (va < vb) {
|
}
|
||||||
|
if (va < vb) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
aIndex ++;
|
aIndex ++;
|
||||||
|
@ -56,7 +56,8 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
|||||||
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
|
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
|
||||||
// 100-continue response must be passed through.
|
// 100-continue response must be passed through.
|
||||||
return msg;
|
return msg;
|
||||||
} else if (msg instanceof HttpMessage) {
|
}
|
||||||
|
if (msg instanceof HttpMessage) {
|
||||||
HttpMessage m = (HttpMessage) msg;
|
HttpMessage m = (HttpMessage) msg;
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
|
@ -29,7 +29,8 @@ public class HttpContentDecompressor extends HttpContentDecoder {
|
|||||||
protected EmbeddedByteChannel newContentDecoder(String contentEncoding) throws Exception {
|
protected EmbeddedByteChannel newContentDecoder(String contentEncoding) throws Exception {
|
||||||
if ("gzip".equalsIgnoreCase(contentEncoding) || "x-gzip".equalsIgnoreCase(contentEncoding)) {
|
if ("gzip".equalsIgnoreCase(contentEncoding) || "x-gzip".equalsIgnoreCase(contentEncoding)) {
|
||||||
return new EmbeddedByteChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
|
return new EmbeddedByteChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
|
||||||
} else if ("deflate".equalsIgnoreCase(contentEncoding) || "x-deflate".equalsIgnoreCase(contentEncoding)) {
|
}
|
||||||
|
if ("deflate".equalsIgnoreCase(contentEncoding) || "x-deflate".equalsIgnoreCase(contentEncoding)) {
|
||||||
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
|
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
|
||||||
return new EmbeddedByteChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.ZLIB_OR_NONE));
|
return new EmbeddedByteChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.ZLIB_OR_NONE));
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,8 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
|||||||
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
|
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
|
||||||
// 100-continue response must be passed through.
|
// 100-continue response must be passed through.
|
||||||
return msg;
|
return msg;
|
||||||
} else if (msg instanceof HttpMessage) {
|
}
|
||||||
|
if (msg instanceof HttpMessage) {
|
||||||
HttpMessage m = (HttpMessage) msg;
|
HttpMessage m = (HttpMessage) msg;
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
|
@ -197,39 +197,39 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
|||||||
if (nextState == State.READ_CHUNK_SIZE) {
|
if (nextState == State.READ_CHUNK_SIZE) {
|
||||||
// Chunked encoding - generate HttpMessage first. HttpChunks will follow.
|
// Chunked encoding - generate HttpMessage first. HttpChunks will follow.
|
||||||
return message;
|
return message;
|
||||||
} else if (nextState == State.SKIP_CONTROL_CHARS) {
|
}
|
||||||
|
if (nextState == State.SKIP_CONTROL_CHARS) {
|
||||||
// No content is expected.
|
// No content is expected.
|
||||||
return reset();
|
return reset();
|
||||||
} else {
|
}
|
||||||
long contentLength = HttpHeaders.getContentLength(message, -1);
|
long contentLength = HttpHeaders.getContentLength(message, -1);
|
||||||
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
|
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
|
||||||
content = Unpooled.EMPTY_BUFFER;
|
content = Unpooled.EMPTY_BUFFER;
|
||||||
return reset();
|
return reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (nextState) {
|
switch (nextState) {
|
||||||
case READ_FIXED_LENGTH_CONTENT:
|
case READ_FIXED_LENGTH_CONTENT:
|
||||||
if (contentLength > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
|
if (contentLength > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
|
||||||
// Generate HttpMessage first. HttpChunks will follow.
|
// Generate HttpMessage first. HttpChunks will follow.
|
||||||
checkpoint(State.READ_FIXED_LENGTH_CONTENT_AS_CHUNKS);
|
checkpoint(State.READ_FIXED_LENGTH_CONTENT_AS_CHUNKS);
|
||||||
message.setTransferEncoding(HttpTransferEncoding.STREAMED);
|
message.setTransferEncoding(HttpTransferEncoding.STREAMED);
|
||||||
// chunkSize will be decreased as the READ_FIXED_LENGTH_CONTENT_AS_CHUNKS
|
// chunkSize will be decreased as the READ_FIXED_LENGTH_CONTENT_AS_CHUNKS
|
||||||
// state reads data chunk by chunk.
|
// state reads data chunk by chunk.
|
||||||
chunkSize = HttpHeaders.getContentLength(message, -1);
|
chunkSize = HttpHeaders.getContentLength(message, -1);
|
||||||
return message;
|
return message;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case READ_VARIABLE_LENGTH_CONTENT:
|
|
||||||
if (buffer.readableBytes() > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
|
|
||||||
// Generate HttpMessage first. HttpChunks will follow.
|
|
||||||
checkpoint(State.READ_VARIABLE_LENGTH_CONTENT_AS_CHUNKS);
|
|
||||||
message.setTransferEncoding(HttpTransferEncoding.STREAMED);
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unexpected state: " + nextState);
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case READ_VARIABLE_LENGTH_CONTENT:
|
||||||
|
if (buffer.readableBytes() > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
|
||||||
|
// Generate HttpMessage first. HttpChunks will follow.
|
||||||
|
checkpoint(State.READ_VARIABLE_LENGTH_CONTENT_AS_CHUNKS);
|
||||||
|
message.setTransferEncoding(HttpTransferEncoding.STREAMED);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unexpected state: " + nextState);
|
||||||
}
|
}
|
||||||
// We return null here, this forces decode to be called again where we will decode the content
|
// We return null here, this forces decode to be called again where we will decode the content
|
||||||
return null;
|
return null;
|
||||||
|
@ -346,7 +346,8 @@ public class QueryStringDecoder {
|
|||||||
if (c == '%') {
|
if (c == '%') {
|
||||||
buf[pos++] = '%'; // "%%" -> "%"
|
buf[pos++] = '%'; // "%%" -> "%"
|
||||||
break;
|
break;
|
||||||
} else if (i == size - 1) {
|
}
|
||||||
|
if (i == size - 1) {
|
||||||
throw new IllegalArgumentException("partial escape"
|
throw new IllegalArgumentException("partial escape"
|
||||||
+ " sequence at end of string: " + s);
|
+ " sequence at end of string: " + s);
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,8 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
|||||||
List<HttpData> fileToDelete = getList(request);
|
List<HttpData> fileToDelete = getList(request);
|
||||||
fileToDelete.add(attribute);
|
fileToDelete.add(attribute);
|
||||||
return attribute;
|
return attribute;
|
||||||
} else if (checkSize) {
|
}
|
||||||
|
if (checkSize) {
|
||||||
Attribute attribute = new MixedAttribute(name, minSize);
|
Attribute attribute = new MixedAttribute(name, minSize);
|
||||||
List<HttpData> fileToDelete = getList(request);
|
List<HttpData> fileToDelete = getList(request);
|
||||||
fileToDelete.add(attribute);
|
fileToDelete.add(attribute);
|
||||||
@ -121,7 +122,8 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
|||||||
List<HttpData> fileToDelete = getList(request);
|
List<HttpData> fileToDelete = getList(request);
|
||||||
fileToDelete.add(attribute);
|
fileToDelete.add(attribute);
|
||||||
return attribute;
|
return attribute;
|
||||||
} else if (checkSize) {
|
}
|
||||||
|
if (checkSize) {
|
||||||
Attribute attribute = new MixedAttribute(name, value, minSize);
|
Attribute attribute = new MixedAttribute(name, value, minSize);
|
||||||
List<HttpData> fileToDelete = getList(request);
|
List<HttpData> fileToDelete = getList(request);
|
||||||
fileToDelete.add(attribute);
|
fileToDelete.add(attribute);
|
||||||
@ -144,7 +146,8 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
|||||||
List<HttpData> fileToDelete = getList(request);
|
List<HttpData> fileToDelete = getList(request);
|
||||||
fileToDelete.add(fileUpload);
|
fileToDelete.add(fileUpload);
|
||||||
return fileUpload;
|
return fileUpload;
|
||||||
} else if (checkSize) {
|
}
|
||||||
|
if (checkSize) {
|
||||||
FileUpload fileUpload = new MixedFileUpload(name, filename, contentType,
|
FileUpload fileUpload = new MixedFileUpload(name, filename, contentType,
|
||||||
contentTransferEncoding, charset, size, minSize);
|
contentTransferEncoding, charset, size, minSize);
|
||||||
List<HttpData> fileToDelete = getList(request);
|
List<HttpData> fileToDelete = getList(request);
|
||||||
|
@ -909,7 +909,8 @@ public class HttpPostRequestDecoder {
|
|||||||
if (newline.equals(delimiter)) {
|
if (newline.equals(delimiter)) {
|
||||||
currentStatus = dispositionStatus;
|
currentStatus = dispositionStatus;
|
||||||
return decodeMultipart(dispositionStatus);
|
return decodeMultipart(dispositionStatus);
|
||||||
} else if (newline.equals(delimiter + "--")) {
|
}
|
||||||
|
if (newline.equals(delimiter + "--")) {
|
||||||
// CLOSEDELIMITER or MIXED CLOSEDELIMITER found
|
// CLOSEDELIMITER or MIXED CLOSEDELIMITER found
|
||||||
currentStatus = closeDelimiterStatus;
|
currentStatus = closeDelimiterStatus;
|
||||||
if (currentStatus == MultiPartStatus.HEADERDELIMITER) {
|
if (currentStatus == MultiPartStatus.HEADERDELIMITER) {
|
||||||
@ -1926,7 +1927,8 @@ public class HttpPostRequestDecoder {
|
|||||||
}
|
}
|
||||||
undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2);
|
undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2);
|
||||||
return false;
|
return false;
|
||||||
} else if (nextByte == HttpConstants.LF) {
|
}
|
||||||
|
if (nextByte == HttpConstants.LF) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
|
undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
|
||||||
|
@ -290,9 +290,11 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
|
|||||||
// fragmented
|
// fragmented
|
||||||
if (frameOpcode == OPCODE_PING) {
|
if (frameOpcode == OPCODE_PING) {
|
||||||
return new PingWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
|
return new PingWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
|
||||||
} else if (frameOpcode == OPCODE_PONG) {
|
}
|
||||||
|
if (frameOpcode == OPCODE_PONG) {
|
||||||
return new PongWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
|
return new PongWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
|
||||||
} else if (frameOpcode == OPCODE_CLOSE) {
|
}
|
||||||
|
if (frameOpcode == OPCODE_CLOSE) {
|
||||||
checkCloseFrameBody(ctx, framePayload);
|
checkCloseFrameBody(ctx, framePayload);
|
||||||
receivedClosingHandshake = true;
|
receivedClosingHandshake = true;
|
||||||
return new CloseWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
|
return new CloseWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
@ -26,6 +25,8 @@ import io.netty.handler.codec.http.DefaultHttpResponse;
|
|||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
|
|
||||||
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles WebSocket control frames (Close, Ping, Pong) and data frames (Text and Binary) are passed
|
* Handles WebSocket control frames (Close, Ping, Pong) and data frames (Text and Binary) are passed
|
||||||
* to the next handler in the pipeline.
|
* to the next handler in the pipeline.
|
||||||
@ -69,7 +70,8 @@ public class WebSocketServerProtocolHandler extends ChannelInboundMessageHandler
|
|||||||
WebSocketServerHandshaker handshaker = getHandshaker(ctx);
|
WebSocketServerHandshaker handshaker = getHandshaker(ctx);
|
||||||
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
|
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
|
||||||
return;
|
return;
|
||||||
} else if (frame instanceof PingWebSocketFrame) {
|
}
|
||||||
|
if (frame instanceof PingWebSocketFrame) {
|
||||||
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
|
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,11 @@ public enum WebSocketVersion {
|
|||||||
public String toHttpHeaderValue() {
|
public String toHttpHeaderValue() {
|
||||||
if (this == V00) {
|
if (this == V00) {
|
||||||
return "0";
|
return "0";
|
||||||
} else if (this == V08) {
|
}
|
||||||
|
if (this == V08) {
|
||||||
return "8";
|
return "8";
|
||||||
} else if (this == V13) {
|
}
|
||||||
|
if (this == V13) {
|
||||||
return "13";
|
return "13";
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Unknown web socket version: " + this);
|
throw new IllegalStateException("Unknown web socket version: " + this);
|
||||||
|
@ -80,11 +80,10 @@ public abstract class ByteToMessageDecoder<O>
|
|||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (oldInputLength == in.readableBytes()) {
|
if (oldInputLength == in.readableBytes()) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"decode() did not read anything but decoded a message.");
|
"decode() did not read anything but decoded a message.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChannelHandlerUtil.unfoldAndAdd(ctx, o, true)) {
|
if (ChannelHandlerUtil.unfoldAndAdd(ctx, o, true)) {
|
||||||
|
@ -364,7 +364,8 @@ final class Deflate {
|
|||||||
nextlen = tree[(n + 1) * 2 + 1];
|
nextlen = tree[(n + 1) * 2 + 1];
|
||||||
if (++ count < max_count && curlen == nextlen) {
|
if (++ count < max_count && curlen == nextlen) {
|
||||||
continue;
|
continue;
|
||||||
} else if (count < min_count) {
|
}
|
||||||
|
if (count < min_count) {
|
||||||
bl_tree[curlen * 2] += count;
|
bl_tree[curlen * 2] += count;
|
||||||
} else if (curlen != 0) {
|
} else if (curlen != 0) {
|
||||||
if (curlen != prevlen) {
|
if (curlen != prevlen) {
|
||||||
@ -458,7 +459,8 @@ final class Deflate {
|
|||||||
nextlen = tree[(n + 1) * 2 + 1];
|
nextlen = tree[(n + 1) * 2 + 1];
|
||||||
if (++ count < max_count && curlen == nextlen) {
|
if (++ count < max_count && curlen == nextlen) {
|
||||||
continue;
|
continue;
|
||||||
} else if (count < min_count) {
|
}
|
||||||
|
if (count < min_count) {
|
||||||
do {
|
do {
|
||||||
send_code(curlen, bl_tree);
|
send_code(curlen, bl_tree);
|
||||||
} while (-- count != 0);
|
} while (-- count != 0);
|
||||||
|
@ -303,7 +303,8 @@ final class Inflate {
|
|||||||
if (z.istate.wrapperType == WrapperType.NONE) {
|
if (z.istate.wrapperType == WrapperType.NONE) {
|
||||||
z.istate.mode = DONE;
|
z.istate.mode = DONE;
|
||||||
break;
|
break;
|
||||||
} else if (z.istate.wrapperType == WrapperType.ZLIB) {
|
}
|
||||||
|
if (z.istate.wrapperType == WrapperType.ZLIB) {
|
||||||
z.istate.mode = CHECK4;
|
z.istate.mode = CHECK4;
|
||||||
} else if (z.istate.wrapperType == WrapperType.GZIP) {
|
} else if (z.istate.wrapperType == WrapperType.GZIP) {
|
||||||
gzipCRC32 = 0;
|
gzipCRC32 = 0;
|
||||||
@ -317,7 +318,7 @@ final class Inflate {
|
|||||||
z.istate.marker = 0;
|
z.istate.marker = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CHECK4:
|
case CHECK4:
|
||||||
if (z.avail_in == 0) {
|
if (z.avail_in == 0) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.example.http.websocketx.server;
|
package io.netty.example.http.websocketx.server;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaders.*;
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
|
||||||
import static io.netty.handler.codec.http.HttpMethod.*;
|
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
@ -40,6 +35,12 @@ import io.netty.logging.InternalLogger;
|
|||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
|
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpHeaders.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpMethod.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles handshakes and messages
|
* Handles handshakes and messages
|
||||||
*/
|
*/
|
||||||
@ -84,7 +85,8 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
|
|||||||
res.setContent(content);
|
res.setContent(content);
|
||||||
sendHttpResponse(ctx, req, res);
|
sendHttpResponse(ctx, req, res);
|
||||||
return;
|
return;
|
||||||
} else if ("/favicon.ico".equals(req.getUri())) {
|
}
|
||||||
|
if ("/favicon.ico".equals(req.getUri())) {
|
||||||
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
|
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
|
||||||
sendHttpResponse(ctx, req, res);
|
sendHttpResponse(ctx, req, res);
|
||||||
return;
|
return;
|
||||||
@ -107,10 +109,12 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
|
|||||||
if (frame instanceof CloseWebSocketFrame) {
|
if (frame instanceof CloseWebSocketFrame) {
|
||||||
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
|
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
|
||||||
return;
|
return;
|
||||||
} else if (frame instanceof PingWebSocketFrame) {
|
}
|
||||||
|
if (frame instanceof PingWebSocketFrame) {
|
||||||
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
|
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
|
||||||
return;
|
return;
|
||||||
} else if (!(frame instanceof TextWebSocketFrame)) {
|
}
|
||||||
|
if (!(frame instanceof TextWebSocketFrame)) {
|
||||||
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
|
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
|
||||||
.getName()));
|
.getName()));
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.example.http.websocketx.sslserver;
|
package io.netty.example.http.websocketx.sslserver;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaders.*;
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
|
||||||
import static io.netty.handler.codec.http.HttpMethod.*;
|
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
@ -41,6 +36,12 @@ import io.netty.logging.InternalLogger;
|
|||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
|
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpHeaders.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpMethod.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles handshakes and messages
|
* Handles handshakes and messages
|
||||||
*/
|
*/
|
||||||
@ -85,7 +86,9 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
|
|||||||
res.setContent(content);
|
res.setContent(content);
|
||||||
sendHttpResponse(ctx, req, res);
|
sendHttpResponse(ctx, req, res);
|
||||||
return;
|
return;
|
||||||
} else if ("/favicon.ico".equals(req.getUri())) {
|
}
|
||||||
|
|
||||||
|
if ("/favicon.ico".equals(req.getUri())) {
|
||||||
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
|
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
|
||||||
sendHttpResponse(ctx, req, res);
|
sendHttpResponse(ctx, req, res);
|
||||||
return;
|
return;
|
||||||
@ -108,10 +111,12 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
|
|||||||
if (frame instanceof CloseWebSocketFrame) {
|
if (frame instanceof CloseWebSocketFrame) {
|
||||||
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
|
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
|
||||||
return;
|
return;
|
||||||
} else if (frame instanceof PingWebSocketFrame) {
|
}
|
||||||
|
if (frame instanceof PingWebSocketFrame) {
|
||||||
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
|
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
|
||||||
return;
|
return;
|
||||||
} else if (!(frame instanceof TextWebSocketFrame)) {
|
}
|
||||||
|
if (!(frame instanceof TextWebSocketFrame)) {
|
||||||
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
|
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
|
||||||
.getName()));
|
.getName()));
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.channel;
|
package io.netty.channel;
|
||||||
|
|
||||||
import static io.netty.channel.ChannelOption.*;
|
|
||||||
import io.netty.channel.socket.SocketChannelConfig;
|
import io.netty.channel.socket.SocketChannelConfig;
|
||||||
|
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static io.netty.channel.ChannelOption.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default {@link SocketChannelConfig} implementation.
|
* The default {@link SocketChannelConfig} implementation.
|
||||||
*/
|
*/
|
||||||
@ -74,7 +75,8 @@ public class DefaultChannelConfig implements ChannelConfig {
|
|||||||
|
|
||||||
if (option == CONNECT_TIMEOUT_MILLIS) {
|
if (option == CONNECT_TIMEOUT_MILLIS) {
|
||||||
return (T) Integer.valueOf(getConnectTimeoutMillis());
|
return (T) Integer.valueOf(getConnectTimeoutMillis());
|
||||||
} else if (option == WRITE_SPIN_COUNT) {
|
}
|
||||||
|
if (option == WRITE_SPIN_COUNT) {
|
||||||
return (T) Integer.valueOf(getWriteSpinCount());
|
return (T) Integer.valueOf(getWriteSpinCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,9 +311,7 @@ public class DefaultChannelFuture extends FlushCheckpoint implements ChannelFutu
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (done) {
|
if (done || waitTime <= 0) {
|
||||||
return done;
|
|
||||||
} else if (waitTime <= 0) {
|
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1351,16 +1351,16 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
}
|
}
|
||||||
flush0(ctx, future);
|
flush0(ctx, future);
|
||||||
return future;
|
return future;
|
||||||
} else {
|
|
||||||
final DefaultChannelHandlerContext ctx0 = ctx;
|
|
||||||
executor.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
write(ctx0, message, future);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final DefaultChannelHandlerContext ctx0 = ctx;
|
||||||
|
executor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
write(ctx0, message, future);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.channel.group;
|
package io.netty.channel.group;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.*;
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
@ -31,6 +30,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default {@link ChannelGroupFuture} implementation.
|
* The default {@link ChannelGroupFuture} implementation.
|
||||||
*/
|
*/
|
||||||
@ -289,9 +290,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (done) {
|
if (done || waitTime <= 0) {
|
||||||
return done;
|
|
||||||
} else if (waitTime <= 0) {
|
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,9 +271,7 @@ public final class NioDatagramChannel
|
|||||||
public ChannelFuture joinGroup(
|
public ChannelFuture joinGroup(
|
||||||
InetAddress multicastAddress, NetworkInterface networkInterface,
|
InetAddress multicastAddress, NetworkInterface networkInterface,
|
||||||
InetAddress source, ChannelFuture future) {
|
InetAddress source, ChannelFuture future) {
|
||||||
if (DetectionUtil.javaVersion() < 7) {
|
if (DetectionUtil.javaVersion() >= 7) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
} else {
|
|
||||||
if (multicastAddress == null) {
|
if (multicastAddress == null) {
|
||||||
throw new NullPointerException("multicastAddress");
|
throw new NullPointerException("multicastAddress");
|
||||||
}
|
}
|
||||||
@ -303,6 +301,8 @@ public final class NioDatagramChannel
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
future.setFailure(e);
|
future.setFailure(e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.channel.local;
|
package io.netty.channel.local;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.MessageBuf;
|
import io.netty.buffer.MessageBuf;
|
||||||
@ -24,11 +23,12 @@ import io.netty.channel.ChannelFuture;
|
|||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class LocalTransportThreadModelTest2 {
|
public class LocalTransportThreadModelTest2 {
|
||||||
|
|
||||||
@ -100,15 +100,15 @@ public class LocalTransportThreadModelTest2 {
|
|||||||
|
|
||||||
localChannel.close();
|
localChannel.close();
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
localChannel.eventLoop().execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
close(localChannel, localRegistrationHandler);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localChannel.eventLoop().execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
close(localChannel, localRegistrationHandler);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Wait until the connection is closed or the connection attempt fails.
|
// Wait until the connection is closed or the connection attempt fails.
|
||||||
localChannel.closeFuture().awaitUninterruptibly();
|
localChannel.closeFuture().awaitUninterruptibly();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user