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