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.handler.codec.quic;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.channel.socket.DatagramPacket;
20  
21  import java.net.InetSocketAddress;
22  
23  /**
24   * Used to allocate datagram packets that use UDP_SEGMENT (GSO).
25   */
26  @FunctionalInterface
27  public interface SegmentedDatagramPacketAllocator {
28  
29      /**
30       * {@link SegmentedDatagramPacketAllocator} which should be used if no UDP_SEGMENT is supported and used.
31       */
32      SegmentedDatagramPacketAllocator NONE = new SegmentedDatagramPacketAllocator() {
33          @Override
34          public int maxNumSegments() {
35              return 0;
36          }
37  
38          @Override
39          public DatagramPacket newPacket(ByteBuf buffer, int segmentSize, InetSocketAddress remoteAddress) {
40              throw new UnsupportedOperationException();
41          }
42      };
43  
44      /**
45       * The maximum number of segments to use per packet. By default this is {@code 10} but this may be overridden by
46       * the implementation of the interface.
47       *
48       * @return  the segments.
49       */
50      default int maxNumSegments() {
51          return 10;
52      }
53  
54      /**
55       * Return a new segmented {@link DatagramPacket}.
56       *
57       * @param buffer        the {@link ByteBuf} that is used as content.
58       * @param segmentSize   the size of each segment.
59       * @param remoteAddress the remote address to send to.
60       * @return              the packet.
61       */
62      DatagramPacket newPacket(ByteBuf buffer, int segmentSize, InetSocketAddress remoteAddress);
63  }