8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer

Alan Bateman Alan.Bateman at oracle.com
Tue Jan 22 08:40:03 UTC 2019



On 22/01/2019 08:07, Langer, Christoph wrote:
> Hi Alan,
>
> the change looks good to me.
>
> In src/java.base/unix/native/libnio/ch/Net.c and src/java.base/windows/native/libnio/ch/Net.c you could change the code from
>
> ...
> int n = NET_SocketAvailable(fdval(env, fdo), &count);
> if (n != 0) {
> ...
>
> to one line
> if (NET_SocketAvailable(fdval(env, fdo), &count) != 0) {
>
> as it is done in src/java.base/unix/native/libnet/PlainSocketImpl.c
>
> The variable n is not used except for the returncode check.
Sometimes it is useful to have a variable when debugging but point taken 
that it is inconsistent between the two implementations.

>
> By the way, looking at the 2 implementations of Net.c for unix resp. windows, it seems they have quite some code in common. Isn't that something where the shared parts could be merged into one file?
>
Most of the native methods in the Windows implementation are very 
different so I would prefer not do this. Also I hope to eventually 
remove NET_SocketAvailable from libnet as part of work to replace the 
legacy SocketImpl implementations so it means sun.nio.ch.Net.available 
will have different implementations.

-Alan


More information about the net-dev mailing list