View Javadoc

1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.channel.socket;
17  
18  import io.netty.buffer.ByteBufAllocator;
19  import io.netty.channel.ChannelConfig;
20  import io.netty.channel.ChannelHandlerContext;
21  import io.netty.channel.ChannelInboundHandler;
22  import io.netty.channel.ChannelOption;
23  import io.netty.channel.MessageSizeEstimator;
24  import io.netty.channel.RecvByteBufAllocator;
25  
26  import java.net.Socket;
27  import java.net.StandardSocketOptions;
28  
29  /**
30   * A {@link ChannelConfig} for a {@link SocketChannel}.
31   *
32   * <h3>Available options</h3>
33   *
34   * In addition to the options provided by {@link ChannelConfig},
35   * {@link SocketChannelConfig} allows the following options in the option map:
36   *
37   * <table border="1" cellspacing="0" cellpadding="6">
38   * <tr>
39   * <th>Name</th><th>Associated setter method</th>
40   * </tr><tr>
41   * <td>{@link ChannelOption#SO_KEEPALIVE}</td><td>{@link #setKeepAlive(boolean)}</td>
42   * </tr><tr>
43   * <td>{@link ChannelOption#SO_REUSEADDR}</td><td>{@link #setReuseAddress(boolean)}</td>
44   * </tr><tr>
45   * <td>{@link ChannelOption#SO_LINGER}</td><td>{@link #setSoLinger(int)}</td>
46   * </tr><tr>
47   * <td>{@link ChannelOption#TCP_NODELAY}</td><td>{@link #setTcpNoDelay(boolean)}</td>
48   * </tr><tr>
49   * <td>{@link ChannelOption#SO_RCVBUF}</td><td>{@link #setReceiveBufferSize(int)}</td>
50   * </tr><tr>
51   * <td>{@link ChannelOption#SO_SNDBUF}</td><td>{@link #setSendBufferSize(int)}</td>
52   * </tr><tr>
53   * <td>{@link ChannelOption#IP_TOS}</td><td>{@link #setTrafficClass(int)}</td>
54   * </tr><tr>
55   * <td>{@link ChannelOption#ALLOW_HALF_CLOSURE}</td><td>{@link #setAllowHalfClosure(boolean)}</td>
56   * </tr>
57   * </table>
58   */
59  public interface SocketChannelConfig extends ChannelConfig {
60  
61      /**
62       * Gets the {@link StandardSocketOptions#TCP_NODELAY} option.  Please note that the default value of this option
63       * is {@code true} unlike the operating system default ({@code false}). However, for some buggy platforms, such as
64       * Android, that shows erratic behavior with Nagle's algorithm disabled, the default value remains to be
65       * {@code false}.
66       */
67      boolean isTcpNoDelay();
68  
69      /**
70       * Sets the {@link StandardSocketOptions#TCP_NODELAY} option.  Please note that the default value of this option
71       * is {@code true} unlike the operating system default ({@code false}). However, for some buggy platforms, such as
72       * Android, that shows erratic behavior with Nagle's algorithm disabled, the default value remains to be
73       * {@code false}.
74       */
75      SocketChannelConfig setTcpNoDelay(boolean tcpNoDelay);
76  
77      /**
78       * Gets the {@link StandardSocketOptions#SO_LINGER} option.
79       */
80      int getSoLinger();
81  
82      /**
83       * Sets the {@link StandardSocketOptions#SO_LINGER} option.
84       */
85      SocketChannelConfig setSoLinger(int soLinger);
86  
87      /**
88       * Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
89       */
90      int getSendBufferSize();
91  
92      /**
93       * Sets the {@link StandardSocketOptions#SO_SNDBUF} option.
94       */
95      SocketChannelConfig setSendBufferSize(int sendBufferSize);
96  
97      /**
98       * Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
99       */
100     int getReceiveBufferSize();
101 
102     /**
103      * Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
104      */
105     SocketChannelConfig setReceiveBufferSize(int receiveBufferSize);
106 
107     /**
108      * Gets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
109      */
110     boolean isKeepAlive();
111 
112     /**
113      * Sets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
114      */
115     SocketChannelConfig setKeepAlive(boolean keepAlive);
116 
117     /**
118      * Gets the {@link StandardSocketOptions#IP_TOS} option.
119      */
120     int getTrafficClass();
121 
122     /**
123      * Sets the {@link StandardSocketOptions#IP_TOS} option.
124      */
125     SocketChannelConfig setTrafficClass(int trafficClass);
126 
127     /**
128      * Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
129      */
130     boolean isReuseAddress();
131 
132     /**
133      * Sets the {@link StandardSocketOptions#SO_REUSEADDR} option.
134      */
135     SocketChannelConfig setReuseAddress(boolean reuseAddress);
136 
137     /**
138      * Sets the performance preferences as specified in
139      * {@link Socket#setPerformancePreferences(int, int, int)}.
140      */
141     SocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth);
142 
143     /**
144      * Returns {@code true} if and only if the channel should not close itself when its remote
145      * peer shuts down output to make the connection half-closed.  If {@code false}, the connection
146      * is closed automatically when the remote peer shuts down output.
147      */
148     boolean isAllowHalfClosure();
149 
150     /**
151      * Sets whether the channel should not close itself when its remote peer shuts down output to
152      * make the connection half-closed.  If {@code true} the connection is not closed when the
153      * remote peer shuts down output. Instead,
154      * {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)}
155      * is invoked with a {@link ChannelInputShutdownEvent} object. If {@code false}, the connection
156      * is closed automatically.
157      */
158     SocketChannelConfig setAllowHalfClosure(boolean allowHalfClosure);
159 
160     @Override
161     SocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis);
162 
163     @Override
164     SocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead);
165 
166     @Override
167     SocketChannelConfig setWriteSpinCount(int writeSpinCount);
168 
169     @Override
170     SocketChannelConfig setAllocator(ByteBufAllocator allocator);
171 
172     @Override
173     SocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
174 
175     @Override
176     SocketChannelConfig setAutoRead(boolean autoRead);
177 
178     @Override
179     SocketChannelConfig setAutoClose(boolean autoClose);
180 
181     @Override
182     SocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator);
183 }