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.ChannelOption;
21  import io.netty.channel.MessageSizeEstimator;
22  import io.netty.channel.RecvByteBufAllocator;
23  import io.netty.channel.WriteBufferWaterMark;
24  
25  import java.net.InetAddress;
26  import java.net.NetworkInterface;
27  import java.net.StandardSocketOptions;
28  
29  /**
30   * A {@link ChannelConfig} for a {@link DatagramChannel}.
31   *
32   * <h3>Available options</h3>
33   *
34   * In addition to the options provided by {@link ChannelConfig},
35   * {@link DatagramChannelConfig} 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_BROADCAST}</td><td>{@link #setBroadcast(boolean)}</td>
42   * </tr><tr>
43   * <td>{@link ChannelOption#IP_MULTICAST_ADDR}</td><td>{@link #setInterface(InetAddress)}</td>
44   * </tr><tr>
45   * <td>{@link ChannelOption#IP_MULTICAST_LOOP_DISABLED}</td>
46   * <td>{@link #setLoopbackModeDisabled(boolean)}</td>
47   * </tr><tr>
48   * <td>{@link ChannelOption#IP_MULTICAST_IF}</td>
49   * <td>{@link #setNetworkInterface(NetworkInterface)}</td>
50   * </tr><tr>
51   * <td>{@link ChannelOption#SO_REUSEADDR}</td><td>{@link #setReuseAddress(boolean)}</td>
52   * </tr><tr>
53   * <td>{@link ChannelOption#SO_RCVBUF}</td><td>{@link #setReceiveBufferSize(int)}</td>
54   * </tr><tr>
55   * <td>{@link ChannelOption#SO_SNDBUF}</td><td>{@link #setSendBufferSize(int)}</td>
56   * </tr><tr>
57   * <td>{@link ChannelOption#IP_MULTICAST_TTL}</td><td>{@link #setTimeToLive(int)}</td>
58   * </tr><tr>
59   * <td>{@link ChannelOption#IP_TOS}</td><td>{@link #setTrafficClass(int)}</td>
60   * </tr>
61   * </table>
62   */
63  public interface DatagramChannelConfig extends ChannelConfig {
64  
65      /**
66       * Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
67       */
68      int getSendBufferSize();
69  
70      /**
71       * Sets the {@link StandardSocketOptions#SO_SNDBUF} option.
72       */
73      DatagramChannelConfig setSendBufferSize(int sendBufferSize);
74  
75      /**
76       * Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
77       */
78      int getReceiveBufferSize();
79  
80      /**
81       * Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
82       */
83      DatagramChannelConfig setReceiveBufferSize(int receiveBufferSize);
84  
85      /**
86       * Gets the {@link StandardSocketOptions#IP_TOS} option.
87       */
88      int getTrafficClass();
89  
90      /**
91       * Sets the {@link StandardSocketOptions#IP_TOS} option.
92       */
93      DatagramChannelConfig setTrafficClass(int trafficClass);
94  
95      /**
96       * Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
97       */
98      boolean isReuseAddress();
99  
100     /**
101      * Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
102      */
103     DatagramChannelConfig setReuseAddress(boolean reuseAddress);
104 
105     /**
106      * Gets the {@link StandardSocketOptions#SO_BROADCAST} option.
107      */
108     boolean isBroadcast();
109 
110     /**
111      * Sets the {@link StandardSocketOptions#SO_BROADCAST} option.
112      */
113     DatagramChannelConfig setBroadcast(boolean broadcast);
114 
115     /**
116      * Gets the {@link StandardSocketOptions#IP_MULTICAST_LOOP} option.
117      *
118      * @return {@code true} if and only if the loopback mode has been disabled
119      */
120     boolean isLoopbackModeDisabled();
121 
122     /**
123      * Sets the {@link StandardSocketOptions#IP_MULTICAST_LOOP} option.
124      *
125      * @param loopbackModeDisabled
126      *        {@code true} if and only if the loopback mode has been disabled
127      */
128     DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled);
129 
130     /**
131      * Gets the {@link StandardSocketOptions#IP_MULTICAST_TTL} option.
132      */
133     int getTimeToLive();
134 
135     /**
136      * Sets the {@link StandardSocketOptions#IP_MULTICAST_TTL} option.
137      */
138     DatagramChannelConfig setTimeToLive(int ttl);
139 
140     /**
141      * Gets the address of the network interface used for multicast packets.
142      */
143     InetAddress getInterface();
144 
145     /**
146      * Sets the address of the network interface used for multicast packets.
147      */
148     DatagramChannelConfig setInterface(InetAddress interfaceAddress);
149 
150     /**
151      * Gets the {@link StandardSocketOptions#IP_MULTICAST_IF} option.
152      */
153     NetworkInterface getNetworkInterface();
154 
155     /**
156      * Sets the {@link StandardSocketOptions#IP_MULTICAST_IF} option.
157      */
158     DatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface);
159 
160     @Override
161     @Deprecated
162     DatagramChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead);
163 
164     @Override
165     DatagramChannelConfig setWriteSpinCount(int writeSpinCount);
166 
167     @Override
168     DatagramChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis);
169 
170     @Override
171     DatagramChannelConfig setAllocator(ByteBufAllocator allocator);
172 
173     @Override
174     DatagramChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
175 
176     @Override
177     DatagramChannelConfig setAutoRead(boolean autoRead);
178 
179     @Override
180     DatagramChannelConfig setAutoClose(boolean autoClose);
181 
182     @Override
183     DatagramChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator);
184 
185     @Override
186     DatagramChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark);
187 
188 }