merge upstream master
This commit is contained in:
commit
20d7379c53
@ -155,11 +155,21 @@ public class QueryStringDecoder {
|
|||||||
"maxParams: " + maxParams + " (expected: a positive integer)");
|
"maxParams: " + maxParams + " (expected: a positive integer)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String rawPath = uri.getRawPath();
|
||||||
|
if (rawPath != null) {
|
||||||
|
hasPath = true;
|
||||||
|
} else {
|
||||||
|
rawPath ="";
|
||||||
|
hasPath = false;
|
||||||
|
}
|
||||||
|
// Also take care of cut of things like "http://localhost"
|
||||||
|
String newUri = rawPath + "?" + uri.getRawQuery();
|
||||||
|
|
||||||
// http://en.wikipedia.org/wiki/Query_string
|
// http://en.wikipedia.org/wiki/Query_string
|
||||||
this.uri = uri.toASCIIString().replace(';', '&');
|
this.uri = newUri.replace(';', '&');
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
this.maxParams = maxParams;
|
this.maxParams = maxParams;
|
||||||
hasPath = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,6 +139,14 @@ final class SpdyCodecUtil {
|
|||||||
(buf.getByte(offset + 3) & 0xFF));
|
(buf.getByte(offset + 3) & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if ID is for a server initiated stream or ping.
|
||||||
|
*/
|
||||||
|
static boolean isServerID(int ID) {
|
||||||
|
// Server initiated streams and pings have even IDs
|
||||||
|
return ID % 2 == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a SPDY header name.
|
* Validate a SPDY header name.
|
||||||
*/
|
*/
|
||||||
|
@ -43,10 +43,27 @@ import io.netty.channel.ChannelUpstreamHandler;
|
|||||||
public class SpdyFrameCodec implements ChannelUpstreamHandler,
|
public class SpdyFrameCodec implements ChannelUpstreamHandler,
|
||||||
ChannelDownstreamHandler {
|
ChannelDownstreamHandler {
|
||||||
|
|
||||||
private final SpdyFrameDecoder decoder = new SpdyFrameDecoder();
|
private final SpdyFrameDecoder decoder;
|
||||||
private final SpdyFrameEncoder encoder = new SpdyFrameEncoder();
|
private final SpdyFrameEncoder encoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with the default decoder and encoder options
|
||||||
|
* ({@code maxChunkSize (8192)}, {@code maxFrameSize (65536)},
|
||||||
|
* {@code maxHeaderSize (16384)}, {@code compressionLevel (6)},
|
||||||
|
* {@code windowBits (15)}, and {@code memLevel (8)}).
|
||||||
|
*/
|
||||||
public SpdyFrameCodec() {
|
public SpdyFrameCodec() {
|
||||||
|
this(8192, 65536, 16384, 6, 15, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with the specified decoder and encoder options.
|
||||||
|
*/
|
||||||
|
public SpdyFrameCodec(
|
||||||
|
int maxChunkSize, int maxFrameSize, int maxHeaderSize,
|
||||||
|
int compressionLevel, int windowBits, int memLevel) {
|
||||||
|
decoder = new SpdyFrameDecoder(maxChunkSize, maxFrameSize, maxHeaderSize);
|
||||||
|
encoder = new SpdyFrameEncoder(compressionLevel, windowBits, memLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
|
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
|
||||||
|
@ -44,11 +44,42 @@ import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
|||||||
*/
|
*/
|
||||||
public class SpdyFrameDecoder extends FrameDecoder {
|
public class SpdyFrameDecoder extends FrameDecoder {
|
||||||
|
|
||||||
|
private final int maxChunkSize;
|
||||||
|
private final int maxFrameSize;
|
||||||
|
private final int maxHeaderSize;
|
||||||
|
|
||||||
private final DecoderEmbedder<ChannelBuffer> headerBlockDecompressor =
|
private final DecoderEmbedder<ChannelBuffer> headerBlockDecompressor =
|
||||||
new DecoderEmbedder<ChannelBuffer>(new ZlibDecoder(SPDY_DICT));
|
new DecoderEmbedder<ChannelBuffer>(new ZlibDecoder(SPDY_DICT));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with the default {@code maxChunkSize (8192)},
|
||||||
|
* {@code maxFrameSize (65536)}, and {@code maxHeaderSize (16384)}.
|
||||||
|
*/
|
||||||
public SpdyFrameDecoder() {
|
public SpdyFrameDecoder() {
|
||||||
super();
|
this(8192, 65536, 16384);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with the specified parameters.
|
||||||
|
*/
|
||||||
|
public SpdyFrameDecoder(
|
||||||
|
int maxChunkSize, int maxFrameSize, int maxHeaderSize) {
|
||||||
|
super(true); // Enable unfold for data frames
|
||||||
|
if (maxChunkSize <= 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"maxChunkSize must be a positive integer: " + maxChunkSize);
|
||||||
|
}
|
||||||
|
if (maxFrameSize <= 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"maxFrameSize must be a positive integer: " + maxFrameSize);
|
||||||
|
}
|
||||||
|
if (maxHeaderSize <= 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"maxHeaderSize must be a positive integer: " + maxHeaderSize);
|
||||||
|
}
|
||||||
|
this.maxChunkSize = maxChunkSize;
|
||||||
|
this.maxFrameSize = maxFrameSize;
|
||||||
|
this.maxHeaderSize = maxHeaderSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,6 +98,12 @@ public class SpdyFrameDecoder extends FrameDecoder {
|
|||||||
int dataLength = getUnsignedMedium(buffer, lengthOffset);
|
int dataLength = getUnsignedMedium(buffer, lengthOffset);
|
||||||
int frameLength = SPDY_HEADER_SIZE + dataLength;
|
int frameLength = SPDY_HEADER_SIZE + dataLength;
|
||||||
|
|
||||||
|
// Throw exception if frameLength exceeds maxFrameSize
|
||||||
|
if (frameLength > maxFrameSize) {
|
||||||
|
throw new SpdyProtocolException(
|
||||||
|
"Frame length exceeds " + maxFrameSize + ": " + frameLength);
|
||||||
|
}
|
||||||
|
|
||||||
// Wait until entire frame is readable
|
// Wait until entire frame is readable
|
||||||
if (buffer.readableBytes() < frameLength) {
|
if (buffer.readableBytes() < frameLength) {
|
||||||
return null;
|
return null;
|
||||||
@ -98,12 +135,25 @@ public class SpdyFrameDecoder extends FrameDecoder {
|
|||||||
int streamID = getUnsignedInt(buffer, frameOffset);
|
int streamID = getUnsignedInt(buffer, frameOffset);
|
||||||
buffer.skipBytes(SPDY_HEADER_SIZE);
|
buffer.skipBytes(SPDY_HEADER_SIZE);
|
||||||
|
|
||||||
|
// Generate data frames that do not exceed maxChunkSize
|
||||||
|
int numFrames = dataLength / maxChunkSize;
|
||||||
|
if (dataLength % maxChunkSize != 0) {
|
||||||
|
numFrames ++;
|
||||||
|
}
|
||||||
|
SpdyDataFrame[] frames = new SpdyDataFrame[numFrames];
|
||||||
|
for (int i = 0; i < numFrames; i++) {
|
||||||
|
int chunkSize = Math.min(maxChunkSize, dataLength);
|
||||||
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(streamID);
|
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(streamID);
|
||||||
spdyDataFrame.setLast((flags & SPDY_DATA_FLAG_FIN) != 0);
|
|
||||||
spdyDataFrame.setCompressed((flags & SPDY_DATA_FLAG_COMPRESS) != 0);
|
spdyDataFrame.setCompressed((flags & SPDY_DATA_FLAG_COMPRESS) != 0);
|
||||||
spdyDataFrame.setData(buffer.readBytes(dataLength));
|
spdyDataFrame.setData(buffer.readBytes(chunkSize));
|
||||||
|
dataLength -= chunkSize;
|
||||||
|
if (dataLength == 0) {
|
||||||
|
spdyDataFrame.setLast((flags & SPDY_DATA_FLAG_FIN) != 0);
|
||||||
|
}
|
||||||
|
frames[i] = spdyDataFrame;
|
||||||
|
}
|
||||||
|
|
||||||
return spdyDataFrame;
|
return frames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,6 +326,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
|
|||||||
throw new SpdyProtocolException(
|
throw new SpdyProtocolException(
|
||||||
"Received invalid header block");
|
"Received invalid header block");
|
||||||
}
|
}
|
||||||
|
int headerSize = 0;
|
||||||
int numEntries = getUnsignedShort(headerBlock, headerBlock.readerIndex());
|
int numEntries = getUnsignedShort(headerBlock, headerBlock.readerIndex());
|
||||||
headerBlock.skipBytes(2);
|
headerBlock.skipBytes(2);
|
||||||
for (int i = 0; i < numEntries; i ++) {
|
for (int i = 0; i < numEntries; i ++) {
|
||||||
@ -289,6 +340,11 @@ public class SpdyFrameDecoder extends FrameDecoder {
|
|||||||
headerFrame.setInvalid();
|
headerFrame.setInvalid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
headerSize += nameLength;
|
||||||
|
if (headerSize > maxHeaderSize) {
|
||||||
|
throw new SpdyProtocolException(
|
||||||
|
"Header block exceeds " + maxHeaderSize);
|
||||||
|
}
|
||||||
if (headerBlock.readableBytes() < nameLength) {
|
if (headerBlock.readableBytes() < nameLength) {
|
||||||
throw new SpdyProtocolException(
|
throw new SpdyProtocolException(
|
||||||
"Received invalid header block");
|
"Received invalid header block");
|
||||||
@ -310,6 +366,11 @@ public class SpdyFrameDecoder extends FrameDecoder {
|
|||||||
headerFrame.setInvalid();
|
headerFrame.setInvalid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
headerSize += valueLength;
|
||||||
|
if (headerSize > maxHeaderSize) {
|
||||||
|
throw new SpdyProtocolException(
|
||||||
|
"Header block exceeds " + maxHeaderSize);
|
||||||
|
}
|
||||||
if (headerBlock.readableBytes() < valueLength) {
|
if (headerBlock.readableBytes() < valueLength) {
|
||||||
throw new SpdyProtocolException(
|
throw new SpdyProtocolException(
|
||||||
"Received invalid header block");
|
"Received invalid header block");
|
||||||
|
@ -48,11 +48,23 @@ import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
|||||||
*/
|
*/
|
||||||
public class SpdyFrameEncoder extends OneToOneEncoder {
|
public class SpdyFrameEncoder extends OneToOneEncoder {
|
||||||
|
|
||||||
private final EncoderEmbedder<ChannelBuffer> headerBlockCompressor =
|
private final EncoderEmbedder<ChannelBuffer> headerBlockCompressor;
|
||||||
new EncoderEmbedder<ChannelBuffer>(new ZlibEncoder(9, SPDY_DICT));
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with the default {@code compressionLevel (6)},
|
||||||
|
* {@code windowBits (15)}, and {@code memLevel (8)}.
|
||||||
|
*/
|
||||||
public SpdyFrameEncoder() {
|
public SpdyFrameEncoder() {
|
||||||
|
this(6, 15, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with the specified parameters.
|
||||||
|
*/
|
||||||
|
public SpdyFrameEncoder(int compressionLevel, int windowBits, int memLevel) {
|
||||||
super();
|
super();
|
||||||
|
headerBlockCompressor = new EncoderEmbedder<ChannelBuffer>(
|
||||||
|
new ZlibEncoder(compressionLevel, windowBits, memLevel, SPDY_DICT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Twitter, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License. You may obtain
|
||||||
|
* a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelDownstreamHandler;
|
||||||
|
import io.netty.channel.ChannelEvent;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.ChannelUpstreamHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A combination of {@link SpdyHttpDecoder} and {@link SpdyHttpEncoder}
|
||||||
|
* @apiviz.has io.netty.handler.codec.sdpy.SpdyHttpDecoder
|
||||||
|
* @apiviz.has io.netty.handler.codec.spdy.SpdyHttpEncoder
|
||||||
|
*/
|
||||||
|
public class SpdyHttpCodec implements ChannelUpstreamHandler, ChannelDownstreamHandler {
|
||||||
|
|
||||||
|
private final SpdyHttpDecoder decoder;
|
||||||
|
private final SpdyHttpEncoder encoder = new SpdyHttpEncoder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with the specified decoder options.
|
||||||
|
*/
|
||||||
|
public SpdyHttpCodec(int maxContentLength) {
|
||||||
|
decoder = new SpdyHttpDecoder(maxContentLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
|
||||||
|
throws Exception {
|
||||||
|
decoder.handleUpstream(ctx, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
|
||||||
|
throws Exception {
|
||||||
|
encoder.handleDownstream(ctx, e);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,296 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Twitter, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License. You may obtain
|
||||||
|
* a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import io.netty.buffer.ChannelBuffer;
|
||||||
|
import io.netty.buffer.ChannelBuffers;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.Channels;
|
||||||
|
import io.netty.handler.codec.frame.TooLongFrameException;
|
||||||
|
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||||
|
import io.netty.handler.codec.http.DefaultHttpResponse;
|
||||||
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
|
import io.netty.handler.codec.http.HttpMessage;
|
||||||
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
|
import io.netty.handler.codec.oneone.OneToOneDecoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes {@link SpdySynStreamFrame}s, {@link SpdySynReplyFrame}s,
|
||||||
|
* and {@link SpdyDataFrame}s into {@link HttpRequest}s and {@link HttpResponse}s.
|
||||||
|
*/
|
||||||
|
public class SpdyHttpDecoder extends OneToOneDecoder {
|
||||||
|
|
||||||
|
private final int maxContentLength;
|
||||||
|
private final Map<Integer, HttpMessage> messageMap = new HashMap<Integer, HttpMessage>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance.
|
||||||
|
*
|
||||||
|
* @param maxContentLength the maximum length of the message content.
|
||||||
|
* If the length of the message content exceeds this value,
|
||||||
|
* a {@link TooLongFrameException} will be raised.
|
||||||
|
*/
|
||||||
|
public SpdyHttpDecoder(int maxContentLength) {
|
||||||
|
super();
|
||||||
|
if (maxContentLength <= 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"maxContentLength must be a positive integer: " + maxContentLength);
|
||||||
|
}
|
||||||
|
this.maxContentLength = maxContentLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
|
if (msg instanceof SpdySynStreamFrame) {
|
||||||
|
|
||||||
|
// HTTP requests/responses are mapped one-to-one to SPDY streams.
|
||||||
|
SpdySynStreamFrame spdySynStreamFrame = (SpdySynStreamFrame) msg;
|
||||||
|
int streamID = spdySynStreamFrame.getStreamID();
|
||||||
|
|
||||||
|
if (SpdyCodecUtil.isServerID(streamID)) {
|
||||||
|
// SYN_STREAM frames inititated by the server are pushed resources
|
||||||
|
int associatedToStreamID = spdySynStreamFrame.getAssociatedToStreamID();
|
||||||
|
|
||||||
|
// If a client receives a SYN_STREAM with an Associated-To-Stream-ID of 0
|
||||||
|
// it must reply with a RST_STREAM with error code INVALID_STREAM
|
||||||
|
if (associatedToStreamID == 0) {
|
||||||
|
SpdyRstStreamFrame spdyRstStreamFrame =
|
||||||
|
new DefaultSpdyRstStreamFrame(streamID, SpdyStreamStatus.INVALID_STREAM);
|
||||||
|
Channels.write(ctx, Channels.future(channel), spdyRstStreamFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
String URL = SpdyHeaders.getUrl(spdySynStreamFrame);
|
||||||
|
|
||||||
|
// If a client receives a SYN_STREAM without a 'url' header
|
||||||
|
// it must reply with a RST_STREAM with error code PROTOCOL_ERROR
|
||||||
|
if (URL == null) {
|
||||||
|
SpdyRstStreamFrame spdyRstStreamFrame =
|
||||||
|
new DefaultSpdyRstStreamFrame(streamID, SpdyStreamStatus.PROTOCOL_ERROR);
|
||||||
|
Channels.write(ctx, Channels.future(channel), spdyRstStreamFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpResponse httpResponse = createHttpResponse(spdySynStreamFrame);
|
||||||
|
|
||||||
|
// Set the Stream-ID, Associated-To-Stream-ID, Priority, and URL as headers
|
||||||
|
SpdyHttpHeaders.setStreamID(httpResponse, streamID);
|
||||||
|
SpdyHttpHeaders.setAssociatedToStreamID(httpResponse, associatedToStreamID);
|
||||||
|
SpdyHttpHeaders.setPriority(httpResponse, spdySynStreamFrame.getPriority());
|
||||||
|
SpdyHttpHeaders.setUrl(httpResponse, URL);
|
||||||
|
|
||||||
|
if (spdySynStreamFrame.isLast()) {
|
||||||
|
HttpHeaders.setContentLength(httpResponse, 0);
|
||||||
|
return httpResponse;
|
||||||
|
} else {
|
||||||
|
// Response body will follow in a series of Data Frames
|
||||||
|
messageMap.put(new Integer(streamID), httpResponse);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
SpdyRstStreamFrame spdyRstStreamFrame =
|
||||||
|
new DefaultSpdyRstStreamFrame(streamID, SpdyStreamStatus.PROTOCOL_ERROR);
|
||||||
|
Channels.write(ctx, Channels.future(channel), spdyRstStreamFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// SYN_STREAM frames initiated by the client are HTTP requests
|
||||||
|
try {
|
||||||
|
HttpRequest httpRequest = createHttpRequest(spdySynStreamFrame);
|
||||||
|
|
||||||
|
// Set the Stream-ID as a header
|
||||||
|
SpdyHttpHeaders.setStreamID(httpRequest, streamID);
|
||||||
|
|
||||||
|
if (spdySynStreamFrame.isLast()) {
|
||||||
|
return httpRequest;
|
||||||
|
} else {
|
||||||
|
// Request body will follow in a series of Data Frames
|
||||||
|
messageMap.put(new Integer(streamID), httpRequest);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// If a client sends a SYN_STREAM without method, url, and version headers
|
||||||
|
// the server must reply with a HTTP 400 BAD REQUEST reply
|
||||||
|
// Also sends HTTP 400 BAD REQUEST reply if header name/value pairs are invalid
|
||||||
|
SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamID);
|
||||||
|
spdySynReplyFrame.setLast(true);
|
||||||
|
SpdyHeaders.setStatus(spdySynReplyFrame, HttpResponseStatus.BAD_REQUEST);
|
||||||
|
SpdyHeaders.setVersion(spdySynReplyFrame, HttpVersion.HTTP_1_0);
|
||||||
|
Channels.write(ctx, Channels.future(channel), spdySynReplyFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (msg instanceof SpdySynReplyFrame) {
|
||||||
|
|
||||||
|
SpdySynReplyFrame spdySynReplyFrame = (SpdySynReplyFrame) msg;
|
||||||
|
int streamID = spdySynReplyFrame.getStreamID();
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpResponse httpResponse = createHttpResponse(spdySynReplyFrame);
|
||||||
|
|
||||||
|
// Set the Stream-ID as a header
|
||||||
|
SpdyHttpHeaders.setStreamID(httpResponse, streamID);
|
||||||
|
|
||||||
|
if (spdySynReplyFrame.isLast()) {
|
||||||
|
HttpHeaders.setContentLength(httpResponse, 0);
|
||||||
|
return httpResponse;
|
||||||
|
} else {
|
||||||
|
// Response body will follow in a series of Data Frames
|
||||||
|
messageMap.put(new Integer(streamID), httpResponse);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// If a client receives a SYN_REPLY without valid status and version headers
|
||||||
|
// the client must reply with a RST_STREAM frame indicating a PROTOCOL_ERROR
|
||||||
|
SpdyRstStreamFrame spdyRstStreamFrame =
|
||||||
|
new DefaultSpdyRstStreamFrame(streamID, SpdyStreamStatus.PROTOCOL_ERROR);
|
||||||
|
Channels.write(ctx, Channels.future(channel), spdyRstStreamFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (msg instanceof SpdyHeadersFrame) {
|
||||||
|
|
||||||
|
SpdyHeadersFrame spdyHeadersFrame = (SpdyHeadersFrame) msg;
|
||||||
|
Integer streamID = new Integer(spdyHeadersFrame.getStreamID());
|
||||||
|
HttpMessage httpMessage = messageMap.get(streamID);
|
||||||
|
|
||||||
|
// If message is not in map discard HEADERS frame.
|
||||||
|
// SpdySessionHandler should prevent this from happening.
|
||||||
|
if (httpMessage == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> e: spdyHeadersFrame.getHeaders()) {
|
||||||
|
httpMessage.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (msg instanceof SpdyDataFrame) {
|
||||||
|
|
||||||
|
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
|
||||||
|
Integer streamID = new Integer(spdyDataFrame.getStreamID());
|
||||||
|
HttpMessage httpMessage = messageMap.get(streamID);
|
||||||
|
|
||||||
|
// If message is not in map discard Data Frame.
|
||||||
|
// SpdySessionHandler should prevent this from happening.
|
||||||
|
if (httpMessage == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChannelBuffer content = httpMessage.getContent();
|
||||||
|
if (content.readableBytes() > maxContentLength - spdyDataFrame.getData().readableBytes()) {
|
||||||
|
messageMap.remove(streamID);
|
||||||
|
throw new TooLongFrameException(
|
||||||
|
"HTTP content length exceeded " + maxContentLength + " bytes.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content == ChannelBuffers.EMPTY_BUFFER) {
|
||||||
|
content = ChannelBuffers.dynamicBuffer(channel.getConfig().getBufferFactory());
|
||||||
|
content.writeBytes(spdyDataFrame.getData());
|
||||||
|
httpMessage.setContent(content);
|
||||||
|
} else {
|
||||||
|
content.writeBytes(spdyDataFrame.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spdyDataFrame.isLast()) {
|
||||||
|
HttpHeaders.setContentLength(httpMessage, content.readableBytes());
|
||||||
|
messageMap.remove(streamID);
|
||||||
|
return httpMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpRequest createHttpRequest(SpdyHeaderBlock requestFrame)
|
||||||
|
throws Exception {
|
||||||
|
// Create the first line of the request from the name/value pairs
|
||||||
|
HttpMethod method = SpdyHeaders.getMethod(requestFrame);
|
||||||
|
String url = SpdyHeaders.getUrl(requestFrame);
|
||||||
|
HttpVersion version = SpdyHeaders.getVersion(requestFrame);
|
||||||
|
SpdyHeaders.removeMethod(requestFrame);
|
||||||
|
SpdyHeaders.removeUrl(requestFrame);
|
||||||
|
SpdyHeaders.removeVersion(requestFrame);
|
||||||
|
|
||||||
|
HttpRequest httpRequest = new DefaultHttpRequest(version, method, url);
|
||||||
|
for (Map.Entry<String, String> e: requestFrame.getHeaders()) {
|
||||||
|
httpRequest.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chunked encoding is no longer valid
|
||||||
|
List<String> encodings = httpRequest.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||||
|
encodings.remove(HttpHeaders.Values.CHUNKED);
|
||||||
|
if (encodings.isEmpty()) {
|
||||||
|
httpRequest.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||||
|
} else {
|
||||||
|
httpRequest.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, encodings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Connection and Keep-Alive headers are no longer valid
|
||||||
|
HttpHeaders.setKeepAlive(httpRequest, true);
|
||||||
|
|
||||||
|
return httpRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpResponse createHttpResponse(SpdyHeaderBlock responseFrame)
|
||||||
|
throws Exception {
|
||||||
|
// Create the first line of the response from the name/value pairs
|
||||||
|
HttpResponseStatus status = SpdyHeaders.getStatus(responseFrame);
|
||||||
|
HttpVersion version = SpdyHeaders.getVersion(responseFrame);
|
||||||
|
SpdyHeaders.removeStatus(responseFrame);
|
||||||
|
SpdyHeaders.removeVersion(responseFrame);
|
||||||
|
|
||||||
|
HttpResponse httpResponse = new DefaultHttpResponse(version, status);
|
||||||
|
for (Map.Entry<String, String> e: responseFrame.getHeaders()) {
|
||||||
|
httpResponse.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chunked encoding is no longer valid
|
||||||
|
List<String> encodings = httpResponse.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||||
|
encodings.remove(HttpHeaders.Values.CHUNKED);
|
||||||
|
if (encodings.isEmpty()) {
|
||||||
|
httpResponse.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||||
|
} else {
|
||||||
|
httpResponse.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, encodings);
|
||||||
|
}
|
||||||
|
httpResponse.removeHeader(HttpHeaders.Names.TRAILER);
|
||||||
|
|
||||||
|
// The Connection and Keep-Alive headers are no longer valid
|
||||||
|
HttpHeaders.setKeepAlive(httpResponse, true);
|
||||||
|
|
||||||
|
return httpResponse;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,325 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Twitter, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License. You may obtain
|
||||||
|
* a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelDownstreamHandler;
|
||||||
|
import io.netty.channel.ChannelEvent;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.Channels;
|
||||||
|
import io.netty.channel.MessageEvent;
|
||||||
|
import io.netty.handler.codec.http.HttpChunk;
|
||||||
|
import io.netty.handler.codec.http.HttpChunkTrailer;
|
||||||
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
|
import io.netty.handler.codec.http.HttpMessage;
|
||||||
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes {@link HttpRequest}s, {@link HttpResponse}s, and {@link HttpChunk}s
|
||||||
|
* into {@link SpdySynStreamFrame}s and {@link SpdySynReplyFrame}s.
|
||||||
|
*
|
||||||
|
* <h3>Request Annotations</h3>
|
||||||
|
*
|
||||||
|
* SPDY specific headers must be added to {@link HttpRequest}s:
|
||||||
|
* <table border=1>
|
||||||
|
* <tr>
|
||||||
|
* <th>Header Name</th><th>Header Value</th>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td>{@code "X-SPDY-Stream-ID"}</td>
|
||||||
|
* <td>The Stream-ID for this request.
|
||||||
|
* Stream-IDs must be odd, positive integers, and must increase monotonically.</td>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td>{@code "X-SPDY-Priority"}</td>
|
||||||
|
* <td>The priority value for this request.
|
||||||
|
* The priority should be between 0 and 3 inclusive.
|
||||||
|
* 0 represents the highest priority and 3 represents the lowest.
|
||||||
|
* This header is optional and defaults to 0.</td>
|
||||||
|
* </tr>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
* <h3>Response Annotations</h3>
|
||||||
|
*
|
||||||
|
* SPDY specific headers must be added to {@link HttpResponse}s:
|
||||||
|
* <table border=1>
|
||||||
|
* <tr>
|
||||||
|
* <th>Header Name</th><th>Header Value</th>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td>{@code "X-SPDY-Stream-ID"}</td>
|
||||||
|
* <td>The Stream-ID of the request corresponding to this response.</td>
|
||||||
|
* </tr>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
* <h3>Pushed Resource Annotations</h3>
|
||||||
|
*
|
||||||
|
* SPDY specific headers must be added to pushed {@link HttpResponse}s:
|
||||||
|
* <table border=1>
|
||||||
|
* <tr>
|
||||||
|
* <th>Header Name</th><th>Header Value</th>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td>{@code "X-SPDY-Stream-ID"}</td>
|
||||||
|
* <td>The Stream-ID for this resource.
|
||||||
|
* Stream-IDs must be even, positive integers, and must increase monotonically.</td>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td>{@code "X-SPDY-Associated-To-Stream-ID"}</td>
|
||||||
|
* <td>The Stream-ID of the request that inititated this pushed resource.</td>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td>{@code "X-SPDY-Priority"}</td>
|
||||||
|
* <td>The priority value for this resource.
|
||||||
|
* The priority should be between 0 and 3 inclusive.
|
||||||
|
* 0 represents the highest priority and 3 represents the lowest.
|
||||||
|
* This header is optional and defaults to 0.</td>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td>{@code "X-SPDY-URL"}</td>
|
||||||
|
* <td>The full URL for the resource being pushed.</td>
|
||||||
|
* </tr>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
* <h3>Chunked Content</h3>
|
||||||
|
*
|
||||||
|
* This encoder associates all {@link HttpChunk}s that it receives
|
||||||
|
* with the most recently received 'chunked' {@link HttpRequest}
|
||||||
|
* or {@link HttpResponse}.
|
||||||
|
*
|
||||||
|
* <h3>Pushed Resources</h3>
|
||||||
|
*
|
||||||
|
* All pushed resources should be sent before sending the response
|
||||||
|
* that corresponds to the initial request.
|
||||||
|
*/
|
||||||
|
public class SpdyHttpEncoder implements ChannelDownstreamHandler {
|
||||||
|
|
||||||
|
private volatile int currentStreamID;
|
||||||
|
|
||||||
|
public SpdyHttpEncoder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent evt)
|
||||||
|
throws Exception {
|
||||||
|
if (!(evt instanceof MessageEvent)) {
|
||||||
|
ctx.sendDownstream(evt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageEvent e = (MessageEvent) evt;
|
||||||
|
Object msg = e.getMessage();
|
||||||
|
|
||||||
|
if (msg instanceof HttpRequest) {
|
||||||
|
|
||||||
|
HttpRequest httpRequest = (HttpRequest) msg;
|
||||||
|
SpdySynStreamFrame spdySynStreamFrame = createSynStreamFrame(httpRequest);
|
||||||
|
int streamID = spdySynStreamFrame.getStreamID();
|
||||||
|
ChannelFuture future = getContentFuture(ctx, e, streamID, httpRequest);
|
||||||
|
Channels.write(ctx, future, spdySynStreamFrame, e.getRemoteAddress());
|
||||||
|
|
||||||
|
} else if (msg instanceof HttpResponse) {
|
||||||
|
|
||||||
|
HttpResponse httpResponse = (HttpResponse) msg;
|
||||||
|
if (httpResponse.containsHeader(SpdyHttpHeaders.Names.ASSOCIATED_TO_STREAM_ID)) {
|
||||||
|
SpdySynStreamFrame spdySynStreamFrame = createSynStreamFrame(httpResponse);
|
||||||
|
int streamID = spdySynStreamFrame.getStreamID();
|
||||||
|
ChannelFuture future = getContentFuture(ctx, e, streamID, httpResponse);
|
||||||
|
Channels.write(ctx, future, spdySynStreamFrame, e.getRemoteAddress());
|
||||||
|
} else {
|
||||||
|
SpdySynReplyFrame spdySynReplyFrame = createSynReplyFrame(httpResponse);
|
||||||
|
int streamID = spdySynReplyFrame.getStreamID();
|
||||||
|
ChannelFuture future = getContentFuture(ctx, e, streamID, httpResponse);
|
||||||
|
Channels.write(ctx, future, spdySynReplyFrame, e.getRemoteAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (msg instanceof HttpChunk) {
|
||||||
|
|
||||||
|
HttpChunk chunk = (HttpChunk) msg;
|
||||||
|
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(currentStreamID);
|
||||||
|
spdyDataFrame.setData(chunk.getContent());
|
||||||
|
spdyDataFrame.setLast(chunk.isLast());
|
||||||
|
|
||||||
|
if (chunk instanceof HttpChunkTrailer) {
|
||||||
|
HttpChunkTrailer trailer = (HttpChunkTrailer) chunk;
|
||||||
|
List<Map.Entry<String, String>> trailers = trailer.getHeaders();
|
||||||
|
if (trailers.isEmpty()) {
|
||||||
|
Channels.write(ctx, e.getFuture(), spdyDataFrame, e.getRemoteAddress());
|
||||||
|
} else {
|
||||||
|
// Create SPDY HEADERS frame out of trailers
|
||||||
|
SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(currentStreamID);
|
||||||
|
for (Map.Entry<String, String> entry: trailers) {
|
||||||
|
spdyHeadersFrame.addHeader(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write HEADERS frame and append Data Frame
|
||||||
|
ChannelFuture future = Channels.future(e.getChannel());
|
||||||
|
future.addListener(new SpdyFrameWriter(ctx, e, spdyDataFrame));
|
||||||
|
Channels.write(ctx, future, spdyHeadersFrame, e.getRemoteAddress());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Channels.write(ctx, e.getFuture(), spdyDataFrame, e.getRemoteAddress());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Unknown message type
|
||||||
|
ctx.sendDownstream(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChannelFuture getContentFuture(
|
||||||
|
ChannelHandlerContext ctx, MessageEvent e, int streamID, HttpMessage httpMessage) {
|
||||||
|
if (httpMessage.getContent().readableBytes() == 0) {
|
||||||
|
return e.getFuture();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create SPDY Data Frame out of message content
|
||||||
|
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(streamID);
|
||||||
|
spdyDataFrame.setData(httpMessage.getContent());
|
||||||
|
spdyDataFrame.setLast(true);
|
||||||
|
|
||||||
|
// Create new future and add listener
|
||||||
|
ChannelFuture future = Channels.future(e.getChannel());
|
||||||
|
future.addListener(new SpdyFrameWriter(ctx, e, spdyDataFrame));
|
||||||
|
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SpdyFrameWriter implements ChannelFutureListener {
|
||||||
|
|
||||||
|
private final ChannelHandlerContext ctx;
|
||||||
|
private final MessageEvent e;
|
||||||
|
private final Object spdyFrame;
|
||||||
|
|
||||||
|
SpdyFrameWriter(ChannelHandlerContext ctx, MessageEvent e, Object spdyFrame) {
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.e = e;
|
||||||
|
this.spdyFrame = spdyFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
|
if (future.isSuccess()) {
|
||||||
|
Channels.write(ctx, e.getFuture(), spdyFrame, e.getRemoteAddress());
|
||||||
|
} else if (future.isCancelled()) {
|
||||||
|
e.getFuture().cancel();
|
||||||
|
} else {
|
||||||
|
e.getFuture().setFailure(future.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SpdySynStreamFrame createSynStreamFrame(HttpMessage httpMessage)
|
||||||
|
throws Exception {
|
||||||
|
boolean chunked = httpMessage.isChunked();
|
||||||
|
|
||||||
|
// Get the Stream-ID, Associated-To-Stream-ID, Priority, and URL from the headers
|
||||||
|
int streamID = SpdyHttpHeaders.getStreamID(httpMessage);
|
||||||
|
int associatedToStreamID = SpdyHttpHeaders.getAssociatedToStreamID(httpMessage);
|
||||||
|
byte priority = SpdyHttpHeaders.getPriority(httpMessage);
|
||||||
|
String URL = SpdyHttpHeaders.getUrl(httpMessage);
|
||||||
|
SpdyHttpHeaders.removeStreamID(httpMessage);
|
||||||
|
SpdyHttpHeaders.removeAssociatedToStreamID(httpMessage);
|
||||||
|
SpdyHttpHeaders.removePriority(httpMessage);
|
||||||
|
SpdyHttpHeaders.removeUrl(httpMessage);
|
||||||
|
|
||||||
|
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
|
||||||
|
// headers are not valid and MUST not be sent.
|
||||||
|
httpMessage.removeHeader(HttpHeaders.Names.CONNECTION);
|
||||||
|
httpMessage.removeHeader("Keep-Alive");
|
||||||
|
httpMessage.removeHeader("Proxy-Connection");
|
||||||
|
httpMessage.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||||
|
|
||||||
|
SpdySynStreamFrame spdySynStreamFrame = new DefaultSpdySynStreamFrame(streamID, associatedToStreamID, priority);
|
||||||
|
for (Map.Entry<String, String> entry: httpMessage.getHeaders()) {
|
||||||
|
spdySynStreamFrame.addHeader(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unfold the first line of the message into name/value pairs
|
||||||
|
SpdyHeaders.setVersion(spdySynStreamFrame, httpMessage.getProtocolVersion());
|
||||||
|
if (httpMessage instanceof HttpRequest) {
|
||||||
|
HttpRequest httpRequest = (HttpRequest) httpMessage;
|
||||||
|
SpdyHeaders.setMethod(spdySynStreamFrame, httpRequest.getMethod());
|
||||||
|
SpdyHeaders.setUrl(spdySynStreamFrame, httpRequest.getUri());
|
||||||
|
}
|
||||||
|
if (httpMessage instanceof HttpResponse) {
|
||||||
|
HttpResponse httpResponse = (HttpResponse) httpMessage;
|
||||||
|
SpdyHeaders.setStatus(spdySynStreamFrame, httpResponse.getStatus());
|
||||||
|
SpdyHeaders.setUrl(spdySynStreamFrame, URL);
|
||||||
|
spdySynStreamFrame.setUnidirectional(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chunked) {
|
||||||
|
currentStreamID = streamID;
|
||||||
|
spdySynStreamFrame.setLast(false);
|
||||||
|
} else {
|
||||||
|
spdySynStreamFrame.setLast(httpMessage.getContent().readableBytes() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return spdySynStreamFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SpdySynReplyFrame createSynReplyFrame(HttpResponse httpResponse)
|
||||||
|
throws Exception {
|
||||||
|
boolean chunked = httpResponse.isChunked();
|
||||||
|
|
||||||
|
// Get the Stream-ID from the headers
|
||||||
|
int streamID = SpdyHttpHeaders.getStreamID(httpResponse);
|
||||||
|
SpdyHttpHeaders.removeStreamID(httpResponse);
|
||||||
|
|
||||||
|
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-ENcoding
|
||||||
|
// headers are not valid and MUST not be sent.
|
||||||
|
httpResponse.removeHeader(HttpHeaders.Names.CONNECTION);
|
||||||
|
httpResponse.removeHeader("Keep-Alive");
|
||||||
|
httpResponse.removeHeader("Proxy-Connection");
|
||||||
|
httpResponse.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||||
|
|
||||||
|
SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamID);
|
||||||
|
for (Map.Entry<String, String> entry: httpResponse.getHeaders()) {
|
||||||
|
spdySynReplyFrame.addHeader(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unfold the first line of the repsonse into name/value pairs
|
||||||
|
SpdyHeaders.setStatus(spdySynReplyFrame, httpResponse.getStatus());
|
||||||
|
SpdyHeaders.setVersion(spdySynReplyFrame, httpResponse.getProtocolVersion());
|
||||||
|
|
||||||
|
if (chunked) {
|
||||||
|
currentStreamID = streamID;
|
||||||
|
spdySynReplyFrame.setLast(false);
|
||||||
|
} else {
|
||||||
|
spdySynReplyFrame.setLast(httpResponse.getContent().readableBytes() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return spdySynReplyFrame;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Twitter, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License. You may obtain
|
||||||
|
* a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
|
import io.netty.handler.codec.http.HttpMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the constants for the header names and the utility methods
|
||||||
|
* used by the {@link SpdyHttpDecoder} and {@link SpdyHttpEncoder}.
|
||||||
|
* @apiviz.sterotype static
|
||||||
|
*/
|
||||||
|
public final class SpdyHttpHeaders {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SPDY HTTP header names
|
||||||
|
* @apiviz.sterotype static
|
||||||
|
*/
|
||||||
|
public static final class Names {
|
||||||
|
/**
|
||||||
|
* {@code "X-SPDY-Stream-ID"}
|
||||||
|
*/
|
||||||
|
public static final String STREAM_ID = "X-SPDY-Stream-ID";
|
||||||
|
/**
|
||||||
|
* {@code "X-SPDY-Associated-To-Stream-ID"}
|
||||||
|
*/
|
||||||
|
public static final String ASSOCIATED_TO_STREAM_ID = "X-SPDY-Associated-To-Stream-ID";
|
||||||
|
/**
|
||||||
|
* {@code "X-SPDY-Priority"}
|
||||||
|
*/
|
||||||
|
public static final String PRIORITY = "X-SPDY-Priority";
|
||||||
|
/**
|
||||||
|
* {@code "X-SPDY-URL"}
|
||||||
|
*/
|
||||||
|
public static final String URL = "X-SPDY-URL";
|
||||||
|
|
||||||
|
private Names() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SpdyHttpHeaders() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the {@code "X-SPDY-Stream-ID"} header.
|
||||||
|
*/
|
||||||
|
public static void removeStreamID(HttpMessage message) {
|
||||||
|
message.removeHeader(Names.STREAM_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the {@code "X-SPDY-Stream-ID"} header.
|
||||||
|
*/
|
||||||
|
public static int getStreamID(HttpMessage message) {
|
||||||
|
return HttpHeaders.getIntHeader(message, Names.STREAM_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@code "X-SPDY-Stream-ID"} header.
|
||||||
|
*/
|
||||||
|
public static void setStreamID(HttpMessage message, int streamID) {
|
||||||
|
HttpHeaders.setIntHeader(message, Names.STREAM_ID, streamID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the {@code "X-SPDY-Associated-To-Stream-ID"} header.
|
||||||
|
*/
|
||||||
|
public static void removeAssociatedToStreamID(HttpMessage message) {
|
||||||
|
message.removeHeader(Names.ASSOCIATED_TO_STREAM_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the {@code "X-SPDY-Associated-To-Stream-ID"} header.
|
||||||
|
*
|
||||||
|
* @return the header value or {@code 0} if there is no such header or
|
||||||
|
* if the header value is not a number
|
||||||
|
*/
|
||||||
|
public static int getAssociatedToStreamID(HttpMessage message) {
|
||||||
|
return HttpHeaders.getIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@code "X-SPDY-Associated-To-Stream-ID"} header.
|
||||||
|
*/
|
||||||
|
public static void setAssociatedToStreamID(HttpMessage message, int associatedToStreamID) {
|
||||||
|
HttpHeaders.setIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the {@code "X-SPDY-Priority"} header.
|
||||||
|
*/
|
||||||
|
public static void removePriority(HttpMessage message) {
|
||||||
|
message.removeHeader(Names.PRIORITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the {@code "X-SPDY-Priority"} header.
|
||||||
|
*
|
||||||
|
* @return the header value or {@code 0} if there is no such header or
|
||||||
|
* if the header value is not a number
|
||||||
|
*/
|
||||||
|
public static byte getPriority(HttpMessage message) {
|
||||||
|
return (byte) HttpHeaders.getIntHeader(message, Names.PRIORITY, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@code "X-SPDY-Priority"} header.
|
||||||
|
*/
|
||||||
|
public static void setPriority(HttpMessage message, byte priority) {
|
||||||
|
HttpHeaders.setIntHeader(message, Names.PRIORITY, priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the {@code "X-SPDY-URL"} header.
|
||||||
|
*/
|
||||||
|
public static void removeUrl(HttpMessage message) {
|
||||||
|
message.removeHeader(Names.URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the {@code "X-SPDY-URL"} header.
|
||||||
|
*/
|
||||||
|
public static String getUrl(HttpMessage message) {
|
||||||
|
return message.getHeader(Names.URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@code "X-SPDY-URL"} header.
|
||||||
|
*/
|
||||||
|
public static void setUrl(HttpMessage message, String url) {
|
||||||
|
message.setHeader(Names.URL, url);
|
||||||
|
}
|
||||||
|
}
|
@ -393,12 +393,8 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
|
|||||||
* Helper functions
|
* Helper functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private boolean isServerID(int ID) {
|
|
||||||
return ID % 2 == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isRemoteInitiatedID(int ID) {
|
private boolean isRemoteInitiatedID(int ID) {
|
||||||
boolean serverID = isServerID(ID);
|
boolean serverID = SpdyCodecUtil.isServerID(ID);
|
||||||
return (server && !serverID) || (!server && serverID);
|
return (server && !serverID) || (!server && serverID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@ -165,4 +168,91 @@ public class QueryStringDecoderTest {
|
|||||||
Assert.assertEquals(ed.getPath(), ad.getPath());
|
Assert.assertEquals(ed.getPath(), ad.getPath());
|
||||||
Assert.assertEquals(ed.getParameters(), ad.getParameters());
|
Assert.assertEquals(ed.getParameters(), ad.getParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See #189
|
||||||
|
@Test
|
||||||
|
public void testURI() {
|
||||||
|
URI uri = URI.create("http://localhost:8080/foo?param1=value1¶m2=value2¶m3=value3");
|
||||||
|
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||||
|
Assert.assertEquals("/foo", decoder.getPath());
|
||||||
|
Map<String, List<String>> params = decoder.getParameters();
|
||||||
|
Assert.assertEquals(3, params.size());
|
||||||
|
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||||
|
|
||||||
|
Entry<String, List<String>> entry = entries.next();
|
||||||
|
Assert.assertEquals("param1", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value1", entry.getValue().get(0));
|
||||||
|
|
||||||
|
|
||||||
|
entry = entries.next();
|
||||||
|
Assert.assertEquals("param2", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value2", entry.getValue().get(0));
|
||||||
|
|
||||||
|
entry = entries.next();
|
||||||
|
Assert.assertEquals("param3", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value3", entry.getValue().get(0));
|
||||||
|
|
||||||
|
Assert.assertFalse(entries.hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
|
// See #189
|
||||||
|
@Test
|
||||||
|
public void testURISlashPath() {
|
||||||
|
URI uri = URI.create("http://localhost:8080/?param1=value1¶m2=value2¶m3=value3");
|
||||||
|
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||||
|
Assert.assertEquals("/", decoder.getPath());
|
||||||
|
Map<String, List<String>> params = decoder.getParameters();
|
||||||
|
Assert.assertEquals(3, params.size());
|
||||||
|
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||||
|
|
||||||
|
Entry<String, List<String>> entry = entries.next();
|
||||||
|
Assert.assertEquals("param1", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value1", entry.getValue().get(0));
|
||||||
|
|
||||||
|
|
||||||
|
entry = entries.next();
|
||||||
|
Assert.assertEquals("param2", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value2", entry.getValue().get(0));
|
||||||
|
|
||||||
|
entry = entries.next();
|
||||||
|
Assert.assertEquals("param3", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value3", entry.getValue().get(0));
|
||||||
|
|
||||||
|
Assert.assertFalse(entries.hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
|
// See #189
|
||||||
|
@Test
|
||||||
|
public void testURINoPath() {
|
||||||
|
URI uri = URI.create("http://localhost:8080?param1=value1¶m2=value2¶m3=value3");
|
||||||
|
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||||
|
Assert.assertEquals("", decoder.getPath());
|
||||||
|
Map<String, List<String>> params = decoder.getParameters();
|
||||||
|
Assert.assertEquals(3, params.size());
|
||||||
|
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||||
|
|
||||||
|
Entry<String, List<String>> entry = entries.next();
|
||||||
|
Assert.assertEquals("param1", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value1", entry.getValue().get(0));
|
||||||
|
|
||||||
|
|
||||||
|
entry = entries.next();
|
||||||
|
Assert.assertEquals("param2", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value2", entry.getValue().get(0));
|
||||||
|
|
||||||
|
entry = entries.next();
|
||||||
|
Assert.assertEquals("param3", entry.getKey());
|
||||||
|
Assert.assertEquals(1, entry.getValue().size());
|
||||||
|
Assert.assertEquals("value3", entry.getValue().get(0));
|
||||||
|
|
||||||
|
Assert.assertFalse(entries.hasNext());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,10 +518,13 @@ public class HashedWheelTimer implements Timer {
|
|||||||
try {
|
try {
|
||||||
task.run(this);
|
task.run(this);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"An exception was thrown by " +
|
"An exception was thrown by " +
|
||||||
TimerTask.class.getSimpleName() + ".", t);
|
TimerTask.class.getSimpleName() + ".", t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,6 +43,7 @@ public class SharedResourceMisuseDetector {
|
|||||||
|
|
||||||
public void increase() {
|
public void increase() {
|
||||||
if (activeInstances.incrementAndGet() > MAX_ACTIVE_INSTANCES) {
|
if (activeInstances.incrementAndGet() > MAX_ACTIVE_INSTANCES) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
if (logged.compareAndSet(false, true)) {
|
if (logged.compareAndSet(false, true)) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"You are creating too many " + type.getSimpleName() +
|
"You are creating too many " + type.getSimpleName() +
|
||||||
@ -52,6 +53,7 @@ public class SharedResourceMisuseDetector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void decrease() {
|
public void decrease() {
|
||||||
activeInstances.decrementAndGet();
|
activeInstances.decrementAndGet();
|
||||||
|
@ -83,7 +83,7 @@ public class HttpSnoopClient {
|
|||||||
|
|
||||||
// Prepare the HTTP request.
|
// Prepare the HTTP request.
|
||||||
HttpRequest request = new DefaultHttpRequest(
|
HttpRequest request = new DefaultHttpRequest(
|
||||||
HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toASCIIString());
|
HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath());
|
||||||
request.setHeader(HttpHeaders.Names.HOST, host);
|
request.setHeader(HttpHeaders.Names.HOST, host);
|
||||||
request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
|
request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
|
||||||
request.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
|
request.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
|
||||||
|
@ -81,8 +81,11 @@ public class AutobahnServerHandler extends SimpleChannelUpstreamHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(String
|
logger.debug(String
|
||||||
.format("Channel %s received %s", ctx.getChannel().getId(), frame.getClass().getSimpleName()));
|
.format("Channel %s received %s", ctx.getChannel().getId(), frame.getClass().getSimpleName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (frame instanceof CloseWebSocketFrame) {
|
if (frame instanceof CloseWebSocketFrame) {
|
||||||
this.handshaker.close(ctx.getChannel(), (CloseWebSocketFrame) frame);
|
this.handshaker.close(ctx.getChannel(), (CloseWebSocketFrame) frame);
|
||||||
|
@ -116,7 +116,9 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler {
|
|||||||
|
|
||||||
// Send the uppercase string back.
|
// Send the uppercase string back.
|
||||||
String request = ((TextWebSocketFrame) frame).getText();
|
String request = ((TextWebSocketFrame) frame).getText();
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(String.format("Channel %s received %s", ctx.getChannel().getId(), request));
|
logger.debug(String.format("Channel %s received %s", ctx.getChannel().getId(), request));
|
||||||
|
}
|
||||||
ctx.getChannel().write(new TextWebSocketFrame(request.toUpperCase()));
|
ctx.getChannel().write(new TextWebSocketFrame(request.toUpperCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,9 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler {
|
|||||||
|
|
||||||
// Send the uppercase string back.
|
// Send the uppercase string back.
|
||||||
String request = ((TextWebSocketFrame) frame).getText();
|
String request = ((TextWebSocketFrame) frame).getText();
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(String.format("Channel %s received %s", ctx.getChannel().getId(), request));
|
logger.debug(String.format("Channel %s received %s", ctx.getChannel().getId(), request));
|
||||||
|
}
|
||||||
ctx.getChannel().write(new TextWebSocketFrame(request.toUpperCase()));
|
ctx.getChannel().write(new TextWebSocketFrame(request.toUpperCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,9 @@ public final class WebSocketSslServerSslContext {
|
|||||||
}
|
}
|
||||||
_serverContext = serverContext;
|
_serverContext = serverContext;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
if (logger.isErrorEnabled()) {
|
||||||
logger.error("Error initializing SslContextManager. " + ex.getMessage(), ex);
|
logger.error("Error initializing SslContextManager. " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,9 @@ public class CIDR6 extends CIDR {
|
|||||||
try {
|
try {
|
||||||
return bigIntToIPv6Address(addressEndBigInt);
|
return bigIntToIPv6Address(addressEndBigInt);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
|
if (logger.isErrorEnabled()) {
|
||||||
logger.error("invalid ip address calculated as an end address");
|
logger.error("invalid ip address calculated as an end address");
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,9 @@ public class IpFilterRuleList extends ArrayList<IpFilterRule> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(rule.startsWith("+") || rule.startsWith("-"))) {
|
if (!(rule.startsWith("+") || rule.startsWith("-"))) {
|
||||||
|
if (logger.isErrorEnabled()) {
|
||||||
logger.error("syntax error in ip filter rule:" + rule);
|
logger.error("syntax error in ip filter rule:" + rule);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,10 +82,14 @@ public class IpFilterRuleList extends ArrayList<IpFilterRule> {
|
|||||||
try {
|
try {
|
||||||
this.add(new IpSubnetFilterRule(allow, rule.substring(3)));
|
this.add(new IpSubnetFilterRule(allow, rule.substring(3)));
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
|
if (logger.isErrorEnabled()) {
|
||||||
logger.error("error parsing ip filter " + rule, e);
|
logger.error("error parsing ip filter " + rule, e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (logger.isErrorEnabled()) {
|
||||||
logger.error("syntax error in ip filter rule:" + rule);
|
logger.error("syntax error in ip filter rule:" + rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,8 +158,10 @@ public class PatternRule implements IpFilterRule, Comparable<Object> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("error getting ip of localhost", e);
|
logger.info("error getting ip of localhost", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
InetAddress[] addrs = InetAddress.getAllByName("127.0.0.1");
|
InetAddress[] addrs = InetAddress.getAllByName("127.0.0.1");
|
||||||
for (InetAddress addr : addrs) {
|
for (InetAddress addr : addrs) {
|
||||||
@ -168,8 +170,10 @@ public class PatternRule implements IpFilterRule, Comparable<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("error getting ip of localhost", e);
|
logger.info("error getting ip of localhost", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -497,11 +497,13 @@ public class SslHandler extends FrameDecoder
|
|||||||
try {
|
try {
|
||||||
engine.closeInbound();
|
engine.closeInbound();
|
||||||
} catch (SSLException ex) {
|
} catch (SSLException ex) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Failed to clean up SSLEngine.", ex);
|
logger.debug("Failed to clean up SSLEngine.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
||||||
@ -513,9 +515,12 @@ public class SslHandler extends FrameDecoder
|
|||||||
synchronized (ignoreClosedChannelExceptionLock) {
|
synchronized (ignoreClosedChannelExceptionLock) {
|
||||||
if (ignoreClosedChannelException > 0) {
|
if (ignoreClosedChannelException > 0) {
|
||||||
ignoreClosedChannelException --;
|
ignoreClosedChannelException --;
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Swallowing an exception raised while " +
|
"Swallowing an exception raised while " +
|
||||||
"writing non-app data", cause);
|
"writing non-app data", cause);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -524,10 +529,12 @@ public class SslHandler extends FrameDecoder
|
|||||||
if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
|
if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
|
||||||
// It is safe to ignore the 'connection reset by peer' or
|
// It is safe to ignore the 'connection reset by peer' or
|
||||||
// 'broken pipe' error after sending closure_notify.
|
// 'broken pipe' error after sending closure_notify.
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Swallowing a 'connection reset by peer / " +
|
"Swallowing a 'connection reset by peer / " +
|
||||||
"broken pipe' error occurred while writing " +
|
"broken pipe' error occurred while writing " +
|
||||||
"'closure_notify'", cause);
|
"'closure_notify'", cause);
|
||||||
|
}
|
||||||
|
|
||||||
// Close the connection explicitly just in case the transport
|
// Close the connection explicitly just in case the transport
|
||||||
// did not close the connection automatically.
|
// did not close the connection automatically.
|
||||||
@ -1085,10 +1092,13 @@ public class SslHandler extends FrameDecoder
|
|||||||
try {
|
try {
|
||||||
engine.closeInbound();
|
engine.closeInbound();
|
||||||
} catch (SSLException e) {
|
} catch (SSLException e) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"SSLEngine.closeInbound() raised an exception after " +
|
"SSLEngine.closeInbound() raised an exception after " +
|
||||||
"a handshake failure.", e);
|
"a handshake failure.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handshakeFuture.setFailure(cause);
|
handshakeFuture.setFailure(cause);
|
||||||
@ -1106,8 +1116,10 @@ public class SslHandler extends FrameDecoder
|
|||||||
try {
|
try {
|
||||||
unwrap(context, e.getChannel(), ChannelBuffers.EMPTY_BUFFER, 0, 0);
|
unwrap(context, e.getChannel(), ChannelBuffers.EMPTY_BUFFER, 0, 0);
|
||||||
} catch (SSLException ex) {
|
} catch (SSLException ex) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Failed to unwrap before sending a close_notify message", ex);
|
logger.debug("Failed to unwrap before sending a close_notify message", ex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!engine.isInboundDone()) {
|
if (!engine.isInboundDone()) {
|
||||||
if (sentCloseNotify.compareAndSet(false, true)) {
|
if (sentCloseNotify.compareAndSet(false, true)) {
|
||||||
@ -1118,9 +1130,11 @@ public class SslHandler extends FrameDecoder
|
|||||||
new ClosingChannelFutureListener(context, e));
|
new ClosingChannelFutureListener(context, e));
|
||||||
success = true;
|
success = true;
|
||||||
} catch (SSLException ex) {
|
} catch (SSLException ex) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Failed to encode a close_notify message", ex);
|
logger.debug("Failed to encode a close_notify message", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
@ -92,9 +92,11 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
|
|||||||
try {
|
try {
|
||||||
flush(ctx);
|
flush(ctx);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Unexpected exception while sending chunks.", e);
|
logger.warn("Unexpected exception while sending chunks.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
|
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
|
||||||
@ -270,7 +272,9 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
|
|||||||
try {
|
try {
|
||||||
chunks.close();
|
chunks.close();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a chunked input.", t);
|
logger.warn("Failed to close a chunked input.", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,9 @@ public abstract class AbstractSocketSslEchoTest {
|
|||||||
ChannelFuture ccf = cb.connect(new InetSocketAddress(SocketAddresses.LOCALHOST, port));
|
ChannelFuture ccf = cb.connect(new InetSocketAddress(SocketAddresses.LOCALHOST, port));
|
||||||
ccf.awaitUninterruptibly();
|
ccf.awaitUninterruptibly();
|
||||||
if (!ccf.isSuccess()) {
|
if (!ccf.isSuccess()) {
|
||||||
|
if(logger.isErrorEnabled()) {
|
||||||
logger.error("Connection attempt failed", ccf.getCause());
|
logger.error("Connection attempt failed", ccf.getCause());
|
||||||
|
}
|
||||||
sc.close().awaitUninterruptibly();
|
sc.close().awaitUninterruptibly();
|
||||||
}
|
}
|
||||||
assertTrue(ccf.isSuccess());
|
assertTrue(ccf.isSuccess());
|
||||||
@ -238,9 +240,11 @@ public abstract class AbstractSocketSslEchoTest {
|
|||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Unexpected exception from the " +
|
"Unexpected exception from the " +
|
||||||
(server? "server" : "client") + " side", e.getCause());
|
(server? "server" : "client") + " side", e.getCause());
|
||||||
|
}
|
||||||
|
|
||||||
exception.compareAndSet(null, e.getCause());
|
exception.compareAndSet(null, e.getCause());
|
||||||
e.getChannel().close();
|
e.getChannel().close();
|
||||||
|
@ -53,6 +53,7 @@ class DefaultNioSctpChannelConfig extends DefaultSctpChannelConfig implements Ni
|
|||||||
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
||||||
// Recover the integrity of the configuration with a sensible value.
|
// Recover the integrity of the configuration with a sensible value.
|
||||||
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
// Notify the user about misconfiguration.
|
// Notify the user about misconfiguration.
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"writeBufferLowWaterMark cannot be greater than " +
|
"writeBufferLowWaterMark cannot be greater than " +
|
||||||
@ -60,6 +61,7 @@ class DefaultNioSctpChannelConfig extends DefaultSctpChannelConfig implements Ni
|
|||||||
"writeBufferHighWaterMark.");
|
"writeBufferHighWaterMark.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setOption(String key, Object value) {
|
public boolean setOption(String key, Object value) {
|
||||||
|
@ -55,12 +55,14 @@ final class SctpClientChannel extends SctpChannelImpl {
|
|||||||
try {
|
try {
|
||||||
underlayingChannel.close();
|
underlayingChannel.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a partially initialized sctp channel.",
|
"Failed to close a partially initialized socket.",
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return underlayingChannel;
|
return underlayingChannel;
|
||||||
}
|
}
|
||||||
|
@ -324,8 +324,10 @@ class SctpClientPipelineSink extends AbstractChannelSink {
|
|||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a selector.", e);
|
"Failed to close a selector.", e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this.selector = null;
|
this.selector = null;
|
||||||
}
|
}
|
||||||
@ -342,8 +344,10 @@ class SctpClientPipelineSink extends AbstractChannelSink {
|
|||||||
shutdown = false;
|
shutdown = false;
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Unexpected exception in the selector loop.", t);
|
"Unexpected exception in the selector loop.", t);
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent possible consecutive immediate failures.
|
// Prevent possible consecutive immediate failures.
|
||||||
try {
|
try {
|
||||||
|
@ -25,17 +25,12 @@ import com.sun.nio.sctp.ShutdownNotification;
|
|||||||
|
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.Channels;
|
import io.netty.channel.Channels;
|
||||||
import io.netty.logging.InternalLogger;
|
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class SctpNotificationHandler extends AbstractNotificationHandler {
|
class SctpNotificationHandler extends AbstractNotificationHandler {
|
||||||
|
|
||||||
private static final InternalLogger logger =
|
|
||||||
InternalLoggerFactory.getInstance(SctpNotificationHandler.class);
|
|
||||||
|
|
||||||
private final SctpChannelImpl sctpChannel;
|
private final SctpChannelImpl sctpChannel;
|
||||||
private final ChannelPipeline pipeline;
|
private final ChannelPipeline pipeline;
|
||||||
|
|
||||||
|
@ -61,29 +61,37 @@ final class SctpProviderMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (constraintLevel >= 0) {
|
if (constraintLevel >= 0) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Setting the NIO constraint level to: " + constraintLevel);
|
"Setting the NIO constraint level to: " + constraintLevel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (constraintLevel < 0) {
|
if (constraintLevel < 0) {
|
||||||
constraintLevel = detectConstraintLevelFromSystemProperties();
|
constraintLevel = detectConstraintLevelFromSystemProperties();
|
||||||
|
|
||||||
if (constraintLevel < 0) {
|
if (constraintLevel < 0) {
|
||||||
constraintLevel = 2;
|
constraintLevel = 2;
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Couldn't determine the NIO constraint level from " +
|
"Couldn't determine the NIO constraint level from " +
|
||||||
"the system properties; using the safest level (2)");
|
"the system properties; using the safest level (2)");
|
||||||
|
}
|
||||||
} else if (constraintLevel != 0) {
|
} else if (constraintLevel != 0) {
|
||||||
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info(
|
logger.info(
|
||||||
"Using the autodetected NIO constraint level: " +
|
"Using the autodetected NIO constraint level: " +
|
||||||
constraintLevel +
|
constraintLevel +
|
||||||
" (Use better NIO provider for better performance)");
|
" (Use better NIO provider for better performance)");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Using the autodetected NIO constraint level: " +
|
"Using the autodetected NIO constraint level: " +
|
||||||
constraintLevel);
|
constraintLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CONSTRAINT_LEVEL = constraintLevel;
|
CONSTRAINT_LEVEL = constraintLevel;
|
||||||
|
|
||||||
@ -236,7 +244,9 @@ final class SctpProviderMetadata {
|
|||||||
ch.bind(new InetSocketAddress(0));
|
ch.bind(new InetSocketAddress(0));
|
||||||
ch.configureBlocking(false);
|
ch.configureBlocking(false);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to configure a temporary socket.", e);
|
logger.warn("Failed to configure a temporary socket.", e);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +254,9 @@ final class SctpProviderMetadata {
|
|||||||
try {
|
try {
|
||||||
loop = new SelectorLoop();
|
loop = new SelectorLoop();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to open a temporary selector.", e);
|
logger.warn("Failed to open a temporary selector.", e);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +264,9 @@ final class SctpProviderMetadata {
|
|||||||
try {
|
try {
|
||||||
ch.register(loop.selector, 0);
|
ch.register(loop.selector, 0);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to register a temporary selector.", e);
|
logger.warn("Failed to register a temporary selector.", e);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,9 +352,11 @@ final class SctpProviderMetadata {
|
|||||||
try {
|
try {
|
||||||
ch.close();
|
ch.close();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a temporary socket.", e);
|
logger.warn("Failed to close a temporary socket.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (loop != null) {
|
if (loop != null) {
|
||||||
loop.done = true;
|
loop.done = true;
|
||||||
@ -368,10 +384,12 @@ final class SctpProviderMetadata {
|
|||||||
try {
|
try {
|
||||||
loop.selector.close();
|
loop.selector.close();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a temporary selector.", e);
|
logger.warn("Failed to close a temporary selector.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return constraintLevel;
|
return constraintLevel;
|
||||||
}
|
}
|
||||||
@ -406,11 +424,13 @@ final class SctpProviderMetadata {
|
|||||||
}
|
}
|
||||||
keys.clear();
|
keys.clear();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to wait for a temporary selector.", e);
|
logger.warn("Failed to wait for a temporary selector.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
for (Entry<Object, Object> e: System.getProperties().entrySet()) {
|
for (Entry<Object, Object> e: System.getProperties().entrySet()) {
|
||||||
|
@ -73,8 +73,10 @@ class SctpServerChannelImpl extends AbstractServerChannel
|
|||||||
try {
|
try {
|
||||||
serverChannel.close();
|
serverChannel.close();
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a partially initialized sctp channel.", e2);
|
"Failed to close a partially initialized socket.", e2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ChannelException("Failed to enter non-blocking mode.", e);
|
throw new ChannelException("Failed to enter non-blocking mode.", e);
|
||||||
|
@ -281,8 +281,10 @@ class SctpServerPipelineSink extends AbstractChannelSink {
|
|||||||
// Closed as requested.
|
// Closed as requested.
|
||||||
break;
|
break;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to accept a connection.", e);
|
"Failed to accept a connection.", e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
@ -306,25 +308,31 @@ class SctpServerPipelineSink extends AbstractChannelSink {
|
|||||||
SctpServerPipelineSink.this, acceptedSocket,
|
SctpServerPipelineSink.this, acceptedSocket,
|
||||||
worker, currentThread), null);
|
worker, currentThread), null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to initialize an accepted socket.", e);
|
"Failed to initialize an accepted socket.", e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
acceptedSocket.close();
|
acceptedSocket.close();
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a partially accepted socket.",
|
"Failed to close a partially accepted socket.",
|
||||||
e2);
|
e2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void closeSelector() {
|
private void closeSelector() {
|
||||||
channel.selector = null;
|
channel.selector = null;
|
||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a selector.", e);
|
logger.warn("Failed to close a selector.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,10 @@ class SctpWorker implements Runnable {
|
|||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a selector.", t);
|
logger.warn("Failed to close a selector.", t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.selector = selector = null;
|
this.selector = selector = null;
|
||||||
// The method will return to the caller at this point.
|
// The method will return to the caller at this point.
|
||||||
}
|
}
|
||||||
@ -204,8 +206,10 @@ class SctpWorker implements Runnable {
|
|||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a selector.", e);
|
"Failed to close a selector.", e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this.selector = null;
|
this.selector = null;
|
||||||
}
|
}
|
||||||
@ -222,9 +226,10 @@ class SctpWorker implements Runnable {
|
|||||||
shutdown = false;
|
shutdown = false;
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Unexpected exception in the selector loop.", t);
|
"Unexpected exception in the selector loop.", t);
|
||||||
|
}
|
||||||
// Prevent possible consecutive immediate failures that lead to
|
// Prevent possible consecutive immediate failures that lead to
|
||||||
// excessive CPU consumption.
|
// excessive CPU consumption.
|
||||||
try {
|
try {
|
||||||
@ -313,7 +318,9 @@ class SctpWorker implements Runnable {
|
|||||||
if (!messageInfo.isUnordered()) {
|
if (!messageInfo.isUnordered()) {
|
||||||
failure = false;
|
failure = false;
|
||||||
} else {
|
} else {
|
||||||
|
if (logger.isErrorEnabled()) {
|
||||||
logger.error("Received unordered SCTP Packet");
|
logger.error("Received unordered SCTP Packet");
|
||||||
|
}
|
||||||
failure = true;
|
failure = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,11 +32,14 @@ final class SelectorUtil {
|
|||||||
try {
|
try {
|
||||||
selector.select(10); // does small timeout give more throughput + less CPU usage?
|
selector.select(10); // does small timeout give more throughput + less CPU usage?
|
||||||
} catch (CancelledKeyException e) {
|
} catch (CancelledKeyException e) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
// Harmless exception - log anyway
|
// Harmless exception - log anyway
|
||||||
logger.debug(
|
logger.debug(
|
||||||
CancelledKeyException.class.getSimpleName() +
|
CancelledKeyException.class.getSimpleName() +
|
||||||
" raised by a Selector - JDK bug?", e);
|
" raised by a Selector - JDK bug?", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SelectorUtil() {
|
private SelectorUtil() {
|
||||||
|
@ -48,11 +48,13 @@ public abstract class CompleteChannelFuture implements ChannelFuture {
|
|||||||
try {
|
try {
|
||||||
listener.operationComplete(this);
|
listener.operationComplete(this);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"An exception was thrown by " +
|
"An exception was thrown by " +
|
||||||
ChannelFutureListener.class.getSimpleName() + ".", t);
|
ChannelFutureListener.class.getSimpleName() + ".", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeListener(ChannelFutureListener listener) {
|
public void removeListener(ChannelFutureListener listener) {
|
||||||
|
@ -56,11 +56,13 @@ public class DefaultChannelFuture implements ChannelFuture {
|
|||||||
public static void setUseDeadLockChecker(boolean useDeadLockChecker) {
|
public static void setUseDeadLockChecker(boolean useDeadLockChecker) {
|
||||||
if (!useDeadLockChecker && !disabledDeadLockCheckerOnce) {
|
if (!useDeadLockChecker && !disabledDeadLockCheckerOnce) {
|
||||||
disabledDeadLockCheckerOnce = true;
|
disabledDeadLockCheckerOnce = true;
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"The dead lock checker in " +
|
"The dead lock checker in " +
|
||||||
DefaultChannelFuture.class.getSimpleName() +
|
DefaultChannelFuture.class.getSimpleName() +
|
||||||
" has been disabled as requested at your own risk.");
|
" has been disabled as requested at your own risk.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
DefaultChannelFuture.useDeadLockChecker = useDeadLockChecker;
|
DefaultChannelFuture.useDeadLockChecker = useDeadLockChecker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,11 +415,13 @@ public class DefaultChannelFuture implements ChannelFuture {
|
|||||||
try {
|
try {
|
||||||
l.operationComplete(this);
|
l.operationComplete(this);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"An exception was thrown by " +
|
"An exception was thrown by " +
|
||||||
ChannelFutureListener.class.getSimpleName() + ".", t);
|
ChannelFutureListener.class.getSimpleName() + ".", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setProgress(long amount, long current, long total) {
|
public boolean setProgress(long amount, long current, long total) {
|
||||||
@ -453,9 +457,11 @@ public class DefaultChannelFuture implements ChannelFuture {
|
|||||||
try {
|
try {
|
||||||
l.operationProgressed(this, amount, current, total);
|
l.operationProgressed(this, amount, current, total);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"An exception was thrown by " +
|
"An exception was thrown by " +
|
||||||
ChannelFutureProgressListener.class.getSimpleName() + ".", t);
|
ChannelFutureProgressListener.class.getSimpleName() + ".", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,8 +357,10 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
remove((DefaultChannelHandlerContext) ctx);
|
remove((DefaultChannelHandlerContext) ctx);
|
||||||
removed = true;
|
removed = true;
|
||||||
} catch (Throwable t2) {
|
} catch (Throwable t2) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to remove a handler: " + ctx.getName(), t2);
|
logger.warn("Failed to remove a handler: " + ctx.getName(), t2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (removed) {
|
if (removed) {
|
||||||
throw new ChannelHandlerLifeCycleException(
|
throw new ChannelHandlerLifeCycleException(
|
||||||
@ -564,8 +566,9 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
public void sendUpstream(ChannelEvent e) {
|
public void sendUpstream(ChannelEvent e) {
|
||||||
DefaultChannelHandlerContext head = getActualUpstreamContext(this.head);
|
DefaultChannelHandlerContext head = getActualUpstreamContext(this.head);
|
||||||
if (head == null) {
|
if (head == null) {
|
||||||
logger.warn(
|
if (logger.isWarnEnabled()) {
|
||||||
"The pipeline contains no upstream handlers; discarding: " + e);
|
logger.warn("The pipeline contains no upstream handlers; discarding: " + e);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,9 +651,11 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
|
|
||||||
protected void notifyHandlerException(ChannelEvent e, Throwable t) {
|
protected void notifyHandlerException(ChannelEvent e, Throwable t) {
|
||||||
if (e instanceof ExceptionEvent) {
|
if (e instanceof ExceptionEvent) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"An exception was thrown by a user handler " +
|
"An exception was thrown by a user handler " +
|
||||||
"while handling an exception event (" + e + ")", t);
|
"while handling an exception event (" + e + ")", t);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -664,9 +669,11 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
try {
|
try {
|
||||||
sink.exceptionCaught(this, e, pe);
|
sink.exceptionCaught(this, e, pe);
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("An exception was thrown by an exception handler.", e1);
|
logger.warn("An exception was thrown by an exception handler.", e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void init(String name, ChannelHandler handler) {
|
private void init(String name, ChannelHandler handler) {
|
||||||
DefaultChannelHandlerContext ctx = new DefaultChannelHandlerContext(null, null, name, handler);
|
DefaultChannelHandlerContext ctx = new DefaultChannelHandlerContext(null, null, name, handler);
|
||||||
@ -815,8 +822,10 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) {
|
public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Not attached yet; discarding: " + e);
|
logger.warn("Not attached yet; discarding: " + e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelPipeline pipeline,
|
public void exceptionCaught(ChannelPipeline pipeline,
|
||||||
|
@ -81,7 +81,9 @@ public class DefaultFileRegion implements FileRegion {
|
|||||||
try {
|
try {
|
||||||
file.close();
|
file.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a file.", e);
|
logger.warn("Failed to close a file.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -382,9 +382,11 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
|
|||||||
try {
|
try {
|
||||||
l.operationComplete(this);
|
l.operationComplete(this);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"An exception was thrown by " +
|
"An exception was thrown by " +
|
||||||
ChannelFutureListener.class.getSimpleName() + ".", t);
|
ChannelFutureListener.class.getSimpleName() + ".", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,8 +116,10 @@ final class LocalClientChannelSink extends AbstractChannelSink {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
future.setFailure(e);
|
future.setFailure(e);
|
||||||
fireExceptionCaught(channel, e);
|
fireExceptionCaught(channel, e);
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to initialize an accepted socket.", e);
|
"Failed to initialize an accepted socket.", e);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,11 +47,14 @@ class DefaultNioDatagramChannelConfig extends DefaultDatagramChannelConfig
|
|||||||
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
||||||
// Recover the integrity of the configuration with a sensible value.
|
// Recover the integrity of the configuration with a sensible value.
|
||||||
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
// Notify the user about misconfiguration.
|
// Notify the user about misconfiguration.
|
||||||
logger.warn("writeBufferLowWaterMark cannot be greater than "
|
logger.warn("writeBufferLowWaterMark cannot be greater than "
|
||||||
+ "writeBufferHighWaterMark; setting to the half of the "
|
+ "writeBufferHighWaterMark; setting to the half of the "
|
||||||
+ "writeBufferHighWaterMark.");
|
+ "writeBufferHighWaterMark.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,12 +55,15 @@ class DefaultNioSocketChannelConfig extends DefaultSocketChannelConfig
|
|||||||
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
||||||
// Recover the integrity of the configuration with a sensible value.
|
// Recover the integrity of the configuration with a sensible value.
|
||||||
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
// Notify the user about misconfiguration.
|
// Notify the user about misconfiguration.
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"writeBufferLowWaterMark cannot be greater than " +
|
"writeBufferLowWaterMark cannot be greater than " +
|
||||||
"writeBufferHighWaterMark; setting to the half of the " +
|
"writeBufferHighWaterMark; setting to the half of the " +
|
||||||
"writeBufferHighWaterMark.");
|
"writeBufferHighWaterMark.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.channel.socket.nio;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.WritableByteChannel;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special {@link ChannelConfig} sub-type which offers extra methods which are useful for NIO.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface NioChannelConfig extends ChannelConfig{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the high water mark of the write buffer. If the number of bytes
|
||||||
|
* queued in the write buffer exceeds this value, {@link Channel#isWritable()}
|
||||||
|
* will start to return {@code true}.
|
||||||
|
*/
|
||||||
|
int getWriteBufferHighWaterMark();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the high water mark of the write buffer. If the number of bytes
|
||||||
|
* queued in the write buffer exceeds this value, {@link Channel#isWritable()}
|
||||||
|
* will start to return {@code true}.
|
||||||
|
*/
|
||||||
|
void setWriteBufferHighWaterMark(int writeBufferHighWaterMark);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the low water mark of the write buffer. Once the number of bytes
|
||||||
|
* queued in the write buffer exceeded the
|
||||||
|
* {@linkplain #setWriteBufferHighWaterMark(int) high water mark} and then
|
||||||
|
* dropped down below this value, {@link Channel#isWritable()} will return
|
||||||
|
* {@code false} again.
|
||||||
|
*/
|
||||||
|
int getWriteBufferLowWaterMark();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the low water mark of the write buffer. Once the number of bytes
|
||||||
|
* queued in the write buffer exceeded the
|
||||||
|
* {@linkplain #setWriteBufferHighWaterMark(int) high water mark} and then
|
||||||
|
* dropped down below this value, {@link Channel#isWritable()} will return
|
||||||
|
* {@code false} again.
|
||||||
|
*/
|
||||||
|
void setWriteBufferLowWaterMark(int writeBufferLowWaterMark);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the maximum loop count for a write operation until
|
||||||
|
* {@link WritableByteChannel#write(ByteBuffer)} returns a non-zero value.
|
||||||
|
* It is similar to what a spin lock is used for in concurrency programming.
|
||||||
|
* It improves memory utilization and write throughput depending on
|
||||||
|
* the platform that JVM runs on. The default value is {@code 16}.
|
||||||
|
*/
|
||||||
|
int getWriteSpinCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the maximum loop count for a write operation until
|
||||||
|
* {@link WritableByteChannel#write(ByteBuffer)} returns a non-zero value.
|
||||||
|
* It is similar to what a spin lock is used for in concurrency programming.
|
||||||
|
* It improves memory utilization and write throughput depending on
|
||||||
|
* the platform that JVM runs on. The default value is {@code 16}.
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* if the specified value is {@code 0} or less than {@code 0}
|
||||||
|
*/
|
||||||
|
void setWriteSpinCount(int writeSpinCount);
|
||||||
|
}
|
@ -52,10 +52,13 @@ final class NioClientSocketChannel extends NioSocketChannel {
|
|||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a partially initialized socket.",
|
"Failed to close a partially initialized socket.",
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,8 +208,10 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
|
|||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a selector.", t);
|
logger.warn("Failed to close a selector.", t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.selector = selector = null;
|
this.selector = selector = null;
|
||||||
// The method will return to the caller at this point.
|
// The method will return to the caller at this point.
|
||||||
}
|
}
|
||||||
@ -302,8 +304,11 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
|
|||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a selector.", e);
|
"Failed to close a selector.", e);
|
||||||
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
this.selector = null;
|
this.selector = null;
|
||||||
}
|
}
|
||||||
@ -320,8 +325,11 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
|
|||||||
shutdown = false;
|
shutdown = false;
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Unexpected exception in the selector loop.", t);
|
"Unexpected exception in the selector loop.", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Prevent possible consecutive immediate failures.
|
// Prevent possible consecutive immediate failures.
|
||||||
try {
|
try {
|
||||||
|
@ -15,10 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.channel.socket.nio;
|
package io.netty.channel.socket.nio;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.channels.WritableByteChannel;
|
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelConfig;
|
import io.netty.channel.ChannelConfig;
|
||||||
import io.netty.channel.socket.DatagramChannel;
|
import io.netty.channel.socket.DatagramChannel;
|
||||||
import io.netty.channel.socket.DatagramChannelConfig;
|
import io.netty.channel.socket.DatagramChannelConfig;
|
||||||
@ -44,58 +40,7 @@ import io.netty.channel.socket.DatagramChannelConfig;
|
|||||||
* </tr><tr>
|
* </tr><tr>
|
||||||
* </table>
|
* </table>
|
||||||
*/
|
*/
|
||||||
public interface NioDatagramChannelConfig extends DatagramChannelConfig {
|
public interface NioDatagramChannelConfig extends DatagramChannelConfig, NioChannelConfig {
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the high water mark of the write buffer. If the number of bytes
|
|
||||||
* queued in the write buffer exceeds this value, {@link Channel#isWritable()}
|
|
||||||
* will start to return {@code true}.
|
|
||||||
*/
|
|
||||||
int getWriteBufferHighWaterMark();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the high water mark of the write buffer. If the number of bytes
|
|
||||||
* queued in the write buffer exceeds this value, {@link Channel#isWritable()}
|
|
||||||
* will start to return {@code true}.
|
|
||||||
*/
|
|
||||||
void setWriteBufferHighWaterMark(int writeBufferHighWaterMark);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the low water mark of the write buffer. Once the number of bytes
|
|
||||||
* queued in the write buffer exceeded the
|
|
||||||
* {@linkplain #setWriteBufferHighWaterMark(int) high water mark} and then
|
|
||||||
* dropped down below this value, {@link Channel#isWritable()} will return
|
|
||||||
* {@code false} again.
|
|
||||||
*/
|
|
||||||
int getWriteBufferLowWaterMark();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the low water mark of the write buffer. Once the number of bytes
|
|
||||||
* queued in the write buffer exceeded the
|
|
||||||
* {@linkplain #setWriteBufferHighWaterMark(int) high water mark} and then
|
|
||||||
* dropped down below this value, {@link Channel#isWritable()} will return
|
|
||||||
* {@code false} again.
|
|
||||||
*/
|
|
||||||
void setWriteBufferLowWaterMark(int writeBufferLowWaterMark);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the maximum loop count for a write operation until
|
|
||||||
* {@link WritableByteChannel#write(ByteBuffer)} returns a non-zero value.
|
|
||||||
* It is similar to what a spin lock is used for in concurrency programming.
|
|
||||||
* It improves memory utilization and write throughput depending on
|
|
||||||
* the platform that JVM runs on. The default value is {@code 16}.
|
|
||||||
*/
|
|
||||||
int getWriteSpinCount();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the maximum loop count for a write operation until
|
|
||||||
* {@link WritableByteChannel#write(ByteBuffer)} returns a non-zero value.
|
|
||||||
* It is similar to what a spin lock is used for in concurrency programming.
|
|
||||||
* It improves memory utilization and write throughput depending on
|
|
||||||
* the platform that JVM runs on. The default value is {@code 16}.
|
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the specified value is {@code 0} or less than {@code 0}
|
|
||||||
*/
|
|
||||||
void setWriteSpinCount(int writeSpinCount);
|
|
||||||
}
|
}
|
||||||
|
@ -155,8 +155,10 @@ class NioDatagramWorker implements Runnable {
|
|||||||
// Release the Selector if the execution fails.
|
// Release the Selector if the execution fails.
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (final Throwable t) {
|
} catch (final Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a selector.", t);
|
logger.warn("Failed to close a selector.", t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.selector = selector = null;
|
this.selector = selector = null;
|
||||||
// The method will return to the caller at this point.
|
// The method will return to the caller at this point.
|
||||||
}
|
}
|
||||||
|
@ -70,19 +70,26 @@ final class NioProviderMetadata {
|
|||||||
|
|
||||||
if (constraintLevel < 0) {
|
if (constraintLevel < 0) {
|
||||||
constraintLevel = 2;
|
constraintLevel = 2;
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Couldn't determine the NIO constraint level from " +
|
"Couldn't determine the NIO constraint level from " +
|
||||||
"the system properties; using the safest level (2)");
|
"the system properties; using the safest level (2)");
|
||||||
|
}
|
||||||
} else if (constraintLevel != 0) {
|
} else if (constraintLevel != 0) {
|
||||||
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info(
|
logger.info(
|
||||||
"Using the autodetected NIO constraint level: " +
|
"Using the autodetected NIO constraint level: " +
|
||||||
constraintLevel +
|
constraintLevel +
|
||||||
" (Use better NIO provider for better performance)");
|
" (Use better NIO provider for better performance)");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Using the autodetected NIO constraint level: " +
|
"Using the autodetected NIO constraint level: " +
|
||||||
constraintLevel);
|
constraintLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CONSTRAINT_LEVEL = constraintLevel;
|
CONSTRAINT_LEVEL = constraintLevel;
|
||||||
@ -235,7 +242,9 @@ final class NioProviderMetadata {
|
|||||||
ch.socket().bind(new InetSocketAddress(0));
|
ch.socket().bind(new InetSocketAddress(0));
|
||||||
ch.configureBlocking(false);
|
ch.configureBlocking(false);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to configure a temporary socket.", e);
|
logger.warn("Failed to configure a temporary socket.", e);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +252,9 @@ final class NioProviderMetadata {
|
|||||||
try {
|
try {
|
||||||
loop = new SelectorLoop();
|
loop = new SelectorLoop();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to open a temporary selector.", e);
|
logger.warn("Failed to open a temporary selector.", e);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +262,9 @@ final class NioProviderMetadata {
|
|||||||
try {
|
try {
|
||||||
ch.register(loop.selector, 0);
|
ch.register(loop.selector, 0);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to register a temporary selector.", e);
|
logger.warn("Failed to register a temporary selector.", e);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,9 +350,11 @@ final class NioProviderMetadata {
|
|||||||
try {
|
try {
|
||||||
ch.close();
|
ch.close();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a temporary socket.", e);
|
logger.warn("Failed to close a temporary socket.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (loop != null) {
|
if (loop != null) {
|
||||||
loop.done = true;
|
loop.done = true;
|
||||||
@ -367,10 +382,12 @@ final class NioProviderMetadata {
|
|||||||
try {
|
try {
|
||||||
loop.selector.close();
|
loop.selector.close();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a temporary selector.", e);
|
logger.warn("Failed to close a temporary selector.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return constraintLevel;
|
return constraintLevel;
|
||||||
}
|
}
|
||||||
@ -405,11 +422,13 @@ final class NioProviderMetadata {
|
|||||||
}
|
}
|
||||||
keys.clear();
|
keys.clear();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to wait for a temporary selector.", e);
|
logger.warn("Failed to wait for a temporary selector.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
for (Entry<Object, Object> e: System.getProperties().entrySet()) {
|
for (Entry<Object, Object> e: System.getProperties().entrySet()) {
|
||||||
|
@ -73,10 +73,13 @@ final class NioServerSocketChannel extends AbstractServerChannel
|
|||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a partially initialized socket.", e2);
|
"Failed to close a partially initialized socket.", e2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
throw new ChannelException("Failed to enter non-blocking mode.", e);
|
throw new ChannelException("Failed to enter non-blocking mode.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,8 +243,10 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
|
|||||||
// Closed as requested.
|
// Closed as requested.
|
||||||
break;
|
break;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to accept a connection.", e);
|
"Failed to accept a connection.", e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
@ -266,25 +268,31 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
|
|||||||
worker.register(NioAcceptedSocketChannel.create(channel.getFactory(), pipeline, channel,
|
worker.register(NioAcceptedSocketChannel.create(channel.getFactory(), pipeline, channel,
|
||||||
NioServerSocketPipelineSink.this, acceptedSocket, worker, currentThread), null);
|
NioServerSocketPipelineSink.this, acceptedSocket, worker, currentThread), null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to initialize an accepted socket.", e);
|
"Failed to initialize an accepted socket.", e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
acceptedSocket.close();
|
acceptedSocket.close();
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a partially accepted socket.",
|
"Failed to close a partially accepted socket.",
|
||||||
e2);
|
e2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void closeSelector() {
|
private void closeSelector() {
|
||||||
channel.selector = null;
|
channel.selector = null;
|
||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a selector.", e);
|
logger.warn("Failed to close a selector.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.channel.socket.nio;
|
package io.netty.channel.socket.nio;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.channels.WritableByteChannel;
|
|
||||||
|
|
||||||
import io.netty.channel.AdaptiveReceiveBufferSizePredictor;
|
import io.netty.channel.AdaptiveReceiveBufferSizePredictor;
|
||||||
import io.netty.channel.AdaptiveReceiveBufferSizePredictorFactory;
|
import io.netty.channel.AdaptiveReceiveBufferSizePredictorFactory;
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelConfig;
|
import io.netty.channel.ChannelConfig;
|
||||||
import io.netty.channel.ReceiveBufferSizePredictor;
|
import io.netty.channel.ReceiveBufferSizePredictor;
|
||||||
import io.netty.channel.ReceiveBufferSizePredictorFactory;
|
import io.netty.channel.ReceiveBufferSizePredictorFactory;
|
||||||
@ -52,60 +48,8 @@ import io.netty.channel.socket.SocketChannelConfig;
|
|||||||
* </tr>
|
* </tr>
|
||||||
* </table>
|
* </table>
|
||||||
*/
|
*/
|
||||||
public interface NioSocketChannelConfig extends SocketChannelConfig {
|
public interface NioSocketChannelConfig extends SocketChannelConfig, NioChannelConfig {
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the high water mark of the write buffer. If the number of bytes
|
|
||||||
* queued in the write buffer exceeds this value, {@link Channel#isWritable()}
|
|
||||||
* will start to return {@code false}.
|
|
||||||
*/
|
|
||||||
int getWriteBufferHighWaterMark();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the high water mark of the write buffer. If the number of bytes
|
|
||||||
* queued in the write buffer exceeds this value, {@link Channel#isWritable()}
|
|
||||||
* will start to return {@code false}.
|
|
||||||
*/
|
|
||||||
void setWriteBufferHighWaterMark(int writeBufferHighWaterMark);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the low water mark of the write buffer. Once the number of bytes
|
|
||||||
* queued in the write buffer exceeded the
|
|
||||||
* {@linkplain #setWriteBufferHighWaterMark(int) high water mark} and then
|
|
||||||
* dropped down below this value, {@link Channel#isWritable()} will return
|
|
||||||
* {@code true} again.
|
|
||||||
*/
|
|
||||||
int getWriteBufferLowWaterMark();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the low water mark of the write buffer. Once the number of bytes
|
|
||||||
* queued in the write buffer exceeded the
|
|
||||||
* {@linkplain #setWriteBufferHighWaterMark(int) high water mark} and then
|
|
||||||
* dropped down below this value, {@link Channel#isWritable()} will return
|
|
||||||
* {@code true} again.
|
|
||||||
*/
|
|
||||||
void setWriteBufferLowWaterMark(int writeBufferLowWaterMark);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the maximum loop count for a write operation until
|
|
||||||
* {@link WritableByteChannel#write(ByteBuffer)} returns a non-zero value.
|
|
||||||
* It is similar to what a spin lock is used for in concurrency programming.
|
|
||||||
* It improves memory utilization and write throughput depending on
|
|
||||||
* the platform that JVM runs on. The default value is {@code 16}.
|
|
||||||
*/
|
|
||||||
int getWriteSpinCount();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the maximum loop count for a write operation until
|
|
||||||
* {@link WritableByteChannel#write(ByteBuffer)} returns a non-zero value.
|
|
||||||
* It is similar to what a spin lock is used for in concurrency programming.
|
|
||||||
* It improves memory utilization and write throughput depending on
|
|
||||||
* the platform that JVM runs on. The default value is {@code 16}.
|
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the specified value is {@code 0} or less than {@code 0}
|
|
||||||
*/
|
|
||||||
void setWriteSpinCount(int writeSpinCount);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link ReceiveBufferSizePredictor} which predicts the
|
* Returns the {@link ReceiveBufferSizePredictor} which predicts the
|
||||||
|
@ -103,8 +103,10 @@ class NioWorker implements Runnable {
|
|||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Failed to close a selector.", t);
|
logger.warn("Failed to close a selector.", t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.selector = selector = null;
|
this.selector = selector = null;
|
||||||
// The method will return to the caller at this point.
|
// The method will return to the caller at this point.
|
||||||
}
|
}
|
||||||
@ -197,8 +199,10 @@ class NioWorker implements Runnable {
|
|||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a selector.", e);
|
"Failed to close a selector.", e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this.selector = null;
|
this.selector = null;
|
||||||
}
|
}
|
||||||
@ -215,8 +219,11 @@ class NioWorker implements Runnable {
|
|||||||
shutdown = false;
|
shutdown = false;
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Unexpected exception in the selector loop.", t);
|
"Unexpected exception in the selector loop.", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Prevent possible consecutive immediate failures that lead to
|
// Prevent possible consecutive immediate failures that lead to
|
||||||
// excessive CPU consumption.
|
// excessive CPU consumption.
|
||||||
|
@ -32,11 +32,14 @@ final class SelectorUtil {
|
|||||||
try {
|
try {
|
||||||
selector.select(500);
|
selector.select(500);
|
||||||
} catch (CancelledKeyException e) {
|
} catch (CancelledKeyException e) {
|
||||||
// Harmless exception - log anyway
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
CancelledKeyException.class.getSimpleName() +
|
CancelledKeyException.class.getSimpleName() +
|
||||||
" raised by a Selector - JDK bug?", e);
|
" raised by a Selector - JDK bug?", e);
|
||||||
}
|
}
|
||||||
|
// Harmless exception - log anyway
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SelectorUtil() {
|
private SelectorUtil() {
|
||||||
|
@ -72,9 +72,12 @@ final class OioServerSocketChannel extends AbstractServerChannel
|
|||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a partially initialized socket.", e2);
|
"Failed to close a partially initialized socket.", e2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
throw new ChannelException(
|
throw new ChannelException(
|
||||||
"Failed to set the server socket timeout.", e);
|
"Failed to set the server socket timeout.", e);
|
||||||
}
|
}
|
||||||
|
@ -203,16 +203,20 @@ class OioServerSocketPipelineSink extends AbstractChannelSink {
|
|||||||
workerExecutor,
|
workerExecutor,
|
||||||
new OioWorker(acceptedChannel));
|
new OioWorker(acceptedChannel));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to initialize an accepted socket.", e);
|
"Failed to initialize an accepted socket.", e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
acceptedSocket.close();
|
acceptedSocket.close();
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to close a partially accepted socket.",
|
"Failed to close a partially accepted socket.",
|
||||||
e2);
|
e2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (SocketTimeoutException e) {
|
} catch (SocketTimeoutException e) {
|
||||||
// Thrown every second to stop when requested.
|
// Thrown every second to stop when requested.
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -222,8 +226,11 @@ class OioServerSocketPipelineSink extends AbstractChannelSink {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Failed to accept a connection.", e);
|
"Failed to accept a connection.", e);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user