Fit every line into 120 columns
This commit is contained in:
parent
e1a006cac4
commit
468a3228a4
@ -39,11 +39,10 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
* <h3>Random Access Indexing</h3>
|
||||
*
|
||||
* Just like an ordinary primitive byte array, {@link ChannelBuffer} uses
|
||||
* <a href="http://en.wikipedia.org/wiki/Index_(information_technology)#Array_element_identifier">zero-based indexing</a>.
|
||||
* It means the index of the first byte is always {@code 0} and the index of
|
||||
* the last byte is always {@link #capacity() capacity - 1}. For example, to
|
||||
* iterate all bytes of a buffer, you can do the following, regardless of
|
||||
* its internal implementation:
|
||||
* <a href="http://en.wikipedia.org/wiki/Zero-based_numbering">zero-based indexing</a>.
|
||||
* It means the index of the first byte is always {@code 0} and the index of the last byte is
|
||||
* always {@link #capacity() capacity - 1}. For example, to iterate all bytes of a buffer, you
|
||||
* can do the following, regardless of its internal implementation:
|
||||
*
|
||||
* <pre>
|
||||
* {@link ChannelBuffer} buffer = ...;
|
||||
|
@ -226,7 +226,8 @@ public final class ChannelBuffers {
|
||||
* More accurate estimation yields less unexpected reallocation overhead.
|
||||
* The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer dynamicBuffer(ByteOrder endianness, int estimatedLength, ChannelBufferFactory factory) {
|
||||
public static ChannelBuffer dynamicBuffer(
|
||||
ByteOrder endianness, int estimatedLength, ChannelBufferFactory factory) {
|
||||
return new DynamicChannelBuffer(endianness, estimatedLength, factory);
|
||||
}
|
||||
|
||||
@ -1249,7 +1250,8 @@ public final class ChannelBuffers {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int firstIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
private static int firstIndexOf(
|
||||
ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
fromIndex = Math.max(fromIndex, 0);
|
||||
if (fromIndex >= toIndex || buffer.capacity() == 0) {
|
||||
return -1;
|
||||
@ -1264,7 +1266,8 @@ public final class ChannelBuffers {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int lastIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
private static int lastIndexOf(
|
||||
ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
fromIndex = Math.min(fromIndex, buffer.capacity());
|
||||
if (fromIndex < 0 || buffer.capacity() == 0) {
|
||||
return -1;
|
||||
|
@ -56,11 +56,11 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
|
||||
private final Object bigEndianLock = new Object();
|
||||
private final Object littleEndianLock = new Object();
|
||||
private final int preallocatedBufferCapacity;
|
||||
private ChannelBuffer preallocatedBigEndianBuffer;
|
||||
private int preallocatedBigEndianBufferPosition;
|
||||
private ChannelBuffer preallocatedLittleEndianBuffer;
|
||||
private int preallocatedLittleEndianBufferPosition;
|
||||
private final int preallocatedBufCapacity;
|
||||
private ChannelBuffer preallocatedBEBuf;
|
||||
private int preallocatedBEBufPos;
|
||||
private ChannelBuffer preallocatedLEBuf;
|
||||
private int preallocatedLEBufPos;
|
||||
|
||||
/**
|
||||
* Creates a new factory whose default {@link ByteOrder} is
|
||||
@ -96,10 +96,10 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
super(defaultOrder);
|
||||
if (preallocatedBufferCapacity <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"preallocatedBufferCapacity must be greater than 0: " + preallocatedBufferCapacity);
|
||||
"preallocatedBufCapacity must be greater than 0: " + preallocatedBufferCapacity);
|
||||
}
|
||||
|
||||
this.preallocatedBufferCapacity = preallocatedBufferCapacity;
|
||||
preallocatedBufCapacity = preallocatedBufferCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,7 +113,7 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
if (capacity == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
if (capacity >= preallocatedBufferCapacity) {
|
||||
if (capacity >= preallocatedBufCapacity) {
|
||||
return ChannelBuffers.directBuffer(order, capacity);
|
||||
}
|
||||
|
||||
@ -163,17 +163,17 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
private ChannelBuffer allocateBigEndianBuffer(int capacity) {
|
||||
ChannelBuffer slice;
|
||||
synchronized (bigEndianLock) {
|
||||
if (preallocatedBigEndianBuffer == null) {
|
||||
preallocatedBigEndianBuffer = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufferCapacity);
|
||||
slice = preallocatedBigEndianBuffer.slice(0, capacity);
|
||||
preallocatedBigEndianBufferPosition = capacity;
|
||||
} else if (preallocatedBigEndianBuffer.capacity() - preallocatedBigEndianBufferPosition >= capacity) {
|
||||
slice = preallocatedBigEndianBuffer.slice(preallocatedBigEndianBufferPosition, capacity);
|
||||
preallocatedBigEndianBufferPosition += capacity;
|
||||
if (preallocatedBEBuf == null) {
|
||||
preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
||||
slice = preallocatedBEBuf.slice(0, capacity);
|
||||
preallocatedBEBufPos = capacity;
|
||||
} else if (preallocatedBEBuf.capacity() - preallocatedBEBufPos >= capacity) {
|
||||
slice = preallocatedBEBuf.slice(preallocatedBEBufPos, capacity);
|
||||
preallocatedBEBufPos += capacity;
|
||||
} else {
|
||||
preallocatedBigEndianBuffer = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufferCapacity);
|
||||
slice = preallocatedBigEndianBuffer.slice(0, capacity);
|
||||
preallocatedBigEndianBufferPosition = capacity;
|
||||
preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
||||
slice = preallocatedBEBuf.slice(0, capacity);
|
||||
preallocatedBEBufPos = capacity;
|
||||
}
|
||||
}
|
||||
return slice;
|
||||
@ -182,17 +182,17 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
private ChannelBuffer allocateLittleEndianBuffer(int capacity) {
|
||||
ChannelBuffer slice;
|
||||
synchronized (littleEndianLock) {
|
||||
if (preallocatedLittleEndianBuffer == null) {
|
||||
preallocatedLittleEndianBuffer = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufferCapacity);
|
||||
slice = preallocatedLittleEndianBuffer.slice(0, capacity);
|
||||
preallocatedLittleEndianBufferPosition = capacity;
|
||||
} else if (preallocatedLittleEndianBuffer.capacity() - preallocatedLittleEndianBufferPosition >= capacity) {
|
||||
slice = preallocatedLittleEndianBuffer.slice(preallocatedLittleEndianBufferPosition, capacity);
|
||||
preallocatedLittleEndianBufferPosition += capacity;
|
||||
if (preallocatedLEBuf == null) {
|
||||
preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
||||
slice = preallocatedLEBuf.slice(0, capacity);
|
||||
preallocatedLEBufPos = capacity;
|
||||
} else if (preallocatedLEBuf.capacity() - preallocatedLEBufPos >= capacity) {
|
||||
slice = preallocatedLEBuf.slice(preallocatedLEBufPos, capacity);
|
||||
preallocatedLEBufPos += capacity;
|
||||
} else {
|
||||
preallocatedLittleEndianBuffer = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufferCapacity);
|
||||
slice = preallocatedLittleEndianBuffer.slice(0, capacity);
|
||||
preallocatedLittleEndianBufferPosition = capacity;
|
||||
preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
||||
slice = preallocatedLEBuf.slice(0, capacity);
|
||||
preallocatedLEBufPos = capacity;
|
||||
}
|
||||
}
|
||||
return slice;
|
||||
|
@ -707,7 +707,8 @@ public class HttpHeaders {
|
||||
|
||||
/**
|
||||
* Adds a new date header with the specified name and value. The specified
|
||||
* value is formatted as defined in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>
|
||||
* value is formatted as defined in
|
||||
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>
|
||||
*/
|
||||
public static void addDateHeader(HttpMessage message, String name, Date value) {
|
||||
message.addHeader(name, value);
|
||||
|
@ -26,28 +26,32 @@ import java.util.Map;
|
||||
*/
|
||||
public class HttpMethod implements Comparable<HttpMethod> {
|
||||
/**
|
||||
* The OPTIONS method represents a request for information about the communication options available on the request/response
|
||||
* chain identified by the Request-URI. This method allows the client to determine the options and/or requirements
|
||||
* associated with a resource, or the capabilities of a server, without implying a resource action or initiating a
|
||||
* resource retrieval.
|
||||
* The OPTIONS method represents a request for information about the communication options
|
||||
* available on the request/response chain identified by the Request-URI. This method allows
|
||||
* the client to determine the options and/or requirements associated with a resource, or the
|
||||
* capabilities of a server, without implying a resource action or initiating a resource
|
||||
* retrieval.
|
||||
*/
|
||||
public static final HttpMethod OPTIONS = new HttpMethod("OPTIONS");
|
||||
|
||||
/**
|
||||
* The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.
|
||||
* If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity
|
||||
* in the response and not the source text of the process, unless that text happens to be the output of the process.
|
||||
* The GET method means retrieve whatever information (in the form of an entity) is identified
|
||||
* by the Request-URI. If the Request-URI refers to a data-producing process, it is the
|
||||
* produced data which shall be returned as the entity in the response and not the source text
|
||||
* of the process, unless that text happens to be the output of the process.
|
||||
*/
|
||||
public static final HttpMethod GET = new HttpMethod("GET");
|
||||
|
||||
/**
|
||||
* The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.
|
||||
* The HEAD method is identical to GET except that the server MUST NOT return a message-body
|
||||
* in the response.
|
||||
*/
|
||||
public static final HttpMethod HEAD = new HttpMethod("HEAD");
|
||||
|
||||
/**
|
||||
* The POST method is used to request that the origin server accept the entity enclosed in the request as a new
|
||||
* subordinate of the resource identified by the Request-URI in the Request-Line.
|
||||
* The POST method is used to request that the origin server accept the entity enclosed in the
|
||||
* request as a new subordinate of the resource identified by the Request-URI in the
|
||||
* Request-Line.
|
||||
*/
|
||||
public static final HttpMethod POST = new HttpMethod("POST");
|
||||
|
||||
@ -63,17 +67,20 @@ public class HttpMethod implements Comparable<HttpMethod> {
|
||||
public static final HttpMethod PATCH = new HttpMethod("PATCH");
|
||||
|
||||
/**
|
||||
* The DELETE method requests that the origin server delete the resource identified by the Request-URI.
|
||||
* The DELETE method requests that the origin server delete the resource identified by the
|
||||
* Request-URI.
|
||||
*/
|
||||
public static final HttpMethod DELETE = new HttpMethod("DELETE");
|
||||
|
||||
/**
|
||||
* The TRACE method is used to invoke a remote, application-layer loop- back of the request message.
|
||||
* The TRACE method is used to invoke a remote, application-layer loop- back of the request
|
||||
* message.
|
||||
*/
|
||||
public static final HttpMethod TRACE = new HttpMethod("TRACE");
|
||||
|
||||
/**
|
||||
* This specification reserves the method name CONNECT for use with a proxy that can dynamically switch to being a tunnel
|
||||
* This specification reserves the method name CONNECT for use with a proxy that can dynamically
|
||||
* switch to being a tunnel
|
||||
*/
|
||||
public static final HttpMethod CONNECT = new HttpMethod("CONNECT");
|
||||
|
||||
|
@ -101,7 +101,9 @@ public class HttpResponseDecoder extends HttpMessageDecoder {
|
||||
|
||||
@Override
|
||||
protected HttpMessage createMessage(String[] initialLine) {
|
||||
return new DefaultHttpResponse(HttpVersion.valueOf(initialLine[0]), new HttpResponseStatus(Integer.valueOf(initialLine[1]), initialLine[2]));
|
||||
return new DefaultHttpResponse(
|
||||
HttpVersion.valueOf(initialLine[0]),
|
||||
new HttpResponseStatus(Integer.valueOf(initialLine[1]), initialLine[2]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,8 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 203 Non-Authoritative Information (since HTTP/1.1)
|
||||
*/
|
||||
public static final HttpResponseStatus NON_AUTHORITATIVE_INFORMATION = new HttpResponseStatus(203, "Non-Authoritative Information");
|
||||
public static final HttpResponseStatus NON_AUTHORITATIVE_INFORMATION =
|
||||
new HttpResponseStatus(203, "Non-Authoritative Information");
|
||||
|
||||
/**
|
||||
* 204 No Content
|
||||
@ -151,7 +152,8 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 407 Proxy Authentication Required
|
||||
*/
|
||||
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED = new HttpResponseStatus(407, "Proxy Authentication Required");
|
||||
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED =
|
||||
new HttpResponseStatus(407, "Proxy Authentication Required");
|
||||
|
||||
/**
|
||||
* 408 Request Timeout
|
||||
@ -181,7 +183,8 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 413 Request Entity Too Large
|
||||
*/
|
||||
public static final HttpResponseStatus REQUEST_ENTITY_TOO_LARGE = new HttpResponseStatus(413, "Request Entity Too Large");
|
||||
public static final HttpResponseStatus REQUEST_ENTITY_TOO_LARGE =
|
||||
new HttpResponseStatus(413, "Request Entity Too Large");
|
||||
|
||||
/**
|
||||
* 414 Request-URI Too Long
|
||||
@ -191,12 +194,14 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 415 Unsupported Media Type
|
||||
*/
|
||||
public static final HttpResponseStatus UNSUPPORTED_MEDIA_TYPE = new HttpResponseStatus(415, "Unsupported Media Type");
|
||||
public static final HttpResponseStatus UNSUPPORTED_MEDIA_TYPE =
|
||||
new HttpResponseStatus(415, "Unsupported Media Type");
|
||||
|
||||
/**
|
||||
* 416 Requested Range Not Satisfiable
|
||||
*/
|
||||
public static final HttpResponseStatus REQUESTED_RANGE_NOT_SATISFIABLE = new HttpResponseStatus(416, "Requested Range Not Satisfiable");
|
||||
public static final HttpResponseStatus REQUESTED_RANGE_NOT_SATISFIABLE =
|
||||
new HttpResponseStatus(416, "Requested Range Not Satisfiable");
|
||||
|
||||
/**
|
||||
* 417 Expectation Failed
|
||||
@ -231,7 +236,8 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 500 Internal Server Error
|
||||
*/
|
||||
public static final HttpResponseStatus INTERNAL_SERVER_ERROR = new HttpResponseStatus(500, "Internal Server Error");
|
||||
public static final HttpResponseStatus INTERNAL_SERVER_ERROR =
|
||||
new HttpResponseStatus(500, "Internal Server Error");
|
||||
|
||||
/**
|
||||
* 501 Not Implemented
|
||||
@ -256,12 +262,14 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 505 HTTP Version Not Supported
|
||||
*/
|
||||
public static final HttpResponseStatus HTTP_VERSION_NOT_SUPPORTED = new HttpResponseStatus(505, "HTTP Version Not Supported");
|
||||
public static final HttpResponseStatus HTTP_VERSION_NOT_SUPPORTED =
|
||||
new HttpResponseStatus(505, "HTTP Version Not Supported");
|
||||
|
||||
/**
|
||||
* 506 Variant Also Negotiates (RFC2295)
|
||||
*/
|
||||
public static final HttpResponseStatus VARIANT_ALSO_NEGOTIATES = new HttpResponseStatus(506, "Variant Also Negotiates");
|
||||
public static final HttpResponseStatus VARIANT_ALSO_NEGOTIATES =
|
||||
new HttpResponseStatus(506, "Variant Also Negotiates");
|
||||
|
||||
/**
|
||||
* 507 Insufficient Storage (WebDAV, RFC4918)
|
||||
|
@ -46,10 +46,10 @@ import java.util.Map;
|
||||
*
|
||||
* <h3>HashDOS vulnerability fix</h3>
|
||||
*
|
||||
* As a workaround to the <a href="http://events.ccc.de/congress/2011/Fahrplan/attachments/2007_28C3_Effective_DoS_on_web_application_platforms.pdf">HashDOS</a>
|
||||
* vulnerability, the decoder limits the maximum number of decoded key-value
|
||||
* parameter pairs, up to {@literal 1024} by default, and you can configure it
|
||||
* when you construct the decoder by passing an additional integer parameter.
|
||||
* As a workaround to the <a href="http://goo.gl/I4Nky">HashDOS</a> vulnerability, the decoder
|
||||
* limits the maximum number of decoded key-value parameter pairs, up to {@literal 1024} by
|
||||
* default, and you can configure it when you construct the decoder by passing an additional
|
||||
* integer parameter.
|
||||
*
|
||||
* @see QueryStringEncoder
|
||||
*
|
||||
|
@ -20,8 +20,8 @@ import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
* Web Socket continuation frame containing continuation text or binary data. This is used for fragmented messages where
|
||||
* the contents of a messages is contained more than 1 frame.
|
||||
* Web Socket continuation frame containing continuation text or binary data. This is used for
|
||||
* fragmented messages where the contents of a messages is contained more than 1 frame.
|
||||
*/
|
||||
public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
@ -35,10 +35,10 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new continuation frame with the specified binary data. The final fragment flag is set to true.
|
||||
* Creates a new continuation frame with the specified binary data. The final fragment flag is
|
||||
* set to true.
|
||||
*
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
* @param binaryData the content of the frame.
|
||||
*/
|
||||
public ContinuationWebSocketFrame(ChannelBuffer binaryData) {
|
||||
setBinaryData(binaryData);
|
||||
@ -70,9 +70,11 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
* @param aggregatedText
|
||||
* Aggregated text set by decoder on the final continuation frame of a fragmented text message
|
||||
* Aggregated text set by decoder on the final continuation frame of a fragmented
|
||||
* text message
|
||||
*/
|
||||
public ContinuationWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData, String aggregatedText) {
|
||||
public ContinuationWebSocketFrame(
|
||||
boolean finalFragment, int rsv, ChannelBuffer binaryData, String aggregatedText) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
setBinaryData(binaryData);
|
||||
|
@ -18,19 +18,20 @@
|
||||
*
|
||||
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
||||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
|
@ -18,19 +18,20 @@
|
||||
*
|
||||
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
||||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
@ -41,20 +42,23 @@ final class UTF8Output {
|
||||
private static final int UTF8_ACCEPT = 0;
|
||||
private static final int UTF8_REJECT = 12;
|
||||
|
||||
private static final byte[] TYPES = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11,
|
||||
6, 6, 6, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
|
||||
private static final byte[] TYPES = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
|
||||
8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6, 6, 5, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8 };
|
||||
|
||||
private static final byte[] STATES = { 0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 24,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12 };
|
||||
private static final byte[] STATES = { 0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12,
|
||||
12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12,
|
||||
12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 36,
|
||||
12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12 };
|
||||
|
||||
private int state = UTF8_ACCEPT;
|
||||
private int codep;
|
||||
|
@ -401,7 +401,8 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkCloseFrameBody(ChannelHandlerContext ctx, ChannelBuffer buffer) throws CorruptedFrameException {
|
||||
protected void checkCloseFrameBody(
|
||||
ChannelHandlerContext ctx, ChannelBuffer buffer) throws CorruptedFrameException {
|
||||
if (buffer == null || buffer.capacity() == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ public class WebSocketClientHandshakerFactory {
|
||||
* Creates a new handshaker.
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param version
|
||||
* Version of web socket specification to use to connect to the server
|
||||
* @param subprotocol
|
||||
@ -48,8 +48,8 @@ public class WebSocketClientHandshakerFactory {
|
||||
* Creates a new handshaker.
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param version
|
||||
* Version of web socket specification to use to connect to the server
|
||||
* @param subprotocol
|
||||
@ -59,20 +59,23 @@ public class WebSocketClientHandshakerFactory {
|
||||
* @param customHeaders
|
||||
* Custom HTTP headers to send during the handshake
|
||||
* @param maxFramePayloadLength
|
||||
* Maximum allowable frame payload length. Setting this value to your application's requirement may
|
||||
* reduce denial of service attacks using long data frames.
|
||||
* Maximum allowable frame payload length. Setting this value to your application's
|
||||
* requirement may reduce denial of service attacks using long data frames.
|
||||
*/
|
||||
public WebSocketClientHandshaker newHandshaker(
|
||||
URI webSocketURL, WebSocketVersion version, String subprotocol,
|
||||
boolean allowExtensions, Map<String, String> customHeaders, int maxFramePayloadLength) {
|
||||
if (version == WebSocketVersion.V13) {
|
||||
return new WebSocketClientHandshaker13(webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
||||
return new WebSocketClientHandshaker13(
|
||||
webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
||||
}
|
||||
if (version == WebSocketVersion.V08) {
|
||||
return new WebSocketClientHandshaker08(webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
||||
return new WebSocketClientHandshaker08(
|
||||
webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
||||
}
|
||||
if (version == WebSocketVersion.V00) {
|
||||
return new WebSocketClientHandshaker00(webSocketURL, version, subprotocol, customHeaders, maxFramePayloadLength);
|
||||
return new WebSocketClientHandshaker00(
|
||||
webSocketURL, version, subprotocol, customHeaders, maxFramePayloadLength);
|
||||
}
|
||||
|
||||
throw new WebSocketHandshakeException("Protocol version " + version.toString() + " not supported.");
|
||||
|
@ -52,17 +52,18 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
* Constructor specifying the destination web socket location
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param subprotocols
|
||||
* CSV of supported protocols
|
||||
* @param allowExtensions
|
||||
* Allow extensions to be used in the reserved bits of the web socket frame
|
||||
* @param maxFramePayloadLength
|
||||
* Maximum allowable frame payload length. Setting this value to your application's requirement may
|
||||
* reduce denial of service attacks using long data frames.
|
||||
* Maximum allowable frame payload length. Setting this value to your application's
|
||||
* requirement may reduce denial of service attacks using long data frames.
|
||||
*/
|
||||
public WebSocketServerHandshaker08(String webSocketURL, String subprotocols, boolean allowExtensions, int maxFramePayloadLength) {
|
||||
public WebSocketServerHandshaker08(
|
||||
String webSocketURL, String subprotocols, boolean allowExtensions, int maxFramePayloadLength) {
|
||||
super(WebSocketVersion.V08, webSocketURL, subprotocols, maxFramePayloadLength);
|
||||
this.allowExtensions = allowExtensions;
|
||||
}
|
||||
|
@ -36,9 +36,7 @@ import io.netty.util.CharsetUtil;
|
||||
/**
|
||||
* <p>
|
||||
* Performs server side opening and closing handshakes for <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a>
|
||||
* (originally web socket specification version <a
|
||||
* href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17" >draft-ietf-hybi-thewebsocketprotocol-
|
||||
* 17</a>).
|
||||
* (originally web socket specification <a href="http://goo.gl/zVBkL">draft-ietf-hybi-thewebsocketprotocol-17</a>).
|
||||
* </p>
|
||||
*/
|
||||
public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
@ -53,17 +51,18 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
* Constructor specifying the destination web socket location
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web
|
||||
* socket frames will be sent to this URL.
|
||||
* @param subprotocols
|
||||
* CSV of supported protocols
|
||||
* @param allowExtensions
|
||||
* Allow extensions to be used in the reserved bits of the web socket frame
|
||||
* @param maxFramePayloadLength
|
||||
* Maximum allowable frame payload length. Setting this value to your application's requirement may
|
||||
* reduce denial of service attacks using long data frames.
|
||||
* Maximum allowable frame payload length. Setting this value to your application's
|
||||
* requirement may reduce denial of service attacks using long data frames.
|
||||
*/
|
||||
public WebSocketServerHandshaker13(String webSocketURL, String subprotocols, boolean allowExtensions, int maxFramePayloadLength) {
|
||||
public WebSocketServerHandshaker13(
|
||||
String webSocketURL, String subprotocols, boolean allowExtensions, int maxFramePayloadLength) {
|
||||
super(WebSocketVersion.V13, webSocketURL, subprotocols, maxFramePayloadLength);
|
||||
this.allowExtensions = allowExtensions;
|
||||
}
|
||||
@ -136,7 +135,8 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
if (subprotocols != null) {
|
||||
String selectedSubprotocol = selectSubprotocol(subprotocols);
|
||||
if (selectedSubprotocol == null) {
|
||||
throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
|
||||
throw new WebSocketHandshakeException(
|
||||
"Requested subprotocol(s) not supported: " + subprotocols);
|
||||
} else {
|
||||
res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
|
||||
setSelectedSubprotocol(selectedSubprotocol);
|
||||
|
@ -40,8 +40,8 @@ public class WebSocketServerHandshakerFactory {
|
||||
* Constructor specifying the destination web socket location
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param subprotocols
|
||||
* CSV of supported protocols. Null if sub protocols not supported.
|
||||
* @param allowExtensions
|
||||
@ -56,15 +56,15 @@ public class WebSocketServerHandshakerFactory {
|
||||
* Constructor specifying the destination web socket location
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param subprotocols
|
||||
* CSV of supported protocols. Null if sub protocols not supported.
|
||||
* @param allowExtensions
|
||||
* Allow extensions to be used in the reserved bits of the web socket frame
|
||||
* @param maxFramePayloadLength
|
||||
* Maximum allowable frame payload length. Setting this value to your application's requirement may
|
||||
* reduce denial of service attacks using long data frames.
|
||||
* Maximum allowable frame payload length. Setting this value to your application's
|
||||
* requirement may reduce denial of service attacks using long data frames.
|
||||
*/
|
||||
public WebSocketServerHandshakerFactory(
|
||||
String webSocketURL, String subprotocols, boolean allowExtensions,
|
||||
@ -78,8 +78,8 @@ public class WebSocketServerHandshakerFactory {
|
||||
/**
|
||||
* Instances a new handshaker
|
||||
*
|
||||
* @return A new WebSocketServerHandshaker for the requested web socket version. Null if web socket version is not
|
||||
* supported.
|
||||
* @return A new WebSocketServerHandshaker for the requested web socket version. Null if web
|
||||
* socket version is not supported.
|
||||
*/
|
||||
public WebSocketServerHandshaker newHandshaker(HttpRequest req) {
|
||||
|
||||
@ -87,10 +87,12 @@ public class WebSocketServerHandshakerFactory {
|
||||
if (version != null) {
|
||||
if (version.equals(WebSocketVersion.V13.toHttpHeaderValue())) {
|
||||
// Version 13 of the wire protocol - RFC 6455 (version 17 of the draft hybi specification).
|
||||
return new WebSocketServerHandshaker13(webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength);
|
||||
return new WebSocketServerHandshaker13(
|
||||
webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength);
|
||||
} else if (version.equals(WebSocketVersion.V08.toHttpHeaderValue())) {
|
||||
// Version 8 of the wire protocol - version 10 of the draft hybi specification.
|
||||
return new WebSocketServerHandshaker08(webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength);
|
||||
return new WebSocketServerHandshaker08(
|
||||
webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -114,5 +116,4 @@ public class WebSocketServerHandshakerFactory {
|
||||
res.setHeader(Names.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
|
||||
channel.write(res);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,10 @@
|
||||
* This package supports different web socket specification versions (hence the X suffix).
|
||||
* The specification current supported are:
|
||||
* <ul>
|
||||
* <li><a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00">draft-ietf-hybi-thewebsocketprotocol-00</a></li>
|
||||
* <li><a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10">draft-ietf-hybi-thewebsocketprotocol-10</a></li>
|
||||
* <li><a href="http://tools.ietf.org/html/rfc6455 ">RFC 6455</a> (originally <a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17">draft-ietf-hybi-thewebsocketprotocol-17</a>)</li>
|
||||
* <li><a href="http://goo.gl/wFiu3">draft-ietf-hybi-thewebsocketprotocol-00</a></li>
|
||||
* <li><a href="http://goo.gl/h27VE">draft-ietf-hybi-thewebsocketprotocol-10</a></li>
|
||||
* <li><a href="http://tools.ietf.org/html/rfc6455 ">RFC 6455</a> (originally
|
||||
* <a href="http://goo.gl/zVBkL">draft-ietf-hybi-thewebsocketprotocol-17</a>)</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
|
@ -27,10 +27,11 @@ import java.util.Map;
|
||||
public final class RtspMethods {
|
||||
|
||||
/**
|
||||
* The OPTIONS method represents a request for information about the communication options available on the request/response
|
||||
* chain identified by the Request-URI. This method allows the client to determine the options and/or requirements
|
||||
* associated with a resource, or the capabilities of a server, without implying a resource action or initiating a
|
||||
* resource retrieval.
|
||||
* The OPTIONS method represents a request for information about the communication options
|
||||
* available on the request/response chain identified by the Request-URI. This method allows
|
||||
* the client to determine the options and/or requirements associated with a resource, or the
|
||||
* capabilities of a server, without implying a resource action or initiating a resource
|
||||
* retrieval.
|
||||
*/
|
||||
public static final HttpMethod OPTIONS = HttpMethod.OPTIONS;
|
||||
|
||||
|
@ -107,7 +107,8 @@ public final class RtspResponseStatuses {
|
||||
/**
|
||||
* 407 Proxy Authentication Required
|
||||
*/
|
||||
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED = HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED;
|
||||
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED =
|
||||
HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED;
|
||||
|
||||
/**
|
||||
* 408 Request Timeout
|
||||
|
@ -239,7 +239,8 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<Object, Object> {
|
||||
httpMessage.removeHeader("Proxy-Connection");
|
||||
httpMessage.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||
|
||||
SpdySynStreamFrame spdySynStreamFrame = new DefaultSpdySynStreamFrame(streamID, associatedToStreamID, priority);
|
||||
SpdySynStreamFrame spdySynStreamFrame =
|
||||
new DefaultSpdySynStreamFrame(streamID, associatedToStreamID, priority);
|
||||
|
||||
// Unfold the first line of the message into name/value pairs
|
||||
if (httpMessage instanceof HttpRequest) {
|
||||
|
@ -777,7 +777,8 @@ public class SpdySessionHandler
|
||||
return false;
|
||||
}
|
||||
spdySession.acceptStream(
|
||||
streamID, priority, remoteSideClosed, localSideClosed, initialSendWindowSize, initialReceiveWindowSize);
|
||||
streamID, priority, remoteSideClosed, localSideClosed,
|
||||
initialSendWindowSize, initialReceiveWindowSize);
|
||||
if (isRemoteInitiatedID(streamID)) {
|
||||
lastGoodStreamID = streamID;
|
||||
}
|
||||
|
@ -52,8 +52,11 @@ public class FixedLengthFrameDecoder extends StreamToMessageDecoder<Object> {
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param frameLength the length of the frame
|
||||
* @param allocateFullBuffer <code>true</code> if the cumulative {@link ChannelBuffer} should use the {@link #frameLength} as its initial size
|
||||
* @param frameLength
|
||||
* the length of the frame
|
||||
* @param allocateFullBuffer
|
||||
* <code>true</code> if the cumulative {@link ChannelBuffer} should use the
|
||||
* {@link #frameLength} as its initial size
|
||||
*/
|
||||
public FixedLengthFrameDecoder(int frameLength, boolean allocateFullBuffer) {
|
||||
if (frameLength <= 0) {
|
||||
|
@ -28,7 +28,9 @@ import io.netty.buffer.HeapChannelBufferFactory;
|
||||
* <a href="http://en.wikipedia.org/wiki/Base64">Base64</a> notation.
|
||||
* <p>
|
||||
* The encoding and decoding algorithm in this class has been derived from
|
||||
* <a href="http://iharder.sourceforge.net/current/java/base64/">Robert Harder's Public Domain Base64 Encoder/Decoder</a>.
|
||||
* <a href="http://iharder.sourceforge.net/current/java/base64/">Robert Harder's Public Domain
|
||||
* Base64 Encoder/Decoder</a>.
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses io.netty.handler.codec.base64.Base64Dialect
|
||||
*/
|
||||
@ -125,7 +127,8 @@ public final class Base64 {
|
||||
return encode(src, off, len, Base64Dialect.STANDARD, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(ChannelBuffer src, int off, int len, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, int off, int len, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
return encode(src, off, len, breakLines(dialect), dialect, bufferFactory);
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ package io.netty.handler.codec.base64;
|
||||
* Enumeration of supported Base64 dialects.
|
||||
* <p>
|
||||
* The internal lookup tables in this class has been derived from
|
||||
* <a href="http://iharder.sourceforge.net/current/java/base64/">Robert Harder's Public Domain Base64 Encoder/Decoder</a>.
|
||||
* <a href="http://iharder.sourceforge.net/current/java/base64/">Robert Harder's Public Domain
|
||||
* Base64 Encoder/Decoder</a>.
|
||||
*/
|
||||
public enum Base64Dialect {
|
||||
/**
|
||||
|
@ -59,7 +59,8 @@ public class ByteArrayDecoder extends MessageToMessageDecoder<ChannelBuffer, byt
|
||||
byte[] array;
|
||||
if (msg.hasArray()) {
|
||||
if (msg.arrayOffset() == 0 && msg.readableBytes() == msg.capacity()) {
|
||||
// we have no offset and the length is the same as the capacity. Its safe to reuse the array without copy it first
|
||||
// we have no offset and the length is the same as the capacity. Its safe to reuse
|
||||
// the array without copy it first
|
||||
array = msg.array();
|
||||
} else {
|
||||
// copy the ChannelBuffer to a byte array
|
||||
|
@ -39,12 +39,15 @@ public class CompatibleMarshallingDecoder extends ReplayingDecoder<Object, VoidE
|
||||
/**
|
||||
* Create a new instance of {@link CompatibleMarshallingDecoder}.
|
||||
*
|
||||
* @param provider the {@link UnmarshallerProvider} which is used to obtain the {@link Unmarshaller} for the {@link Channel}
|
||||
* @param maxObjectSize the maximal size (in bytes) of the {@link Object} to unmarshal. Once the size is exceeded
|
||||
* the {@link Channel} will get closed. Use a a maxObjectSize of {@link Integer#MAX_VALUE} to disable this.
|
||||
* You should only do this if you are sure that the received Objects will never be big and the
|
||||
* sending side are trusted, as this opens the possibility for a DOS-Attack due an {@link OutOfMemoryError}.
|
||||
*
|
||||
* @param provider
|
||||
* the {@link UnmarshallerProvider} which is used to obtain the {@link Unmarshaller}
|
||||
* for the {@link Channel}
|
||||
* @param maxObjectSize
|
||||
* the maximal size (in bytes) of the {@link Object} to unmarshal. Once the size is
|
||||
* exceeded the {@link Channel} will get closed. Use a a maxObjectSize of
|
||||
* {@link Integer#MAX_VALUE} to disable this. You should only do this if you are sure
|
||||
* that the received Objects will never be big and the sending side are trusted, as this
|
||||
* opens the possibility for a DOS-Attack due an {@link OutOfMemoryError}.
|
||||
*/
|
||||
public CompatibleMarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize) {
|
||||
this.provider = provider;
|
||||
|
@ -27,7 +27,8 @@ import org.jboss.marshalling.Unmarshaller;
|
||||
/**
|
||||
* Decoder which MUST be used with {@link MarshallingEncoder}.
|
||||
*
|
||||
* A {@link LengthFieldBasedFrameDecoder} which use an {@link Unmarshaller} to read the Object out of the {@link ChannelBuffer}.
|
||||
* A {@link LengthFieldBasedFrameDecoder} which use an {@link Unmarshaller} to read the Object out
|
||||
* of the {@link ChannelBuffer}.
|
||||
*
|
||||
*/
|
||||
public class MarshallingDecoder extends LengthFieldBasedFrameDecoder {
|
||||
|
@ -38,7 +38,9 @@ public final class ClassResolvers {
|
||||
* @return new instance of class resolver
|
||||
*/
|
||||
public static ClassResolver weakCachingResolver(ClassLoader classLoader) {
|
||||
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
|
||||
return new CachingClassResolver(
|
||||
new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
|
||||
new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +51,9 @@ public final class ClassResolvers {
|
||||
* @return new instance of class resolver
|
||||
*/
|
||||
public static ClassResolver softCachingResolver(ClassLoader classLoader) {
|
||||
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new SoftReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
|
||||
return new CachingClassResolver(
|
||||
new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
|
||||
new SoftReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,7 +64,9 @@ public final class ClassResolvers {
|
||||
* @return new instance of class resolver
|
||||
*/
|
||||
public static ClassResolver weakCachingConcurrentResolver(ClassLoader classLoader) {
|
||||
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new WeakReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
|
||||
return new CachingClassResolver(
|
||||
new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
|
||||
new WeakReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +77,9 @@ public final class ClassResolvers {
|
||||
* @return new instance of class resolver
|
||||
*/
|
||||
public static ClassResolver softCachingConcurrentResolver(ClassLoader classLoader) {
|
||||
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new SoftReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
|
||||
return new CachingClassResolver(
|
||||
new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
|
||||
new SoftReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
|
||||
}
|
||||
|
||||
static ClassLoader defaultClassLoader(ClassLoader classLoader) {
|
||||
|
@ -18,7 +18,7 @@ package io.netty.logging;
|
||||
|
||||
/**
|
||||
* Logger factory which creates a
|
||||
* <a href="http://java.sun.com/javase/6/docs/technotes/guides/logging/index.html">java.util.logging</a>
|
||||
* <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/logging/">java.util.logging</a>
|
||||
* logger.
|
||||
*/
|
||||
public class JdkLoggerFactory extends InternalLoggerFactory {
|
||||
|
@ -44,7 +44,8 @@ public final class SocketAddresses {
|
||||
localhost = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 });
|
||||
} catch (UnknownHostException e1) {
|
||||
try {
|
||||
localhost = InetAddress.getByAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 });
|
||||
localhost = InetAddress.getByAddress(
|
||||
new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 });
|
||||
} catch (UnknownHostException e2) {
|
||||
logger.error("Failed to resolve localhost", e2);
|
||||
}
|
||||
@ -60,8 +61,7 @@ public final class SocketAddresses {
|
||||
loopbackIf = null;
|
||||
}
|
||||
|
||||
// check if the NetworkInterface is null, this is the case on my ubuntu dev machine but not on osx and windows.
|
||||
// if so fail back the the first interface
|
||||
// If null is returned, iterate over all the available network interfaces.
|
||||
if (loopbackIf == null) {
|
||||
try {
|
||||
for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||
|
@ -131,7 +131,8 @@ public class HttpStaticFileServerHandler extends ChannelInboundMessageHandlerAda
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
|
||||
Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince);
|
||||
|
||||
// Only compare up to the second because the datetime format we send to the client does not have milliseconds
|
||||
// Only compare up to the second because the datetime format we send to the client
|
||||
// does not have milliseconds
|
||||
long ifModifiedSinceDateSeconds = ifModifiedSinceDate.getTime() / 1000;
|
||||
long fileLastModifiedSeconds = file.lastModified() / 1000;
|
||||
if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) {
|
||||
@ -270,7 +271,8 @@ public class HttpStaticFileServerHandler extends ChannelInboundMessageHandlerAda
|
||||
time.add(Calendar.SECOND, HTTP_CACHE_SECONDS);
|
||||
response.setHeader(HttpHeaders.Names.EXPIRES, dateFormatter.format(time.getTime()));
|
||||
response.setHeader(HttpHeaders.Names.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
|
||||
response.setHeader(HttpHeaders.Names.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified())));
|
||||
response.setHeader(
|
||||
HttpHeaders.Names.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,7 +137,8 @@ public class HttpSnoopServerHandler extends ChannelInboundMessageHandlerAdapter<
|
||||
if (keepAlive) {
|
||||
// Add 'Content-Length' header only for a keep-alive connection.
|
||||
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
|
||||
// Add keep alive header as per http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
|
||||
// Add keep alive header as per:
|
||||
// - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
|
||||
response.setHeader(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
|
||||
}
|
||||
|
||||
|
@ -27,67 +27,50 @@ public final class WebSocketServerIndexPage {
|
||||
private static final String NEWLINE = "\r\n";
|
||||
|
||||
public static ChannelBuffer getContent(String webSocketLocation) {
|
||||
return ChannelBuffers
|
||||
.copiedBuffer(
|
||||
"<html><head><title>Web Socket Test</title></head>"
|
||||
+ NEWLINE
|
||||
+ "<body>"
|
||||
+ NEWLINE
|
||||
+ "<script type=\"text/javascript\">"
|
||||
+ NEWLINE
|
||||
+ "var socket;"
|
||||
+ NEWLINE
|
||||
+ "if (!window.WebSocket) {"
|
||||
+ NEWLINE
|
||||
+ " window.WebSocket = window.MozWebSocket;"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ "if (window.WebSocket) {"
|
||||
+ NEWLINE
|
||||
+ " socket = new WebSocket(\""
|
||||
+ webSocketLocation
|
||||
+ "\");"
|
||||
+ NEWLINE
|
||||
+ " socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\\n' + event.data };"
|
||||
+ NEWLINE
|
||||
+ " socket.onopen = function(event) { var ta = document.getElementById('responseText'); ta.value = \"Web Socket opened!\"; };"
|
||||
+ NEWLINE
|
||||
+ " socket.onclose = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + \"Web Socket closed\"; };"
|
||||
+ NEWLINE
|
||||
+ "} else {"
|
||||
+ NEWLINE
|
||||
+ " alert(\"Your browser does not support Web Socket.\");"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ NEWLINE
|
||||
+ "function send(message) {"
|
||||
+ NEWLINE
|
||||
+ " if (!window.WebSocket) { return; }"
|
||||
+ NEWLINE
|
||||
+ " if (socket.readyState == WebSocket.OPEN) {"
|
||||
+ NEWLINE
|
||||
+ " socket.send(message);"
|
||||
+ NEWLINE
|
||||
+ " } else {"
|
||||
+ NEWLINE
|
||||
+ " alert(\"The socket is not open.\");"
|
||||
+ NEWLINE
|
||||
+ " }"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ "</script>"
|
||||
+ NEWLINE
|
||||
+ "<form onsubmit=\"return false;\">"
|
||||
+ NEWLINE
|
||||
+ "<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>"
|
||||
+ "<input type=\"button\" value=\"Send Web Socket Data\" onclick=\"send(this.form.message.value)\" />"
|
||||
+ NEWLINE + "<h3>Output</h3>" + NEWLINE
|
||||
+ "<textarea id=\"responseText\" style=\"width: 500px; height:300px;\"></textarea>"
|
||||
+ NEWLINE + "</form>" + NEWLINE + "</body>" + NEWLINE + "</html>" + NEWLINE,
|
||||
CharsetUtil.US_ASCII);
|
||||
return ChannelBuffers.copiedBuffer(
|
||||
"<html><head><title>Web Socket Test</title></head>" + NEWLINE +
|
||||
"<body>" + NEWLINE +
|
||||
"<script type=\"text/javascript\">" + NEWLINE +
|
||||
"var socket;" + NEWLINE +
|
||||
"if (!window.WebSocket) {" + NEWLINE +
|
||||
" window.WebSocket = window.MozWebSocket;" + NEWLINE +
|
||||
"}" + NEWLINE +
|
||||
"if (window.WebSocket) {" + NEWLINE +
|
||||
" socket = new WebSocket(\"" + webSocketLocation + "\");" + NEWLINE +
|
||||
" socket.onmessage = function(event) {" + NEWLINE +
|
||||
" var ta = document.getElementById('responseText');" + NEWLINE +
|
||||
" ta.value = ta.value + '\\n' + event.data" + NEWLINE +
|
||||
" };" + NEWLINE +
|
||||
" socket.onopen = function(event) {" + NEWLINE +
|
||||
" var ta = document.getElementById('responseText');" + NEWLINE +
|
||||
" ta.value = \"Web Socket opened!\";" + NEWLINE +
|
||||
" };" + NEWLINE +
|
||||
" socket.onclose = function(event) {" + NEWLINE +
|
||||
" var ta = document.getElementById('responseText');" + NEWLINE +
|
||||
" ta.value = ta.value + \"Web Socket closed\"; " + NEWLINE +
|
||||
" };" + NEWLINE +
|
||||
"} else {" + NEWLINE +
|
||||
" alert(\"Your browser does not support Web Socket.\");" + NEWLINE +
|
||||
"}" + NEWLINE +
|
||||
NEWLINE +
|
||||
"function send(message) {" + NEWLINE +
|
||||
" if (!window.WebSocket) { return; }" + NEWLINE +
|
||||
" if (socket.readyState == WebSocket.OPEN) {" + NEWLINE +
|
||||
" socket.send(message);" + NEWLINE +
|
||||
" } else {" + NEWLINE +
|
||||
" alert(\"The socket is not open.\");" + NEWLINE +
|
||||
" }" + NEWLINE +
|
||||
"}" + NEWLINE +
|
||||
"</script>" + NEWLINE +
|
||||
"<form onsubmit=\"return false;\">" + NEWLINE +
|
||||
"<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>" +
|
||||
"<input type=\"button\" value=\"Send Web Socket Data\"" + NEWLINE +
|
||||
" onclick=\"send(this.form.message.value)\" />" + NEWLINE +
|
||||
"<h3>Output</h3>" + NEWLINE +
|
||||
"<textarea id=\"responseText\" style=\"width:500px;height:300px;\"></textarea>" + NEWLINE +
|
||||
"</form>" + NEWLINE +
|
||||
"</body>" + NEWLINE +
|
||||
"</html>" + NEWLINE, CharsetUtil.US_ASCII);
|
||||
}
|
||||
|
||||
private WebSocketServerIndexPage() {
|
||||
|
@ -26,6 +26,7 @@ import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||
import io.netty.example.http.websocketx.server.WebSocketServerIndexPage;
|
||||
import io.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
@ -71,7 +72,7 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
|
||||
if (req.getUri().equals("/")) {
|
||||
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, OK);
|
||||
|
||||
ChannelBuffer content = WebSocketSslServerIndexPage.getContent(getWebSocketLocation(req));
|
||||
ChannelBuffer content = WebSocketServerIndexPage.getContent(getWebSocketLocation(req));
|
||||
|
||||
res.setHeader(CONTENT_TYPE, "text/html; charset=UTF-8");
|
||||
setContentLength(res, content.readableBytes());
|
||||
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package io.netty.example.http.websocketx.sslserver;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
* Generates the demo HTML page which is served at http://localhost:8080/
|
||||
*/
|
||||
public final class WebSocketSslServerIndexPage {
|
||||
|
||||
private static final String NEWLINE = "\r\n";
|
||||
|
||||
public static ChannelBuffer getContent(String webSocketLocation) {
|
||||
return ChannelBuffers
|
||||
.copiedBuffer(
|
||||
"<html><head><title>Web Socket Test</title></head>"
|
||||
+ NEWLINE
|
||||
+ "<body>"
|
||||
+ NEWLINE
|
||||
+ "<script type=\"text/javascript\">"
|
||||
+ NEWLINE
|
||||
+ "var socket;"
|
||||
+ NEWLINE
|
||||
+ "if (!window.WebSocket) {"
|
||||
+ NEWLINE
|
||||
+ " window.WebSocket = window.MozWebSocket;"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ "if (window.WebSocket) {"
|
||||
+ NEWLINE
|
||||
+ " socket = new WebSocket(\""
|
||||
+ webSocketLocation
|
||||
+ "\");"
|
||||
+ NEWLINE
|
||||
+ " socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\\n' + event.data };"
|
||||
+ NEWLINE
|
||||
+ " socket.onopen = function(event) { var ta = document.getElementById('responseText'); ta.value = \"Web Socket opened!\"; };"
|
||||
+ NEWLINE
|
||||
+ " socket.onclose = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + \"Web Socket closed\"; };"
|
||||
+ NEWLINE
|
||||
+ "} else {"
|
||||
+ NEWLINE
|
||||
+ " alert(\"Your browser does not support Web Socket.\");"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ NEWLINE
|
||||
+ "function send(message) {"
|
||||
+ NEWLINE
|
||||
+ " if (!window.WebSocket) { return; }"
|
||||
+ NEWLINE
|
||||
+ " if (socket.readyState == WebSocket.OPEN) {"
|
||||
+ NEWLINE
|
||||
+ " socket.send(message);"
|
||||
+ NEWLINE
|
||||
+ " } else {"
|
||||
+ NEWLINE
|
||||
+ " alert(\"The socket is not open.\");"
|
||||
+ NEWLINE
|
||||
+ " }"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ "</script>"
|
||||
+ NEWLINE
|
||||
+ "<form onsubmit=\"return false;\">"
|
||||
+ NEWLINE
|
||||
+ "<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>"
|
||||
+ "<input type=\"button\" value=\"Send Web Socket Data\" onclick=\"send(this.form.message.value)\" />"
|
||||
+ NEWLINE + "<h3>Output</h3>" + NEWLINE
|
||||
+ "<textarea id=\"responseText\" style=\"width: 500px; height:300px;\"></textarea>"
|
||||
+ NEWLINE + "</form>" + NEWLINE + "</body>" + NEWLINE + "</html>" + NEWLINE,
|
||||
CharsetUtil.US_ASCII);
|
||||
}
|
||||
|
||||
private WebSocketSslServerIndexPage() {
|
||||
// Unused
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ import java.net.InetSocketAddress;
|
||||
* A UDP broadcast client that asks for a quote of the moment (QOTM) to
|
||||
* {@link QuoteOfTheMomentServer}.
|
||||
*
|
||||
* Inspired by <a href="http://java.sun.com/docs/books/tutorial/networking/datagrams/clientServer.html">the official Java tutorial</a>.
|
||||
* Inspired by <a href="http://goo.gl/BsXVR">the official Java tutorial</a>.
|
||||
*/
|
||||
public class QuoteOfTheMomentClient {
|
||||
|
||||
|
@ -26,7 +26,7 @@ import java.net.InetSocketAddress;
|
||||
* A UDP server that responds to the QOTM (quote of the moment) request to a
|
||||
* {@link QuoteOfTheMomentClient}.
|
||||
*
|
||||
* Inspired by <a href="http://java.sun.com/docs/books/tutorial/networking/datagrams/clientServer.html">the official Java tutorial</a>.
|
||||
* Inspired by <a href="http://goo.gl/BsXVR">the official Java tutorial</a>.
|
||||
*/
|
||||
public class QuoteOfTheMomentServer {
|
||||
|
||||
|
@ -18,6 +18,7 @@ package io.netty.example.securechat;
|
||||
import io.netty.handler.ssl.SslHandler;
|
||||
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.Security;
|
||||
|
||||
import javax.net.ssl.KeyManager;
|
||||
@ -42,10 +43,10 @@ import javax.net.ssl.TrustManager;
|
||||
* {@link SslHandler}.</li>
|
||||
* <li>When initializing an {@link SSLContext} on the client side,
|
||||
* specify the {@link KeyManager} that contains the client certificate as
|
||||
* the first argument of {@link SSLContext#init(KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)}.</li>
|
||||
* the first argument of {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.</li>
|
||||
* <li>When initializing an {@link SSLContext} on the server side,
|
||||
* specify the proper {@link TrustManager} as the second argument of
|
||||
* {@link SSLContext#init(KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)}
|
||||
* {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}
|
||||
* to validate the client certificate.</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
@ -62,9 +62,10 @@ import javax.net.ssl.SSLException;
|
||||
* <h3>Handshake</h3>
|
||||
* <p>
|
||||
* If {@link #isIssueHandshake()} is {@code false}
|
||||
* (default) you will need to take care of calling {@link #handshake()} by your own. In most situations were {@link SslHandler} is used in 'client mode'
|
||||
* you want to issue a handshake once the connection was established. if {@link #setIssueHandshake(boolean)} is set to <code>true</code> you don't need to
|
||||
* worry about this as the {@link SslHandler} will take care of it.
|
||||
* (default) you will need to take care of calling {@link #handshake()} by your own. In most
|
||||
* situations were {@link SslHandler} is used in 'client mode' you want to issue a handshake once
|
||||
* the connection was established. if {@link #setIssueHandshake(boolean)} is set to <code>true</code>
|
||||
* you don't need to worry about this as the {@link SslHandler} will take care of it.
|
||||
* <p>
|
||||
*
|
||||
* <h3>Renegotiation</h3>
|
||||
@ -83,7 +84,8 @@ import javax.net.ssl.SSLException;
|
||||
* <ul>
|
||||
* <li><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3555">CVE-2009-3555</a></li>
|
||||
* <li><a href="http://www.ietf.org/rfc/rfc5746.txt">RFC5746</a></li>
|
||||
* <li><a href="http://www.oracle.com/technetwork/java/javase/documentation/tlsreadme2-176330.html">Phased Approach to Fixing the TLS Renegotiation Issue</a></li>
|
||||
* <li><a href="http://www.oracle.com/technetwork/java/javase/documentation/tlsreadme2-176330.html">Phased
|
||||
* Approach to Fixing the TLS Renegotiation Issue</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <h3>Closing the session</h3>
|
||||
@ -646,7 +648,8 @@ public class SslHandler
|
||||
@Override
|
||||
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
|
||||
if (!startTls && engine.getUseClientMode()) {
|
||||
// issue and handshake and add a listener to it which will fire an exception event if an exception was thrown while doing the handshake
|
||||
// issue and handshake and add a listener to it which will fire an exception event if
|
||||
// an exception was thrown while doing the handshake
|
||||
handshake().addListener(new ChannelFutureListener() {
|
||||
|
||||
@Override
|
||||
|
@ -234,8 +234,9 @@ public class ChunkedWriteHandler
|
||||
if (endOfInput) {
|
||||
this.currentEvent = null;
|
||||
|
||||
// Register a listener which will close the input once the write is complete. This is needed because the Chunk may have
|
||||
// some resource bound that can not be closed before its not written
|
||||
// Register a listener which will close the input once the write is complete.
|
||||
// This is needed because the Chunk may have some resource bound that can not
|
||||
// be closed before its not written.
|
||||
//
|
||||
// See https://github.com/netty/netty/issues/303
|
||||
f.addListener(new ChannelFutureListener() {
|
||||
|
2
pom.xml
2
pom.xml
@ -315,7 +315,7 @@
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>netty-build</artifactId>
|
||||
<version>8</version>
|
||||
<version>9-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
@ -143,7 +143,7 @@ import java.nio.channels.Channels;
|
||||
* <pre>
|
||||
* public final class DataServerState {
|
||||
*
|
||||
* <b>public static final {@link ChannelLocal}<Boolean> loggedIn = new {@link ChannelLocal}<Boolean>() {
|
||||
* <b>public static final {@link ChannelLocal}<Boolean> loggedIn = new {@link ChannelLocal}<>() {
|
||||
* protected Boolean initialValue(Channel channel) {
|
||||
* return false;
|
||||
* }
|
||||
|
@ -28,7 +28,9 @@ public class ChannelHandlerAdapter extends ChannelStateHandlerAdapter implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future) throws Exception {
|
||||
public void connect(
|
||||
ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
|
||||
ChannelFuture future) throws Exception {
|
||||
ctx.connect(remoteAddress, localAddress, future);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,9 @@ import java.net.SocketAddress;
|
||||
|
||||
public interface ChannelOperationHandler extends ChannelHandler {
|
||||
void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelFuture future) throws Exception;
|
||||
void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future) throws Exception;
|
||||
void connect(
|
||||
ChannelHandlerContext ctx, SocketAddress remoteAddress,
|
||||
SocketAddress localAddress, ChannelFuture future) throws Exception;
|
||||
void disconnect(ChannelHandlerContext ctx, ChannelFuture future) throws Exception;
|
||||
void close(ChannelHandlerContext ctx, ChannelFuture future) throws Exception;
|
||||
void deregister(ChannelHandlerContext ctx, ChannelFuture future) throws Exception;
|
||||
|
@ -37,7 +37,8 @@ public class DefaultChannelConfig implements ChannelConfig {
|
||||
return getOptions(null, CONNECT_TIMEOUT_MILLIS, WRITE_SPIN_COUNT);
|
||||
}
|
||||
|
||||
protected Map<ChannelOption<?>, Object> getOptions(Map<ChannelOption<?>, Object> result, ChannelOption<?>... options) {
|
||||
protected Map<ChannelOption<?>, Object> getOptions(
|
||||
Map<ChannelOption<?>, Object> result, ChannelOption<?>... options) {
|
||||
if (result == null) {
|
||||
result = new IdentityHashMap<ChannelOption<?>, Object>();
|
||||
}
|
||||
|
@ -86,7 +86,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
synchronized (this) {
|
||||
checkDuplicateName(name);
|
||||
final DefaultChannelHandlerContext nextCtx = head.next;
|
||||
final DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(this, executor, head, nextCtx, name, handler);
|
||||
final DefaultChannelHandlerContext newCtx =
|
||||
new DefaultChannelHandlerContext(this, executor, head, nextCtx, name, handler);
|
||||
|
||||
if (!newCtx.channel().isRegistered() || newCtx.executor().inEventLoop()) {
|
||||
addFirst0(name, nextCtx, newCtx);
|
||||
@ -118,7 +119,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
|
||||
}
|
||||
|
||||
private void addFirst0(final String name, DefaultChannelHandlerContext nextCtx, DefaultChannelHandlerContext newCtx) {
|
||||
private void addFirst0(
|
||||
final String name, DefaultChannelHandlerContext nextCtx, DefaultChannelHandlerContext newCtx) {
|
||||
callBeforeAdd(newCtx);
|
||||
|
||||
if (nextCtx != null) {
|
||||
@ -144,7 +146,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
checkDuplicateName(name);
|
||||
|
||||
final DefaultChannelHandlerContext oldTail = tail;
|
||||
final DefaultChannelHandlerContext newTail = new DefaultChannelHandlerContext(this, executor, oldTail, null, name, handler);
|
||||
final DefaultChannelHandlerContext newTail =
|
||||
new DefaultChannelHandlerContext(this, executor, oldTail, null, name, handler);
|
||||
|
||||
if (!newTail.channel().isRegistered() || newTail.executor().inEventLoop()) {
|
||||
addLast0(name, oldTail, newTail);
|
||||
@ -177,7 +180,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
|
||||
}
|
||||
|
||||
private void addLast0(final String name, DefaultChannelHandlerContext oldTail, DefaultChannelHandlerContext newTail) {
|
||||
private void addLast0(
|
||||
final String name, DefaultChannelHandlerContext oldTail, DefaultChannelHandlerContext newTail) {
|
||||
callBeforeAdd(newTail);
|
||||
|
||||
oldTail.next = newTail;
|
||||
@ -193,14 +197,16 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPipeline addBefore(EventExecutor executor, String baseName, final String name, final ChannelHandler handler) {
|
||||
public ChannelPipeline addBefore(
|
||||
EventExecutor executor, String baseName, final String name, final ChannelHandler handler) {
|
||||
try {
|
||||
Future<Throwable> future;
|
||||
|
||||
synchronized (this) {
|
||||
final DefaultChannelHandlerContext ctx = getContextOrDie(baseName);
|
||||
checkDuplicateName(name);
|
||||
final DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(this, executor, ctx.prev, ctx, name, handler);
|
||||
final DefaultChannelHandlerContext newCtx =
|
||||
new DefaultChannelHandlerContext(this, executor, ctx.prev, ctx, name, handler);
|
||||
|
||||
if (!newCtx.channel().isRegistered() || newCtx.executor().inEventLoop()) {
|
||||
addBefore0(name, ctx, newCtx);
|
||||
@ -250,7 +256,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPipeline addAfter(EventExecutor executor, String baseName, final String name, final ChannelHandler handler) {
|
||||
public ChannelPipeline addAfter(
|
||||
EventExecutor executor, String baseName, final String name, final ChannelHandler handler) {
|
||||
|
||||
try {
|
||||
Future<Throwable> future;
|
||||
@ -261,7 +268,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
return addLast(name, handler);
|
||||
}
|
||||
checkDuplicateName(name);
|
||||
final DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(this, executor, ctx, ctx.next, name, handler);
|
||||
final DefaultChannelHandlerContext newCtx =
|
||||
new DefaultChannelHandlerContext(this, executor, ctx, ctx.next, name, handler);
|
||||
|
||||
if (!newCtx.channel().isRegistered() || newCtx.executor().inEventLoop()) {
|
||||
addAfter0(name, ctx, newCtx);
|
||||
@ -531,7 +539,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
return (T) replace(getContextOrDie(oldHandlerType), newName, newHandler);
|
||||
}
|
||||
|
||||
private ChannelHandler replace(final DefaultChannelHandlerContext ctx, final String newName, final ChannelHandler newHandler) {
|
||||
private ChannelHandler replace(
|
||||
final DefaultChannelHandlerContext ctx, final String newName, final ChannelHandler newHandler) {
|
||||
try {
|
||||
Future<Throwable> future;
|
||||
synchronized (this) {
|
||||
@ -542,7 +551,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
final DefaultChannelHandlerContext oldTail = tail;
|
||||
final DefaultChannelHandlerContext newTail = new DefaultChannelHandlerContext(this, null, oldTail, null, newName, newHandler);
|
||||
final DefaultChannelHandlerContext newTail =
|
||||
new DefaultChannelHandlerContext(this, null, oldTail, null, newName, newHandler);
|
||||
|
||||
if (!oldTail.channel().isRegistered() || oldTail.executor().inEventLoop()) {
|
||||
removeLast0(oldTail);
|
||||
@ -570,7 +580,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
DefaultChannelHandlerContext prev = ctx.prev;
|
||||
DefaultChannelHandlerContext next = ctx.next;
|
||||
|
||||
final DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(this, ctx.executor, prev, next, newName, newHandler);
|
||||
final DefaultChannelHandlerContext newCtx =
|
||||
new DefaultChannelHandlerContext(this, ctx.executor, prev, next, newName, newHandler);
|
||||
|
||||
if (!newCtx.channel().isRegistered() || newCtx.executor().inEventLoop()) {
|
||||
replace0(ctx, newName, newCtx);
|
||||
@ -1263,7 +1274,8 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
return bind(firstContext(ChannelHandlerType.OPERATION), localAddress, future);
|
||||
}
|
||||
|
||||
ChannelFuture bind(final DefaultChannelHandlerContext ctx, final SocketAddress localAddress, final ChannelFuture future) {
|
||||
ChannelFuture bind(
|
||||
final DefaultChannelHandlerContext ctx, final SocketAddress localAddress, final ChannelFuture future) {
|
||||
if (localAddress == null) {
|
||||
throw new NullPointerException("localAddress");
|
||||
}
|
||||
@ -1297,7 +1309,9 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
return connect(firstContext(ChannelHandlerType.OPERATION), remoteAddress, localAddress, future);
|
||||
}
|
||||
|
||||
ChannelFuture connect(final DefaultChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelFuture future) {
|
||||
ChannelFuture connect(
|
||||
final DefaultChannelHandlerContext ctx, final SocketAddress remoteAddress,
|
||||
final SocketAddress localAddress, final ChannelFuture future) {
|
||||
if (remoteAddress == null) {
|
||||
throw new NullPointerException("remoteAddress");
|
||||
}
|
||||
|
@ -49,7 +49,8 @@ public abstract class SingleThreadEventExecutor extends AbstractExecutorService
|
||||
private static final long START_TIME = System.nanoTime();
|
||||
private static final AtomicLong nextTaskId = new AtomicLong();
|
||||
|
||||
static final ThreadLocal<SingleThreadEventExecutor> CURRENT_EVENT_LOOP = new ThreadLocal<SingleThreadEventExecutor>();
|
||||
static final ThreadLocal<SingleThreadEventExecutor> CURRENT_EVENT_LOOP =
|
||||
new ThreadLocal<SingleThreadEventExecutor>();
|
||||
|
||||
public static SingleThreadEventExecutor currentEventLoop() {
|
||||
return CURRENT_EVENT_LOOP.get();
|
||||
|
@ -45,10 +45,12 @@ public interface DatagramChannel extends Channel {
|
||||
* Joins the specified multicast group at the specified interface.
|
||||
*/
|
||||
ChannelFuture joinGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface);
|
||||
ChannelFuture joinGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface, ChannelFuture future);
|
||||
ChannelFuture joinGroup(
|
||||
InetSocketAddress multicastAddress, NetworkInterface networkInterface, ChannelFuture future);
|
||||
|
||||
ChannelFuture joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source);
|
||||
ChannelFuture joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source, ChannelFuture future);
|
||||
ChannelFuture joinGroup(
|
||||
InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source, ChannelFuture future);
|
||||
|
||||
/**
|
||||
* Leaves a multicast group.
|
||||
@ -60,7 +62,8 @@ public interface DatagramChannel extends Channel {
|
||||
* Leaves a multicast group on a specified local interface.
|
||||
*/
|
||||
ChannelFuture leaveGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface);
|
||||
ChannelFuture leaveGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface, ChannelFuture future);
|
||||
ChannelFuture leaveGroup(
|
||||
InetSocketAddress multicastAddress, NetworkInterface networkInterface, ChannelFuture future);
|
||||
|
||||
/**
|
||||
* Leave the specified multicast group at the specified interface using the specified source.
|
||||
|
@ -17,9 +17,9 @@ package io.netty.channel.socket;
|
||||
|
||||
import io.netty.channel.ChannelConfig;
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.StandardSocketOptions;
|
||||
|
||||
/**
|
||||
* A {@link ChannelConfig} for a {@link DatagramChannel}.
|
||||
@ -56,22 +56,22 @@ import java.net.NetworkInterface;
|
||||
public interface DatagramChannelConfig extends ChannelConfig {
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
int getSendBufferSize();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
void setSendBufferSize(int sendBufferSize);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
int getReceiveBufferSize();
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
void setReceiveBufferSize(int receiveBufferSize);
|
||||
|
||||
@ -80,44 +80,44 @@ public interface DatagramChannelConfig extends ChannelConfig {
|
||||
void setReceivePacketSize(int receivePacketSize);
|
||||
|
||||
/**
|
||||
* Gets the traffic class.
|
||||
* Gets the {@link StandardSocketOptions#IP_TOS} option.
|
||||
*/
|
||||
int getTrafficClass();
|
||||
|
||||
/**
|
||||
* Sets the traffic class as specified in {@link DatagramSocket#setTrafficClass(int)}.
|
||||
* Sets the {@link StandardSocketOptions#IP_TOS} option.
|
||||
*/
|
||||
void setTrafficClass(int trafficClass);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
boolean isReuseAddress();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
void setReuseAddress(boolean reuseAddress);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_BROADCAST}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_BROADCAST} option.
|
||||
*/
|
||||
boolean isBroadcast();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_BROADCAST}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_BROADCAST} option.
|
||||
*/
|
||||
void setBroadcast(boolean broadcast);
|
||||
|
||||
/**
|
||||
* Gets the setting for local loopback of multicast datagrams.
|
||||
* Gets the {@link StandardSocketOptions#IP_MULTICAST_LOOP} option.
|
||||
*
|
||||
* @return {@code true} if and only if the loopback mode has been disabled
|
||||
*/
|
||||
boolean isLoopbackModeDisabled();
|
||||
|
||||
/**
|
||||
* Sets the setting for local loopback of multicast datagrams.
|
||||
* Sets the {@link StandardSocketOptions#IP_MULTICAST_LOOP} option.
|
||||
*
|
||||
* @param loopbackModeDisabled
|
||||
* {@code true} if and only if the loopback mode has been disabled
|
||||
@ -125,14 +125,12 @@ public interface DatagramChannelConfig extends ChannelConfig {
|
||||
void setLoopbackModeDisabled(boolean loopbackModeDisabled);
|
||||
|
||||
/**
|
||||
* Gets the default time-to-live for multicast packets sent out on the
|
||||
* socket.
|
||||
* Gets the {@link StandardSocketOptions#IP_MULTICAST_TTL} option.
|
||||
*/
|
||||
int getTimeToLive();
|
||||
|
||||
/**
|
||||
* Sets the default time-to-live for multicast packets sent out on the
|
||||
* {@link DatagramChannel} in order to control the scope of the multicasts.
|
||||
* Sets the {@link StandardSocketOptions#IP_MULTICAST_TTL} option.
|
||||
*/
|
||||
void setTimeToLive(int ttl);
|
||||
|
||||
@ -147,14 +145,12 @@ public interface DatagramChannelConfig extends ChannelConfig {
|
||||
void setInterface(InetAddress interfaceAddress);
|
||||
|
||||
/**
|
||||
* Gets the network interface for outgoing multicast datagrams sent on
|
||||
* the {@link DatagramChannel}.
|
||||
* Gets the {@link StandardSocketOptions#IP_MULTICAST_IF} option.
|
||||
*/
|
||||
NetworkInterface getNetworkInterface();
|
||||
|
||||
/**
|
||||
* Sets the network interface for outgoing multicast datagrams sent on
|
||||
* the {@link DatagramChannel}.
|
||||
* Sets the {@link StandardSocketOptions#IP_MULTICAST_IF} option.
|
||||
*/
|
||||
void setNetworkInterface(NetworkInterface networkInterface);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package io.netty.channel.socket;
|
||||
import io.netty.channel.ChannelConfig;
|
||||
|
||||
import java.net.ServerSocket;
|
||||
import java.net.StandardSocketOptions;
|
||||
|
||||
/**
|
||||
* A {@link ChannelConfig} for a {@link ServerSocketChannel}.
|
||||
@ -55,22 +56,22 @@ public interface ServerSocketChannelConfig extends ChannelConfig {
|
||||
void setBacklog(int backlog);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
boolean isReuseAddress();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
void setReuseAddress(boolean reuseAddress);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
int getReceiveBufferSize();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
void setReceiveBufferSize(int receiveBufferSize);
|
||||
|
||||
|
@ -18,6 +18,7 @@ package io.netty.channel.socket;
|
||||
import io.netty.channel.ChannelConfig;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.net.StandardSocketOptions;
|
||||
|
||||
/**
|
||||
* A {@link ChannelConfig} for a {@link SocketChannel}.
|
||||
@ -50,72 +51,72 @@ import java.net.Socket;
|
||||
public interface SocketChannelConfig extends ChannelConfig {
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_TCPNODELAY}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#TCP_NODELAY} option.
|
||||
*/
|
||||
boolean isTcpNoDelay();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_TCPNODELAY}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#TCP_NODELAY} option.
|
||||
*/
|
||||
void setTcpNoDelay(boolean tcpNoDelay);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_LINGER}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_LINGER} option.
|
||||
*/
|
||||
int getSoLinger();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_LINGER}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_LINGER} option.
|
||||
*/
|
||||
void setSoLinger(int soLinger);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
int getSendBufferSize();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
void setSendBufferSize(int sendBufferSize);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
int getReceiveBufferSize();
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
void setReceiveBufferSize(int receiveBufferSize);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_KEEPALIVE}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
|
||||
*/
|
||||
boolean isKeepAlive();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_KEEPALIVE}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
|
||||
*/
|
||||
void setKeepAlive(boolean keepAlive);
|
||||
|
||||
/**
|
||||
* Gets the traffic class.
|
||||
* Gets the {@link StandardSocketOptions#IP_TOS} option.
|
||||
*/
|
||||
int getTrafficClass();
|
||||
|
||||
/**
|
||||
* Sets the traffic class as specified in {@link Socket#setTrafficClass(int)}.
|
||||
* Sets the {@link StandardSocketOptions#IP_TOS} option.
|
||||
*/
|
||||
void setTrafficClass(int trafficClass);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
boolean isReuseAddress();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
void setReuseAddress(boolean reuseAddress);
|
||||
|
||||
@ -123,6 +124,5 @@ public interface SocketChannelConfig extends ChannelConfig {
|
||||
* Sets the performance preferences as specified in
|
||||
* {@link Socket#setPerformancePreferences(int, int, int)}.
|
||||
*/
|
||||
void setPerformancePreferences(
|
||||
int connectionTime, int latency, int bandwidth);
|
||||
void setPerformancePreferences(int connectionTime, int latency, int bandwidth);
|
||||
}
|
||||
|
@ -113,7 +113,8 @@ public abstract class AbstractNioChannel extends AbstractChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelFuture future) {
|
||||
public void connect(
|
||||
final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelFuture future) {
|
||||
if (eventLoop().inEventLoop()) {
|
||||
if (!ensureOpen(future)) {
|
||||
return;
|
||||
|
@ -44,7 +44,8 @@ import java.util.Queue;
|
||||
/**
|
||||
* Provides an NIO based {@link io.netty.channel.socket.DatagramChannel}.
|
||||
*/
|
||||
public final class NioDatagramChannel extends AbstractNioMessageChannel implements io.netty.channel.socket.DatagramChannel {
|
||||
public final class NioDatagramChannel
|
||||
extends AbstractNioMessageChannel implements io.netty.channel.socket.DatagramChannel {
|
||||
|
||||
private final DatagramChannelConfig config;
|
||||
private final Map<InetAddress, List<MembershipKey>> memberships =
|
||||
@ -299,7 +300,8 @@ public final class NioDatagramChannel extends AbstractNioMessageChannel implemen
|
||||
@Override
|
||||
public ChannelFuture leaveGroup(InetAddress multicastAddress, ChannelFuture future) {
|
||||
try {
|
||||
return leaveGroup(multicastAddress, NetworkInterface.getByInetAddress(localAddress().getAddress()), null, future);
|
||||
return leaveGroup(
|
||||
multicastAddress, NetworkInterface.getByInetAddress(localAddress().getAddress()), null, future);
|
||||
} catch (SocketException e) {
|
||||
future.setFailure(e);
|
||||
}
|
||||
@ -348,7 +350,8 @@ public final class NioDatagramChannel extends AbstractNioMessageChannel implemen
|
||||
while (keyIt.hasNext()) {
|
||||
MembershipKey key = keyIt.next();
|
||||
if (networkInterface.equals(key.networkInterface())) {
|
||||
if (source == null && key.sourceAddress() == null || source != null && source.equals(key.sourceAddress())) {
|
||||
if (source == null && key.sourceAddress() == null ||
|
||||
source != null && source.equals(key.sourceAddress())) {
|
||||
key.drop();
|
||||
keyIt.remove();
|
||||
}
|
||||
|
@ -46,6 +46,12 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
|
||||
} catch (Exception e) {
|
||||
// Not Java 7+
|
||||
}
|
||||
Class<?> stdSocketOptionType = null;
|
||||
try {
|
||||
stdSocketOptionType = Class.forName("java.net.StandardSocketOptions", true, classLoader);
|
||||
} catch (Exception e) {
|
||||
// Not Java 7+
|
||||
}
|
||||
|
||||
Object ipMulticastTtl = null;
|
||||
Object ipMulticastIf = null;
|
||||
@ -54,19 +60,19 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
|
||||
Method setOption = null;
|
||||
if (socketOptionType != null) {
|
||||
try {
|
||||
ipMulticastTtl = Class.forName("java.net.StandardSocketOptions", true, classLoader).getDeclaredField("IP_MULTICAST_TTL").get(null);
|
||||
ipMulticastTtl = stdSocketOptionType.getDeclaredField("IP_MULTICAST_TTL").get(null);
|
||||
} catch (Exception e) {
|
||||
throw new Error("cannot locate the IP_MULTICAST_TTL field", e);
|
||||
}
|
||||
|
||||
try {
|
||||
ipMulticastIf = Class.forName("java.net.StandardSocketOptions", true, classLoader).getDeclaredField("IP_MULTICAST_IF").get(null);
|
||||
ipMulticastIf = stdSocketOptionType.getDeclaredField("IP_MULTICAST_IF").get(null);
|
||||
} catch (Exception e) {
|
||||
throw new Error("cannot locate the IP_MULTICAST_IF field", e);
|
||||
}
|
||||
|
||||
try {
|
||||
ipMulticastLoop = Class.forName("java.net.StandardSocketOptions", true, classLoader).getDeclaredField("IP_MULTICAST_LOOP").get(null);
|
||||
ipMulticastLoop = stdSocketOptionType.getDeclaredField("IP_MULTICAST_LOOP").get(null);
|
||||
} catch (Exception e) {
|
||||
throw new Error("cannot locate the IP_MULTICAST_LOOP field", e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user