src/java.base/unix/native/libnet/PlainSocketImpl.c
changeset 53422 6f02e036630e
parent 50275 69204b98dc3d
child 54627 22323f20401b
--- a/src/java.base/unix/native/libnet/PlainSocketImpl.c	Thu Jan 03 17:39:39 2019 +0800
+++ b/src/java.base/unix/native/libnet/PlainSocketImpl.c	Tue Jan 22 16:39:52 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -740,8 +740,7 @@
  */
 JNIEXPORT jint JNICALL
 Java_java_net_PlainSocketImpl_socketAvailable(JNIEnv *env, jobject this) {
-
-    jint ret = -1;
+    int count = 0;
     jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
     jint fd;
 
@@ -752,8 +751,7 @@
     } else {
         fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
     }
-    /* NET_SocketAvailable returns 0 for failure, 1 for success */
-    if (NET_SocketAvailable(fd, &ret) == 0){
+    if (NET_SocketAvailable(fd, &count) != 0) {
         if (errno == ECONNRESET) {
             JNU_ThrowByName(env, "sun/net/ConnectionResetException", "");
         } else {
@@ -761,7 +759,7 @@
                 (env, JNU_JAVANETPKG "SocketException", "ioctl FIONREAD failed");
         }
     }
-    return ret;
+    return (jint) count;
 }
 
 /*