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.
Add FlushStrategy to be even more flexible (java-native-access#228)
Motivation: 85d313b added some sort of auto flushing after X bytes. While this works very well in practice some users may need something more flexible. Modifications: Add FlushStrategy as an API that can be used to influence how flushes are executed. Add a default implementation which flushes after X bytes (just as we did before) Result: More flexible way of influence when flushes happen
- Loading branch information
1 parent
85d313b
commit 2423c2f
Showing
7 changed files
with
89 additions
and
28 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/java/io/netty/incubator/codec/quic/FlushStrategy.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,60 @@ | ||
/* | ||
* 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.util.internal.ObjectUtil; | ||
|
||
/** | ||
* Allows to configure a strategy for when flushes should be happening. | ||
*/ | ||
public interface FlushStrategy { | ||
|
||
/** | ||
* Default {@link FlushStrategy} implementation. | ||
*/ | ||
FlushStrategy DEFAULT = afterNumBytes(20 * Quic.MAX_DATAGRAM_SIZE); | ||
|
||
/** | ||
* Returns {@code true} if a flush should happen now, {@code false} otherwise. | ||
* | ||
* @param numPackets the number of packets that were written since the last flush. | ||
* @param numBytes the number of bytes that were written since the last flush. | ||
* @return {@code true} if a flush should be done now, {@code false} otherwise. | ||
*/ | ||
boolean shouldFlushNow(int numPackets, int numBytes); | ||
|
||
/** | ||
* Implementation that flushes after a number of bytes. | ||
* | ||
* @param bytes the number of bytes after which we should issue a flush. | ||
* @return the {@link FlushStrategy}. | ||
*/ | ||
static FlushStrategy afterNumBytes(int bytes) { | ||
ObjectUtil.checkPositive(bytes, "bytes"); | ||
return (numPackets, numBytes) -> numBytes > bytes; | ||
} | ||
|
||
/** | ||
* Implementation that flushes after a number of packets. | ||
* | ||
* @param packets the number of packets after which we should issue a flush. | ||
* @return the {@link FlushStrategy}. | ||
*/ | ||
static FlushStrategy afterNumPackets(int packets) { | ||
ObjectUtil.checkPositive(packets, "packets"); | ||
return (numPackets, numBytes) -> numPackets > packets; | ||
} | ||
} |
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
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