use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class Util_jni method socketClose0.
/* @formatter:on */
/* Do not re-format commented-out code: @formatter:off */
// 829 /*
// 830 * Class: java_net_PlainSocketImpl
// 831 * Method: socketClose0
// 832 * Signature: (Z)V
// 833 */
// 834 JNIEXPORT void JNICALL
// 835 Java_java_net_PlainSocketImpl_socketClose0(JNIEnv *env, jobject this,
// 836 jboolean useDeferredClose) {
@Substitute
void socketClose0(boolean useDeferredClose) throws IOException {
// 838 jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
FileDescriptor fdObj = Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).fd;
// 839 jint fd;
int fd;
// 841 if (IS_NULL(fdObj)) {
if (fdObj == null) {
// 843 "socket already closed");
throw new SocketException("socket already closed");
// 844 return;
} else {
// 846 fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
fd = Util_java_io_FileDescriptor.getFD(fdObj);
}
// 848 if (fd != -1) {
if (fd != -1) {
// 849 if (useDeferredClose && marker_fd >= 0) {
if (useDeferredClose && (Util_java_net_PlainSocketImpl.marker_fd >= 0)) {
// 850 NET_Dup2(marker_fd, fd);
JavaNetNetUtilMD.NET_Dup2(Util_java_net_PlainSocketImpl.marker_fd, fd);
} else {
// 852 (*env)->SetIntField(env, fdObj, IO_fd_fdID, -1);
Util_java_io_FileDescriptor.setFD(fdObj, -1);
// 853 NET_SocketClose(fd);
JavaNetNetUtilMD.NET_SocketClose(fd);
}
}
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class Util_jni method socketAvailable.
/* Do not re-format commented-out code: @formatter:off */
// 798 /*
// 799 * Class: java_net_PlainSocketImpl
// 800 * Method: socketAvailable
// 801 * Signature: ()I
// 802 */
// 803 JNIEXPORT jint JNICALL
// 804 Java_java_net_PlainSocketImpl_socketAvailable(JNIEnv *env, jobject this) {
@Substitute
int socketAvailable() throws IOException {
// 806 jint ret = -1;
CIntPointer ret_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
ret_Pointer.write(-1);
// 807 jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
FileDescriptor fdObj = Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).fd;
// 808 jint fd;
int fd;
// 810 if (IS_NULL(fdObj)) {
if (fdObj == null) {
// 812 "Socket closed");
throw new SocketException("Socket closed");
// 813 return -1;
} else {
// 815 fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
fd = Util_java_io_FileDescriptor.getFD(fdObj);
}
// 818 if (!JVM_SocketAvailable(fd, &ret)){
if (!CTypeConversion.toBoolean(VmPrimsJVM.JVM_SocketAvailable(fd, ret_Pointer))) {
// 819 if (errno == ECONNRESET) {
if (Errno.errno() == Errno.ECONNRESET()) {
// 820 JNU_ThrowByName(env, "sun/net/ConnectionResetException", "");
throw new sun.net.ConnectionResetException("");
} else {
// 823 "ioctl FIONREAD failed");
throw new SocketException("ioctl FIONREAD failed");
}
}
// 826 return ret;
return ret_Pointer.read();
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class Util_jni method socketBind.
/* @formatter:on */
/* Do not re-format commented-out code: @formatter:off */
// 543 /*
// 544 * Class: java_net_PlainSocketImpl
// 545 * Method: socketBind
// 546 * Signature: (Ljava/net/InetAddress;I)V
// 547 */
// 548 JNIEXPORT void JNICALL
// 549 Java_java_net_PlainSocketImpl_socketBind(JNIEnv *env, jobject this,
// 550 jobject iaObj, jint localport) {
@Substitute
void socketBind(InetAddress iaObj, int localportArg) throws IOException {
int localport = localportArg;
// 552 /* fdObj is the FileDescriptor field on this */
// 553 jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
FileDescriptor fdObj = Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).fd;
// 554 /* fd is an int field on fdObj */
// 555 int fd;
int fd;
// 556 int len;
CIntPointer len_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
len_Pointer.write(0);
// 557 SOCKADDR him;
Socket.sockaddr him = StackValue.get(JavaNetNetUtilMD.SOCKADDR_LEN());
// 559 if (IS_NULL(fdObj)) {
if (fdObj == null) {
// 562 return;
throw new SocketException("Socket closed");
} else {
// 564 fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
fd = Util_java_io_FileDescriptor.getFD(fdObj);
}
// 566 if (IS_NULL(iaObj)) {
if (iaObj == null) {
// 568 return;
throw new NullPointerException("iaObj is null.");
}
// 572 if (NET_InetAddressToSockaddr(env, iaObj, localport, (struct sockaddr *)&him, &len, JNI_TRUE) != 0) {
if (JavaNetNetUtilMD.NET_InetAddressToSockaddr(iaObj, localport, him, len_Pointer, Util_jni.JNI_TRUE()) != 0) {
// 573 return;
return;
}
// 575 setDefaultScopeID(env, (struct sockaddr *)&him);
JavaNetNetUtilMD.setDefaultScopeID(him);
// 577 if (NET_Bind(fd, (struct sockaddr *)&him, len) < 0) {
if (JavaNetNetUtilMD.NET_Bind(fd, him, len_Pointer.read()) < 0) {
// 579 errno == EPERM || errno == EACCES) {
if (//
Errno.errno() == Errno.EADDRINUSE() || Errno.errno() == Errno.EADDRNOTAVAIL() || Errno.errno() == Errno.EPERM() || Errno.errno() == Errno.EACCES()) {
// 581 "Bind failed");
throw new BindException("Bind failed");
} else {
// 584 "Bind failed");
throw new SocketException("Bind failed");
}
// 586 return;
}
// 589 /* set the address */
// 590 (*env)->SetObjectField(env, this, psi_addressID, iaObj);
Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).address = iaObj;
// 593 if (localport == 0) {
if (localport == 0) {
// 597 if (JVM_GetSockName(fd, (struct sockaddr *)&him, &len) == -1) {
if (VmPrimsJVM.JVM_GetSockName(fd, him, len_Pointer) == -1) {
// 600 return;
throw new SocketException("Error getting socket name");
}
// 602 localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
localport = JavaNetNetUtilMD.NET_GetPortFromSockaddr(him);
// 603 (*env)->SetIntField(env, this, psi_localportID, localport);
Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).localport = localport;
} else {
// 605 (*env)->SetIntField(env, this, psi_localportID, localport);
Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).localport = localport;
}
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class Util_jni method convert0.
/* @formatter:on */
/* Do not re-format commented-out code: @formatter:off */
// 094 /**
// 095 * Converts an existing file descriptor, that references an unbound TCP socket,
// 096 * to SDP.
// 097 */
// 098 JNIEXPORT void JNICALL
// 099 Java_sun_net_sdp_SdpSupport_convert0(JNIEnv *env, jclass cls, int fd)
// 100 {
@Substitute
static void convert0(int fd) throws IOException {
// 101 int s = create(env);
int s = Util_sun_net_sdp_SdpSupport.create();
// 102 if (s >= 0) {
if (s >= 0) {
// 103 socklen_t len;
CIntPointer len_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
// 104 int arg, res;
CIntPointer arg_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
int res;
// 105 struct linger linger;
Socket.linger linger = StackValue.get(SizeOf.get(Socket.linger.class));
// 107 /* copy socket options that are relevant to SDP */
// 108 len = sizeof(arg);
len_Pointer.write(SizeOf.get(CIntPointer.class));
// 109 if (getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, &len) == 0)
if (Socket.getsockopt(fd, Socket.SOL_SOCKET(), Socket.SO_REUSEADDR(), arg_Pointer, len_Pointer) == 0) {
// 110 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, len);
Socket.setsockopt(s, Socket.SOL_SOCKET(), Socket.SO_REUSEADDR(), arg_Pointer, len_Pointer.read());
}
// 111 len = sizeof(arg);
len_Pointer.write(SizeOf.get(CIntPointer.class));
// 112 if (getsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char*)&arg, &len) == 0)
if (Socket.getsockopt(fd, Socket.SOL_SOCKET(), Socket.SO_OOBINLINE(), arg_Pointer, len_Pointer) == 0) {
// 113 setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char*)&arg, len);
Socket.setsockopt(s, Socket.SOL_SOCKET(), Socket.SO_OOBINLINE(), arg_Pointer, len_Pointer.read());
}
// 114 len = sizeof(linger);
len_Pointer.write(SizeOf.get(Socket.linger.class));
// 115 if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (void*)&linger, &len) == 0)
if (Socket.getsockopt(fd, Socket.SOL_SOCKET(), Socket.SO_LINGER(), linger, len_Pointer) == 0) {
// 116 setsockopt(s, SOL_SOCKET, SO_LINGER, (char*)&linger, len);
Socket.setsockopt(s, Socket.SOL_SOCKET(), Socket.SO_LINGER(), linger, len_Pointer.read());
}
// 118 RESTARTABLE(dup2(s, fd), res);
do {
res = Unistd.dup2(s, fd);
} while ((res == -1) && (Errno.errno() == Errno.EINTR()));
// 119 if (res < 0)
if (res < 0) {
// 120 JNU_ThrowIOExceptionWithLastError(env, "dup2");
throw new IOException("dup2");
}
// 121 RESTARTABLE(close(s), res);
do {
res = Unistd.close(fd);
} while ((res == -1) && (Errno.errno() == Errno.EINTR()));
}
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class Util_jni method socketListen.
/* @formatter:on */
/* Do not re-format commented-out code: @formatter:off */
@Substitute
// 616 jint count) {
void socketListen(int countArg) throws IOException {
int count = countArg;
// 618 /* this FileDescriptor fd field */
// 619 jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
FileDescriptor fdObj = Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).fd;
// 620 /* fdObj's int fd field */
// 621 int fd;
int fd;
// 623 if (IS_NULL(fdObj)) {
if (fdObj == null) {
// 626 return;
throw new SocketException("Socket closed");
} else {
// 628 fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
fd = Util_java_io_FileDescriptor.getFD(fdObj);
}
// 635 if (count == 0x7fffffff)
if (count == Integer.MAX_VALUE) {
// 636 count -= 1;
count -= 1;
}
// 638 if (JVM_Listen(fd, count) == JVM_IO_ERR) {
if (VmPrimsJVM.JVM_Listen(fd, count) == JavavmExportJvm.JvmIoErrorCode.JVM_IO_ERR()) {
// 640 "Listen failed");
throw new SocketException("Listen failed");
}
}
Aggregations