Skip to content

Commit

Permalink
Merge pull request #51 from gregw/issue-50
Browse files Browse the repository at this point in the history
Fix #50 buffer consumed on flow controlled write
  • Loading branch information
headius authored May 16, 2018
2 parents 8348819 + f96f134 commit 9e2d0bd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/jnr/enxio/channels/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,25 @@ long read(ByteBuffer[] dsts, int offset, int length)

int write(ByteBuffer src) throws IOException {

ByteBuffer buffer = ByteBuffer.allocate(src.remaining());

int r = src.remaining();

ByteBuffer buffer = ByteBuffer.allocate(r);

buffer.put(src);

buffer.position(0);

int n = Native.write(_fd, buffer);

if (n < 0) {
if (n >=0 ) {
if (n < r) {
src.position(src.position()-(r-n));
}
} else {
switch (Native.getLastError()) {
case EAGAIN:
case EWOULDBLOCK:
src.position(src.position()-r);
return 0;
default:
throw new IOException(Native.getLastErrorString());
Expand Down

0 comments on commit 9e2d0bd

Please sign in to comment.