Skip to content

Commit

Permalink
TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilmann Zäschke committed Feb 28, 2024
1 parent 0c091ab commit 322ead9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/main/java/org/scion/AbstractDatagramChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,20 @@ public synchronized <T> C setOption(SocketOption<T> option, T t) throws IOExcept
} else {
throw new UnsupportedOperationException();
}
} else if (StandardSocketOptions.SO_RCVBUF.equals(option)) {
// TODO resize buf
channel.setOption(option, t);
} else if (StandardSocketOptions.SO_SNDBUF.equals(option)) {
// TODO resize buf
} else if (StandardSocketOptions.SO_RCVBUF.equals(option)
|| StandardSocketOptions.SO_SNDBUF.equals(option)) {
channel.setOption(option, t);
resizeBuffers(
channel.getOption(StandardSocketOptions.SO_RCVBUF),
channel.getOption(StandardSocketOptions.SO_SNDBUF));
} else {
channel.setOption(option, t);
}
return (C) this;
}

protected abstract void resizeBuffers(int sizeReceive, int sizeSend);

/**
* @param path path
* @param payloadLength payload length
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/scion/DatagramChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
public class DatagramChannel extends AbstractDatagramChannel<DatagramChannel>
implements ByteChannel, Closeable {

private final ByteBuffer bufferReceive;
private final ByteBuffer bufferSend;
private ByteBuffer bufferReceive;
private ByteBuffer bufferSend;

protected DatagramChannel(ScionService service, java.nio.channels.DatagramChannel channel)
throws IOException {
Expand Down Expand Up @@ -61,6 +61,16 @@ public synchronized boolean isBlocking() {
return super.isBlocking();
}

@Override
protected void resizeBuffers(int sizeReceive, int sizeSend) {
if (bufferReceive.capacity() != sizeReceive) {
bufferReceive = ByteBuffer.allocateDirect(sizeReceive);
}
if (bufferSend.capacity() != sizeSend) {
bufferSend = ByteBuffer.allocateDirect(sizeSend);
}
}

public synchronized ResponsePath receive(ByteBuffer userBuffer) throws IOException {
ResponsePath receivePath = receiveFromChannel(bufferReceive, InternalConstants.HdrTypes.UDP);
if (receivePath == null) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/scion/ScmpChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ private interface IOCallable<V> {
}

private class InternalChannel extends AbstractDatagramChannel<InternalChannel> {
private final ByteBuffer bufferReceive;
private final ByteBuffer bufferSend;
private ByteBuffer bufferReceive;
private ByteBuffer bufferSend;
private final Selector selector;

protected InternalChannel(ScionService service, RequestPath path, int port) throws IOException {
Expand Down Expand Up @@ -227,6 +227,16 @@ private ResponsePath receiveWithTimeout(ByteBuffer buffer) throws IOException {
}
}

@Override
protected void resizeBuffers(int sizeReceive, int sizeSend) {
if (bufferReceive.capacity() != sizeReceive) {
bufferReceive = ByteBuffer.allocateDirect(sizeReceive);
}
if (bufferSend.capacity() != sizeSend) {
bufferSend = ByteBuffer.allocateDirect(sizeSend);
}
}

@Override
public void close() throws IOException {
super.close();
Expand Down

0 comments on commit 322ead9

Please sign in to comment.