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  import io.netty.channel.WriteBufferWaterMark;
26  
27  import java.net.Socket;
28  import java.net.StandardSocketOptions;
29  
30  /**
31   * A {@link ChannelConfig} for a {@link SocketChannel}.
32   *
33   * <h3>Available options</h3>
34   *
35   * In addition to the options provided by {@link ChannelConfig},
36   * {@link SocketChannelConfig} allows the following options in the option map:
37   *
38   * <table border="1" cellspacing="0" cellpadding="6">
39   * <tr>
40   * <th>Name</th><th>Associated setter method</th>
41   * </tr><tr>
42   * <td>{@link ChannelOption#SO_KEEPALIVE}</td><td>{@link #setKeepAlive(boolean)}</td>
43   * </tr><tr>
44   * <td>{@link ChannelOption#SO_REUSEADDR}</td><td>{@link #setReuseAddress(boolean)}</td>
45   * </tr><tr>
46   * <td>{@link ChannelOption#SO_LINGER}</td><td>{@link #setSoLinger(int)}</td>
47   * </tr><tr>
48   * <td>{@link ChannelOption#TCP_NODELAY}</td><td>{@link #setTcpNoDelay(boolean)}</td>
49   * </tr><tr>
50   * <td>{@link ChannelOption#SO_RCVBUF}</td><td>{@link #setReceiveBufferSize(int)}</td>
51   * </tr><tr>
52   * <td>{@link ChannelOption#SO_SNDBUF}</td><td>{@link #setSendBufferSize(int)}</td>
53   * </tr><tr>
54   * <td>{@link ChannelOption#IP_TOS}</td><td>{@link #setTrafficClass(int)}</td>
55   * </tr><tr>
56   * <td>{@link ChannelOption#ALLOW_HALF_CLOSURE}</td><td>{@link #setAllowHalfClosure(boolean)}</td>
57   * </tr>
58   * </table>
59   */
60  public interface SocketChannelConfig extends ChannelConfig {
61  
62      /**
63       * Gets the {@link StandardSocketOptions#TCP_NODELAY} option.  Please note that the default value of this option
64       * is {@code true} unlike the operating system default ({@code false}). However, for some buggy platforms, such as
65       * Android, that shows erratic behavior with Nagle's algorithm disabled, the default value remains to be
66       * {@code false}.
67       */
68      boolean isTcpNoDelay();
69  
70      /**
71       * Sets the {@link StandardSocketOptions#TCP_NODELAY} option.  Please note that the default value of this option
72       * is {@code true} unlike the operating system default ({@code false}). However, for some buggy platforms, such as
73       * Android, that shows erratic behavior with Nagle's algorithm disabled, the default value remains to be
74       * {@code false}.
75       */
76      SocketChannelConfig setTcpNoDelay(boolean tcpNoDelay);
77  
78      /**
79       * Gets the {@link StandardSocketOptions#SO_LINGER} option.
80       */
81      int getSoLinger();
82  
83      /**
84       * Sets the {@link StandardSocketOptions#SO_LINGER} option.
85       */
86      SocketChannelConfig setSoLinger(int soLinger);
87  
88      /**
89       * Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
90       */
91      int getSendBufferSize();
92  
93      /**
94       * Sets the {@link StandardSocketOptions#SO_SNDBUF} option.
95       */
96      SocketChannelConfig setSendBufferSize(int sendBufferSize);
97  
98      /**
99       * Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
100      */
101     int getReceiveBufferSize();
102 
103     /**
104      * Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
105      */
106     SocketChannelConfig setReceiveBufferSize(int receiveBufferSize);
107 
108     /**
109      * Gets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
110      */
111     boolean isKeepAlive();
112 
113     /**
114      * Sets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
115      */
116     SocketChannelConfig setKeepAlive(boolean keepAlive);
117 
118     /**
119      * Gets the {@link StandardSocketOptions#IP_TOS} option.
120      */
121     int getTrafficClass();
122 
123     /**
124      * Sets the {@link StandardSocketOptions#IP_TOS} option.
125      */
126     SocketChannelConfig setTrafficClass(int trafficClass);
127 
128     /**
129      * Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
130      */
131     boolean isReuseAddress();
132 
133     /**
134      * Sets the {@link StandardSocketOptions#SO_REUSEADDR} option.
135      */
136     SocketChannelConfig setReuseAddress(boolean reuseAddress);
137 
138     /**
139      * Sets the performance preferences as specified in
140      * {@link Socket#setPerformancePreferences(int, int, int)}.
141      */
142     SocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth);
143 
144     /**
145      * Returns {@code true} if and only if the channel should not close itself when its remote
146      * peer shuts down output to make the connection half-closed.  If {@code false}, the connection
147      * is closed automatically when the remote peer shuts down output.
148      */
149     boolean isAllowHalfClosure();
150 
151     /**
152      * Sets whether the channel should not close itself when its remote peer shuts down output to
153      * make the connection half-closed.  If {@code true} the connection is not closed when the
154      * remote peer shuts down output. Instead,
155      * {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)}
156      * is invoked with a {@link ChannelInputShutdownEvent} object. If {@code false}, the connection
157      * is closed automatically.
158      */
159     SocketChannelConfig setAllowHalfClosure(boolean allowHalfClosure);
160 
161     @Override
162     SocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis);
163 
164     @Override
165     @Deprecated
166     SocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead);
167 
168     @Override
169     SocketChannelConfig setWriteSpinCount(int writeSpinCount);
170 
171     @Override
172     SocketChannelConfig setAllocator(ByteBufAllocator allocator);
173 
174     @Override
175     SocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
176 
177     @Override
178     SocketChannelConfig setAutoRead(boolean autoRead);
179 
180     @Override
181     SocketChannelConfig setAutoClose(boolean autoClose);
182 
183     @Override
184     SocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator);
185 
186     @Override
187     SocketChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark);
188 
189 }