Skip to content

Commit

Permalink
deduplicate the raw can read buffer allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
pschichtel committed Mar 8, 2024
1 parent c8372bd commit cf859e7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions core/src/main/java/tel/schich/javacan/RawCanChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,19 @@ public synchronized boolean isBound() {
return this.device != null;
}

private ByteBuffer allocateBuffer() throws IOException {
int length = getOption(CanSocketOptions.FD_FRAMES) ? FD_MTU : MTU;
return JavaCAN.allocateOrdered(length);
}

@Override
public CanFrame read() throws IOException {
int length = getOption(CanSocketOptions.FD_FRAMES) ? FD_MTU : MTU;
ByteBuffer frameBuf = JavaCAN.allocateOrdered(length);
return read(frameBuf);
return read(allocateBuffer());
}

@Override
public CanFrame receive() throws IOException {
int length = getOption(CanSocketOptions.FD_FRAMES) ? FD_MTU : MTU;
ByteBuffer frameBuf = JavaCAN.allocateOrdered(length);
return receive(frameBuf);
return receive(allocateBuffer());
}

@Override
Expand Down

0 comments on commit cf859e7

Please sign in to comment.