src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c

Print this page
rev 11363 : [mq]: 8072466-Deadlock-when-starting-MulticastSocket-and-DatagramSocket

*** 1,7 **** /* ! * Copyright (c) 1997, 2014, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2015, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 30,39 **** --- 30,45 ---- #include <sys/types.h> #include <sys/socket.h> #ifdef __solaris__ #include <fcntl.h> + #include <unistd.h> + #include <stropts.h> + + #ifndef BSD_COMP + #define BSD_COMP + #endif #endif #ifdef __linux__ #include <unistd.h> #include <sys/sysctl.h> #include <sys/utsname.h>
*** 50,59 **** --- 56,67 ---- #ifndef IP_MULTICAST_ALL #define IP_MULTICAST_ALL 49 #endif #endif // __linux__ + #include <sys/ioctl.h> + #ifndef IPTOS_TOS_MASK #define IPTOS_TOS_MASK 0x1e #endif #ifndef IPTOS_PREC_MASK #define IPTOS_PREC_MASK 0xe0
*** 2238,2242 **** --- 2246,2275 ---- Java_java_net_PlainDatagramSocketImpl_leave(JNIEnv *env, jobject this, jobject iaObj, jobject niObj) { mcast_join_leave(env, this, iaObj, niObj, JNI_FALSE); } + + /* + * Class: java_net_PlainDatagramSocketImpl + * Method: dataAvailable + * Signature: ()I + */ + JNIEXPORT jint JNICALL + Java_java_net_PlainDatagramSocketImpl_dataAvailable(JNIEnv *env, jobject this) + { + int fd, retval; + + jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID); + + if (IS_NULL(fdObj)) { + JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + "Socket closed"); + return -1; + } + fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + + if (ioctl(fd, FIONREAD, &retval) < 0) { + return -1; + } + return retval; + }