Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only read from remote when buffer isn't full #54

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class AnonymousTcpSession(
handleReturnTrafficLoop(maxRead)
} else {
logger.warn("No more space in outgoing buffer, waiting for more space")
changeRequests.add(ChangeRequest(channel, ChangeRequest.CHANGE_OPS, 0))
0
}
if (len < 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jasonernst.kanonproxy.tcp

import com.jasonernst.kanonproxy.BidirectionalByteChannel
import com.jasonernst.kanonproxy.ChangeRequest
import com.jasonernst.knet.Packet
import com.jasonernst.knet.network.ip.IpHeader
import com.jasonernst.knet.network.ip.IpType
Expand All @@ -23,6 +24,9 @@ import org.slf4j.LoggerFactory
import java.net.Inet4Address
import java.net.Inet6Address
import java.nio.ByteBuffer
import java.nio.channels.DatagramChannel
import java.nio.channels.SelectionKey.OP_READ
import java.nio.channels.SocketChannel
import java.util.ArrayList
import java.util.concurrent.ConcurrentLinkedQueue
import kotlin.jvm.javaClass
Expand Down Expand Up @@ -2042,6 +2046,31 @@ class TcpStateMachine(
tcbMutex.unlock()
logger.warn("ENCAP PACKETS LOCK RELEASED")
}

if (outgoingBuffer.remaining() > 0) {
// let the channel know we're ready to read again
if (session.channel is SocketChannel) {
synchronized(session.changeRequests) {
session.changeRequests.add(
ChangeRequest(
session.channel as SocketChannel,
ChangeRequest.CHANGE_OPS,
OP_READ,
),
)
}
} else if (session.channel is DatagramChannel) {
synchronized(session.changeRequests) {
session.changeRequests.add(
ChangeRequest(
session.channel as DatagramChannel,
ChangeRequest.CHANGE_OPS,
OP_READ,
),
)
}
}
}
}
if (packets.isNotEmpty()) {
if (rtoJob == null) {
Expand Down
Loading