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

NativeSocketChannel.read() does not take ByteBuffer's position() into account #18

Open
shenberg opened this issue Aug 18, 2016 · 2 comments
Milestone

Comments

@shenberg
Copy link

Reading into a direct byte buffer always starts from position 0 (the call to libc.read() passes the ByteBuffer's address using jnr.invoke.AsmRuntime.longValue() instead of using BufferParameterStrategy.address() to obtain the bytebuffer's address, which disregards its position().

replication:

public static void main(String[] args) throws IOException {        
        UnixSocketChannel[] pair = UnixSocketChannel.pair();
        ByteBuffer src = ByteBuffer.allocate(1);
        src.put((byte)0);
        src.clear();
        pair[0].write(src);
        ByteBuffer dst = ByteBuffer.allocateDirect(2);
        pair[1].read(dst);
        src.clear();
        src.put((byte)5);
        src.clear();
        pair[0].write(src);
        pair[1].read(dst);
        System.out.println(dst.get(0)); // prints '5' (should print 0)
        System.out.println(dst.get(1)); // prints '0' (uninitialized)
}
@headius
Copy link
Member

headius commented Sep 28, 2016

This did not make latest release, but I think you're right. Wanna help out with a PR?

@headius headius added this to the 0.14 milestone Sep 28, 2016
@shenberg
Copy link
Author

I'm traveling till Oct 13, I'll give it a look when I'm back. It seems like
the change should be very small.

On Wed, Sep 28, 2016 at 3:24 PM, Charles Oliver Nutter <
notifications@github.com> wrote:

This did not make latest release, but I think you're right. Wanna help out
with a PR?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#18 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAn6lBkDgrJMwSCi4zafZKFxKjsiXPu4ks5quukAgaJpZM4JnZMQ
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants