查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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    *   https://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.ChannelOption;
21  import io.netty.channel.MessageSizeEstimator;
22  import io.netty.channel.RecvByteBufAllocator;
23  import io.netty.channel.WriteBufferWaterMark;
24  
25  import java.net.Socket;
26  import java.net.StandardSocketOptions;
27  
28  /**
29   * A {@link ChannelConfig} for a {@link SocketChannel}.
30   *
31   * <h3>Available options</h3>
32   *
33   * In addition to the options provided by {@link DuplexChannelConfig},
34   * {@link SocketChannelConfig} allows the following options in the option map:
35   *
36   * <table border="1" cellspacing="0" cellpadding="6">
37   * <tr>
38   * <th>Name</th><th>Associated setter method</th>
39   * </tr><tr>
40   * <td>{@link ChannelOption#SO_KEEPALIVE}</td><td>{@link #setKeepAlive(boolean)}</td>
41   * </tr><tr>
42   * <td>{@link ChannelOption#SO_REUSEADDR}</td><td>{@link #setReuseAddress(boolean)}</td>
43   * </tr><tr>
44   * <td>{@link ChannelOption#SO_LINGER}</td><td>{@link #setSoLinger(int)}</td>
45   * </tr><tr>
46   * <td>{@link ChannelOption#TCP_NODELAY}</td><td>{@link #setTcpNoDelay(boolean)}</td>
47   * </tr><tr>
48   * <td>{@link ChannelOption#SO_RCVBUF}</td><td>{@link #setReceiveBufferSize(int)}</td>
49   * </tr><tr>
50   * <td>{@link ChannelOption#SO_SNDBUF}</td><td>{@link #setSendBufferSize(int)}</td>
51   * </tr><tr>
52   * <td>{@link ChannelOption#IP_TOS}</td><td>{@link #setTrafficClass(int)}</td>
53   * </tr><tr>
54   * <td>{@link ChannelOption#ALLOW_HALF_CLOSURE}</td><td>{@link #setAllowHalfClosure(boolean)}</td>
55   * </tr>
56   * </table>
57   */
58  public interface SocketChannelConfig extends DuplexChannelConfig {
59  
60      /**
61       * Gets the {@link StandardSocketOptions#TCP_NODELAY} option.  Please note that the default value of this option
62       * is {@code true} unlike the operating system default ({@code false}). However, for some buggy platforms, such as
63       * Android, that shows erratic behavior with Nagle's algorithm disabled, the default value remains to be
64       * {@code false}.
65       */
66      boolean isTcpNoDelay();
67  
68      /**
69       * Sets the {@link StandardSocketOptions#TCP_NODELAY} option.  Please note that the default value of this option
70       * is {@code true} unlike the operating system default ({@code false}). However, for some buggy platforms, such as
71       * Android, that shows erratic behavior with Nagle's algorithm disabled, the default value remains to be
72       * {@code false}.
73       */
74      SocketChannelConfig setTcpNoDelay(boolean tcpNoDelay);
75  
76      /**
77       * Gets the {@link StandardSocketOptions#SO_LINGER} option.
78       */
79      int getSoLinger();
80  
81      /**
82       * Sets the {@link StandardSocketOptions#SO_LINGER} option.
83       */
84      SocketChannelConfig setSoLinger(int soLinger);
85  
86      /**
87       * Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
88       */
89      int getSendBufferSize();
90  
91      /**
92       * Sets the {@link StandardSocketOptions#SO_SNDBUF} option.
93       */
94      SocketChannelConfig setSendBufferSize(int sendBufferSize);
95  
96      /**
97       * Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
98       */
99      int getReceiveBufferSize();
100 
101     /**
102      * Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
103      */
104     SocketChannelConfig setReceiveBufferSize(int receiveBufferSize);
105 
106     /**
107      * Gets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
108      */
109     boolean isKeepAlive();
110 
111     /**
112      * Sets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
113      */
114     SocketChannelConfig setKeepAlive(boolean keepAlive);
115 
116     /**
117      * Gets the {@link StandardSocketOptions#IP_TOS} option.
118      */
119     int getTrafficClass();
120 
121     /**
122      * Sets the {@link StandardSocketOptions#IP_TOS} option.
123      */
124     SocketChannelConfig setTrafficClass(int trafficClass);
125 
126     /**
127      * Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
128      */
129     boolean isReuseAddress();
130 
131     /**
132      * Sets the {@link StandardSocketOptions#SO_REUSEADDR} option.
133      */
134     SocketChannelConfig setReuseAddress(boolean reuseAddress);
135 
136     /**
137      * Sets the performance preferences as specified in
138      * {@link Socket#setPerformancePreferences(int, int, int)}.
139      */
140     SocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth);
141 
142     @Override
143     SocketChannelConfig setAllowHalfClosure(boolean allowHalfClosure);
144 
145     @Override
146     SocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis);
147 
148     @Override
149     @Deprecated
150     SocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead);
151 
152     @Override
153     SocketChannelConfig setWriteSpinCount(int writeSpinCount);
154 
155     @Override
156     SocketChannelConfig setAllocator(ByteBufAllocator allocator);
157 
158     @Override
159     SocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
160 
161     @Override
162     SocketChannelConfig setAutoRead(boolean autoRead);
163 
164     @Override
165     SocketChannelConfig setAutoClose(boolean autoClose);
166 
167     @Override
168     SocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator);
169 
170     @Override
171     SocketChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark);
172 }