jdk/src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c
changeset 32503 1478c9130534
parent 25859 3317bb8137f4
child 41214 855ac576eb77
equal deleted inserted replaced
32502:03f7450aec42 32503:1478c9130534
     1 /*
     1 /*
     2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    68     }
    68     }
    69 
    69 
    70     return got_icmp;
    70     return got_icmp;
    71 }
    71 }
    72 
    72 
       
    73 static jfieldID IO_fd_fdID = NULL;
       
    74 static jfieldID pdsi_fdID = NULL;
       
    75 
    73 /*
    76 /*
    74  * Class:     java_net_DualStackPlainDatagramSocketImpl
    77  * Class:     java_net_DualStackPlainDatagramSocketImpl
    75  * Method:    initIDs
    78  * Method:    initIDs
    76  * Signature: ()V
    79  * Signature: ()V
    77  */
    80  */
    78 JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_initIDs
    81 JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_initIDs
    79   (JNIEnv *env, jclass clazz)
    82   (JNIEnv *env, jclass clazz)
    80 {
    83 {
       
    84     pdsi_fdID = (*env)->GetFieldID(env, clazz, "fd",
       
    85                                    "Ljava/io/FileDescriptor;");
       
    86     CHECK_NULL(pdsi_fdID);
       
    87     IO_fd_fdID = NET_GetFileDescriptorID(env);
       
    88     CHECK_NULL(IO_fd_fdID);
       
    89     JNU_CHECK_EXCEPTION(env);
       
    90 
    81     initInetAddressIDs(env);
    91     initInetAddressIDs(env);
    82 }
    92 }
    83 
    93 
    84 /*
    94 /*
    85  * Class:     java_net_DualStackPlainDatagramSocketImpl
    95  * Class:     java_net_DualStackPlainDatagramSocketImpl
   501         return -1;
   511         return -1;
   502     }
   512     }
   503 
   513 
   504     return result;
   514     return result;
   505 }
   515 }
       
   516 
       
   517 /*
       
   518  * Class:     java_net_DualStackPlainDatagramSocketImpl
       
   519  * Method:    dataAvailable
       
   520  * Signature: ()I
       
   521  */
       
   522 JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_dataAvailable
       
   523 (JNIEnv *env, jobject this) {
       
   524     SOCKET fd;
       
   525     int  rv = -1;
       
   526     jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
       
   527 
       
   528     if (!IS_NULL(fdObj)) {
       
   529         int retval = 0;
       
   530         fd = (SOCKET)(*env)->GetIntField(env, fdObj, IO_fd_fdID);
       
   531         rv = ioctlsocket(fd, FIONREAD, &retval);
       
   532         if (retval > 0) {
       
   533             return retval;
       
   534         }
       
   535     }
       
   536 
       
   537     if (rv < 0) {
       
   538         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
       
   539                         "Socket closed");
       
   540         return -1;
       
   541     }
       
   542 
       
   543     return 0;
       
   544 }