View Javadoc
1   /*
2    * Copyright 2021 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.epoll;
17  
18  import io.netty.buffer.ByteBuf;
19  
20  import java.net.InetSocketAddress;
21  
22  /**
23   * @deprecated use {@link io.netty.channel.unix.SegmentedDatagramPacket}.
24   */
25  @Deprecated
26  public final class SegmentedDatagramPacket extends io.netty.channel.unix.SegmentedDatagramPacket {
27  
28      /**
29       * Create a new instance.
30       *
31       * @param data          the {@link ByteBuf} which must be continguous.
32       * @param segmentSize   the segment size.
33       * @param recipient     the recipient.
34       */
35      public SegmentedDatagramPacket(ByteBuf data, int segmentSize, InetSocketAddress recipient) {
36          super(data, segmentSize, recipient);
37          checkIsSupported();
38      }
39  
40      /**
41       * Create a new instance.
42       *
43       * @param data          the {@link ByteBuf} which must be continguous.
44       * @param segmentSize   the segment size.
45       * @param recipient     the recipient.
46       */
47      public SegmentedDatagramPacket(ByteBuf data, int segmentSize,
48                                     InetSocketAddress recipient, InetSocketAddress sender) {
49          super(data, segmentSize, recipient, sender);
50          checkIsSupported();
51      }
52  
53      /**
54       * Returns {@code true} if the underlying system supports GSO.
55       */
56      public static boolean isSupported() {
57          return Epoll.isAvailable() &&
58                  // We only support it together with sendmmsg(...)
59                  Native.IS_SUPPORTING_SENDMMSG && Native.IS_SUPPORTING_UDP_SEGMENT;
60      }
61  
62      @Override
63      public SegmentedDatagramPacket copy() {
64          return new SegmentedDatagramPacket(content().copy(), segmentSize(), recipient(), sender());
65      }
66  
67      @Override
68      public SegmentedDatagramPacket duplicate() {
69          return new SegmentedDatagramPacket(content().duplicate(), segmentSize(), recipient(), sender());
70      }
71  
72      @Override
73      public SegmentedDatagramPacket retainedDuplicate() {
74          return new SegmentedDatagramPacket(content().retainedDuplicate(), segmentSize(), recipient(), sender());
75      }
76  
77      @Override
78      public SegmentedDatagramPacket replace(ByteBuf content) {
79          return new SegmentedDatagramPacket(content, segmentSize(), recipient(), sender());
80      }
81  
82      @Override
83      public SegmentedDatagramPacket retain() {
84          super.retain();
85          return this;
86      }
87  
88      @Override
89      public SegmentedDatagramPacket retain(int increment) {
90          super.retain(increment);
91          return this;
92      }
93  
94      @Override
95      public SegmentedDatagramPacket touch() {
96          super.touch();
97          return this;
98      }
99  
100     @Override
101     public SegmentedDatagramPacket touch(Object hint) {
102         super.touch(hint);
103         return this;
104     }
105 
106     private static void checkIsSupported() {
107         if (!isSupported()) {
108             throw new IllegalStateException();
109         }
110     }
111 }