src/solaris/native/sun/nio/ch/DevPollArrayWrapper.c

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 #include "jni.h"
  27 #include "jni_util.h"
  28 #include "jvm.h"
  29 #include "jlong.h"
  30 #include "sun_nio_ch_DevPollArrayWrapper.h"

  31 #include <sys/poll.h>
  32 #include <sys/resource.h>
  33 #include <unistd.h>
  34 #include <sys/time.h>
  35 
  36 #ifdef  __cplusplus
  37 extern "C" {
  38 #endif
  39 
  40 typedef uint32_t        caddr32_t;
  41 
  42 /* /dev/poll ioctl */
  43 #define         DPIOC   (0xD0 << 8)
  44 #define DP_POLL         (DPIOC | 1)     /* poll on fds in cached in /dev/poll */
  45 #define DP_ISPOLLED     (DPIOC | 2)     /* is this fd cached in /dev/poll */
  46 #define DEVPOLLSIZE     1000            /* /dev/poll table size increment */
  47 #define POLLREMOVE      0x0800          /* Removes fd from monitored set */
  48 
  49 /*
  50  * /dev/poll DP_POLL ioctl format


 175         RESTARTABLE (ioctl(wfd, DP_POLL, &a), result);
 176     } else {                        /* Bounded wait; bounded restarts */
 177         result = idevpoll(wfd, DP_POLL, a);
 178     }
 179 
 180     if (result < 0) {
 181         JNU_ThrowIOExceptionWithLastError(env, "Error reading driver");
 182         return -1;
 183     }
 184     return result;
 185 }
 186 
 187 JNIEXPORT jint JNICALL
 188 Java_sun_nio_ch_DevPollArrayWrapper_fdLimit(JNIEnv *env, jclass this)
 189 {
 190     struct rlimit rlp;
 191     if (getrlimit(RLIMIT_NOFILE, &rlp) < 0) {
 192         JNU_ThrowIOExceptionWithLastError(env,
 193                                           "getrlimit failed");
 194     }



 195     return (jint)rlp.rlim_max;

 196 }
 197 
 198 JNIEXPORT void JNICALL
 199 Java_sun_nio_ch_DevPollArrayWrapper_interrupt(JNIEnv *env, jclass this, jint fd)
 200 {
 201     int fakebuf[1];
 202     fakebuf[0] = 1;
 203     if (write(fd, fakebuf, 1) < 0) {
 204         JNU_ThrowIOExceptionWithLastError(env,
 205                                           "Write to interrupt fd failed");
 206     }
 207 }


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 #include "jni.h"
  27 #include "jni_util.h"
  28 #include "jvm.h"
  29 #include "jlong.h"
  30 #include "sun_nio_ch_DevPollArrayWrapper.h"
  31 #include "java_lang_Integer.h"
  32 #include <sys/poll.h>
  33 #include <sys/resource.h>
  34 #include <unistd.h>
  35 #include <sys/time.h>
  36 
  37 #ifdef  __cplusplus
  38 extern "C" {
  39 #endif
  40 
  41 typedef uint32_t        caddr32_t;
  42 
  43 /* /dev/poll ioctl */
  44 #define         DPIOC   (0xD0 << 8)
  45 #define DP_POLL         (DPIOC | 1)     /* poll on fds in cached in /dev/poll */
  46 #define DP_ISPOLLED     (DPIOC | 2)     /* is this fd cached in /dev/poll */
  47 #define DEVPOLLSIZE     1000            /* /dev/poll table size increment */
  48 #define POLLREMOVE      0x0800          /* Removes fd from monitored set */
  49 
  50 /*
  51  * /dev/poll DP_POLL ioctl format


 176         RESTARTABLE (ioctl(wfd, DP_POLL, &a), result);
 177     } else {                        /* Bounded wait; bounded restarts */
 178         result = idevpoll(wfd, DP_POLL, a);
 179     }
 180 
 181     if (result < 0) {
 182         JNU_ThrowIOExceptionWithLastError(env, "Error reading driver");
 183         return -1;
 184     }
 185     return result;
 186 }
 187 
 188 JNIEXPORT jint JNICALL
 189 Java_sun_nio_ch_DevPollArrayWrapper_fdLimit(JNIEnv *env, jclass this)
 190 {
 191     struct rlimit rlp;
 192     if (getrlimit(RLIMIT_NOFILE, &rlp) < 0) {
 193         JNU_ThrowIOExceptionWithLastError(env,
 194                                           "getrlimit failed");
 195     }
 196     if (rlp.rlim_max < 0 || rlp.rlim_max > java_lang_Integer_MAX_VALUE) {
 197         return java_lang_Integer_MAX_VALUE;
 198     } else {
 199         return (jint)rlp.rlim_max;
 200     }
 201 }
 202 
 203 JNIEXPORT void JNICALL
 204 Java_sun_nio_ch_DevPollArrayWrapper_interrupt(JNIEnv *env, jclass this, jint fd)
 205 {
 206     int fakebuf[1];
 207     fakebuf[0] = 1;
 208     if (write(fd, fakebuf, 1) < 0) {
 209         JNU_ThrowIOExceptionWithLastError(env,
 210                                           "Write to interrupt fd failed");
 211     }
 212 }