< prev index next >

src/java.base/unix/native/libnio/ch/DatagramDispatcher.c

Print this page
rev 53271 : 8216981: Per thread IO statistics in JFR


  33 #include "sun_nio_ch_DatagramDispatcher.h"
  34 #include <sys/types.h>
  35 #include <sys/uio.h>
  36 #include <sys/socket.h>
  37 #include <string.h>
  38 
  39 #include "nio_util.h"
  40 #include <limits.h>
  41 
  42 JNIEXPORT jint JNICALL
  43 Java_sun_nio_ch_DatagramDispatcher_read0(JNIEnv *env, jclass clazz,
  44                          jobject fdo, jlong address, jint len)
  45 {
  46     jint fd = fdval(env, fdo);
  47     void *buf = (void *)jlong_to_ptr(address);
  48     int result = recv(fd, buf, len, 0);
  49     if (result < 0 && errno == ECONNREFUSED) {
  50         JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0);
  51         return -2;
  52     }





  53     return convertReturnVal(env, result, JNI_TRUE);
  54 }
  55 
  56 
  57 JNIEXPORT jlong JNICALL
  58 Java_sun_nio_ch_DatagramDispatcher_readv0(JNIEnv *env, jclass clazz,
  59                               jobject fdo, jlong address, jint len)
  60 {
  61     jint fd = fdval(env, fdo);
  62     ssize_t result = 0;
  63     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
  64     struct msghdr m;
  65     if (len > IOV_MAX) {
  66         len = IOV_MAX;
  67     }
  68 
  69     // initialize the message
  70     memset(&m, 0, sizeof(m));
  71     m.msg_iov = iov;
  72     m.msg_iovlen = len;
  73 
  74     result = recvmsg(fd, &m, 0);
  75     if (result < 0 && errno == ECONNREFUSED) {
  76         JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0);
  77         return -2;
  78     }





  79     return convertLongReturnVal(env, (jlong)result, JNI_TRUE);
  80 }
  81 
  82 JNIEXPORT jint JNICALL
  83 Java_sun_nio_ch_DatagramDispatcher_write0(JNIEnv *env, jclass clazz,
  84                               jobject fdo, jlong address, jint len)
  85 {
  86     jint fd = fdval(env, fdo);
  87     void *buf = (void *)jlong_to_ptr(address);
  88     int result = send(fd, buf, len, 0);
  89     if (result < 0 && errno == ECONNREFUSED) {
  90         JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0);
  91         return -2;
  92     }





  93     return convertReturnVal(env, result, JNI_FALSE);
  94 }
  95 
  96 JNIEXPORT jlong JNICALL
  97 Java_sun_nio_ch_DatagramDispatcher_writev0(JNIEnv *env, jclass clazz,
  98                                        jobject fdo, jlong address, jint len)
  99 {
 100     jint fd = fdval(env, fdo);
 101     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
 102     struct msghdr m;
 103     ssize_t result = 0;
 104     if (len > IOV_MAX) {
 105         len = IOV_MAX;
 106     }
 107 
 108     // initialize the message
 109     memset(&m, 0, sizeof(m));
 110     m.msg_iov = iov;
 111     m.msg_iovlen = len;
 112 
 113     result = sendmsg(fd, &m, 0);
 114     if (result < 0 && errno == ECONNREFUSED) {
 115         JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0);
 116         return -2;
 117     }





 118     return convertLongReturnVal(env, (jlong)result, JNI_FALSE);
 119 }


  33 #include "sun_nio_ch_DatagramDispatcher.h"
  34 #include <sys/types.h>
  35 #include <sys/uio.h>
  36 #include <sys/socket.h>
  37 #include <string.h>
  38 
  39 #include "nio_util.h"
  40 #include <limits.h>
  41 
  42 JNIEXPORT jint JNICALL
  43 Java_sun_nio_ch_DatagramDispatcher_read0(JNIEnv *env, jclass clazz,
  44                          jobject fdo, jlong address, jint len)
  45 {
  46     jint fd = fdval(env, fdo);
  47     void *buf = (void *)jlong_to_ptr(address);
  48     int result = recv(fd, buf, len, 0);
  49     if (result < 0 && errno == ECONNREFUSED) {
  50         JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0);
  51         return -2;
  52     }
  53 
  54     if (result > 0) {
  55         JVM_callNetworkReadBytes(env, result);
  56     }
  57 
  58     return convertReturnVal(env, result, JNI_TRUE);
  59 }
  60 
  61 
  62 JNIEXPORT jlong JNICALL
  63 Java_sun_nio_ch_DatagramDispatcher_readv0(JNIEnv *env, jclass clazz,
  64                               jobject fdo, jlong address, jint len)
  65 {
  66     jint fd = fdval(env, fdo);
  67     ssize_t result = 0;
  68     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
  69     struct msghdr m;
  70     if (len > IOV_MAX) {
  71         len = IOV_MAX;
  72     }
  73 
  74     // initialize the message
  75     memset(&m, 0, sizeof(m));
  76     m.msg_iov = iov;
  77     m.msg_iovlen = len;
  78 
  79     result = recvmsg(fd, &m, 0);
  80     if (result < 0 && errno == ECONNREFUSED) {
  81         JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0);
  82         return -2;
  83     }
  84 
  85     if (result > 0) {
  86         JVM_callNetworkReadBytes(env, result);
  87     }
  88 
  89     return convertLongReturnVal(env, (jlong)result, JNI_TRUE);
  90 }
  91 
  92 JNIEXPORT jint JNICALL
  93 Java_sun_nio_ch_DatagramDispatcher_write0(JNIEnv *env, jclass clazz,
  94                               jobject fdo, jlong address, jint len)
  95 {
  96     jint fd = fdval(env, fdo);
  97     void *buf = (void *)jlong_to_ptr(address);
  98     int result = send(fd, buf, len, 0);
  99     if (result < 0 && errno == ECONNREFUSED) {
 100         JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0);
 101         return -2;
 102     }
 103 
 104     if (result > 0) {
 105         JVM_callNetworkWriteBytes(env, result);
 106     }
 107 
 108     return convertReturnVal(env, result, JNI_FALSE);
 109 }
 110 
 111 JNIEXPORT jlong JNICALL
 112 Java_sun_nio_ch_DatagramDispatcher_writev0(JNIEnv *env, jclass clazz,
 113                                        jobject fdo, jlong address, jint len)
 114 {
 115     jint fd = fdval(env, fdo);
 116     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
 117     struct msghdr m;
 118     ssize_t result = 0;
 119     if (len > IOV_MAX) {
 120         len = IOV_MAX;
 121     }
 122 
 123     // initialize the message
 124     memset(&m, 0, sizeof(m));
 125     m.msg_iov = iov;
 126     m.msg_iovlen = len;
 127 
 128     result = sendmsg(fd, &m, 0);
 129     if (result < 0 && errno == ECONNREFUSED) {
 130         JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0);
 131         return -2;
 132     }
 133 
 134     if (result > 0) {
 135         JVM_callNetworkWriteBytes(env, result);
 136     }
 137 
 138     return convertLongReturnVal(env, (jlong)result, JNI_FALSE);
 139 }
< prev index next >