forked from java-native-access/jna
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it more flexible in terms of supporting GSO (java-native-access#222
- Loading branch information
1 parent
19625e5
commit 91c90cb
Showing
6 changed files
with
140 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/io/netty/incubator/codec/quic/SegmentedDatagramPacketAllocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2021 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.incubator.codec.quic; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.socket.DatagramPacket; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
/** | ||
* Used to allocate datagram packets that use UDP_SEGMENT (GSO). | ||
*/ | ||
public interface SegmentedDatagramPacketAllocator { | ||
|
||
/** | ||
* {@link SegmentedDatagramPacketAllocator} which should be used if no UDP_SEGMENT is supported and used. | ||
*/ | ||
SegmentedDatagramPacketAllocator NONE = new SegmentedDatagramPacketAllocator() { | ||
@Override | ||
public int maxNumSegments() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public DatagramPacket newPacket(ByteBuf buffer, int segmentSize, InetSocketAddress remoteAddress) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
}; | ||
|
||
/** | ||
* The maximum number of segments to use per packet. | ||
* | ||
* @return the segments. | ||
*/ | ||
int maxNumSegments(); | ||
|
||
/** | ||
* Return a new segmented {@link DatagramPacket}. | ||
* | ||
* @param buffer the {@link ByteBuf} that is used as content. | ||
* @param segmentSize the size of each segment. | ||
* @param remoteAddress the remote address to send to. | ||
* @return the packet. | ||
*/ | ||
DatagramPacket newPacket(ByteBuf buffer, int segmentSize, InetSocketAddress remoteAddress); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/io/netty/incubator/codec/quic/EpollSegmentedDatagramPacketAllocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2021 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.incubator.codec.quic; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.epoll.SegmentedDatagramPacket; | ||
import io.netty.channel.socket.DatagramPacket; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
final class EpollSegmentedDatagramPacketAllocator implements SegmentedDatagramPacketAllocator { | ||
|
||
private final int maxNumSegments; | ||
|
||
EpollSegmentedDatagramPacketAllocator(int maxNumSegments) { | ||
this.maxNumSegments = maxNumSegments; | ||
} | ||
|
||
@Override | ||
public int maxNumSegments() { | ||
return maxNumSegments; | ||
} | ||
|
||
@Override | ||
public DatagramPacket newPacket(ByteBuf buffer, int segmentSize, InetSocketAddress remoteAddress) { | ||
return new SegmentedDatagramPacket(buffer, segmentSize, remoteAddress); | ||
} | ||
|
||
static boolean isSupported() { | ||
return SegmentedDatagramPacket.isSupported(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters