use of org.graalvm.nativeimage.c.type.CIntPointer 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 org.graalvm.nativeimage.c.type.CIntPointer 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 org.graalvm.nativeimage.c.type.CIntPointer 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 org.graalvm.nativeimage.c.type.CIntPointer in project graal by oracle.
the class JavavmExportJvm method JVM_GetSockName.
// 3801 JVM_LEAF(jint, JVM_GetSockName(jint fd, struct sockaddr *him, int *len))
static int JVM_GetSockName(int fd, Socket.sockaddr him, CIntPointer len_Pointer) {
// 3802 JVMWrapper2("JVM_GetSockName (0x%x)", fd);
// 3803 //%note jvm_r6
// 3804 socklen_t socklen = (socklen_t)(*len);
CIntPointer socklen_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
socklen_Pointer.write(len_Pointer.read());
// 3805 jint result = os::get_sock_name(fd, him, &socklen);
int result = Target_os.get_sock_name(fd, him, socklen_Pointer);
// 3806 *len = (int)socklen;
len_Pointer.write(socklen_Pointer.read());
// 3807 return result;
return result;
// 3808 JVM_END
}
use of org.graalvm.nativeimage.c.type.CIntPointer in project graal by oracle.
the class JavavmExportJvm method NET_SetSockOpt.
/* @formatter:on */
/* Do not re-wrap commented-out code. @formatter:off */
// 1266 /*
// 1267 * Wrapper for setsockopt system routine - performs any
// 1268 * necessary pre/post processing to deal with OS specific
// 1269 * issue :-
// 1270 *
// 1271 * On Solaris need to limit the suggested value for SO_SNDBUF
// 1272 * and SO_RCVBUF to the kernel configured limit
// 1273 *
// 1274 * For IP_TOS socket option need to mask off bits as this
// 1275 * aren't automatically masked by the kernel and results in
// 1276 * an error. In addition IP_TOS is a NOOP with IPv6 as it
// 1277 * should be setup as connection time.
// 1278 */
// 1279 int
// 1280 NET_SetSockOpt(int fd, int level, int opt, const void *arg,
// 1281 int len)
// 1282 {
static int NET_SetSockOpt(int fd, int level, int opt, WordPointer arg, int len) {
// 1283
// 1284 #ifndef IPTOS_TOS_MASK
// 1285 #define IPTOS_TOS_MASK 0x1e
final int IPTOS_TOS_MASK = 0x1e;
// 1286 #endif
// 1287 #ifndef IPTOS_PREC_MASK
// 1288 #define IPTOS_PREC_MASK 0xe0
final int IPTOS_PREC_MASK = 0xe0;
// 1289 #endif
// 1290
// 1291 #if defined(_ALLBSD_SOURCE)
/* Hoist declarations out of "#if defined" block". */
CIntPointer mib = null;
CLongPointer rlen_Pointer = null;
CIntPointer bufsize = null;
/* maxsockbuf should be static. */
/* Declaring maxsockbuf to be a CIntPointer because it is only used inside _ALLBSD_SOURCE. */
CIntPointer maxsockbuf_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
int maxsockbuf_size = SizeOf.get(CIntPointer.class);
if (IsDefined._ALLBSD_SOURCE()) {
// 1292 #if defined(KIPC_MAXSOCKBUF)
if (IsDefined.sysctl_KIPC_MAXSOCKBUF()) {
// 1293 int mib[3];
mib = StackValue.get(3, SizeOf.get(CIntPointer.class));
// 1294 size_t rlen;
rlen_Pointer = StackValue.get(SizeOf.get(CLongPointer.class));
}
// 1295 #endif
// 1296
// 1297 int *bufsize;
bufsize = StackValue.get(SizeOf.get(CIntPointer.class));
// 1299 #ifdef __APPLE__
if (IsDefined.__APPLE__()) {
// 1300 static int maxsockbuf = -1;
maxsockbuf_Pointer.write(-1);
maxsockbuf_size = SizeOf.get(CIntPointer.class);
// 1301 #else
} else {
// 1302 static long maxsockbuf = -1;
VMError.unimplemented();
}
// 1303 #endif
}
// 1317 if (level == IPPROTO_IP && opt == IP_TOS) {
if (level == NetinetIn.IPPROTO_IP() && opt == NetinetIn.IP_TOS()) {
// 1318 int *iptos;
CIntPointer iptos = StackValue.get(SizeOf.get(CIntPointer.class));
// 1320 #if defined(AF_INET6) && (defined(__solaris__) || defined(MACOSX))
if (IsDefined.socket_AF_INET6() && (IsDefined.__solaris__() || IsDefined.MACOSX())) {
// 1321 if (ipv6_available()) {
if (JavaNetNetUtil.ipv6_available()) {
// 1322 return 0;
return 0;
}
// 1324 #endif
}
// 1326 #if defined(AF_INET6) && defined(__linux__)
if (IsDefined.socket_AF_INET6() && IsDefined.__linux__()) {
VMError.unimplemented();
// 1327 if (ipv6_available()) {
// 1328 int optval = 1;
// 1329 if (setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND,
// 1330 (void *)&optval, sizeof(optval)) < 0) {
// 1331 return -1;
// 1332 }
// 1332 }
}
// 1334 #endif
// 1335
// 1336 iptos = (int *)arg;
iptos = (CIntPointer) arg;
// 1337 *iptos &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK);
iptos.write(iptos.read() & (IPTOS_TOS_MASK | IPTOS_PREC_MASK));
}
// 1344 #ifdef __solaris__
if (IsDefined.__solaris__()) {
VMError.unimplemented();
// 1345 if (level == SOL_SOCKET) {
// 1346 if (opt == SO_SNDBUF || opt == SO_RCVBUF) {
// 1347 int sotype=0, arglen;
// 1348 int *bufsize, maxbuf;
// 1349 int ret;
// 1350
// 1351 /* Attempt with the original size */
// 1352 ret = setsockopt(fd, level, opt, arg, len);
// 1353 if ((ret == 0) || (ret == -1 && errno != ENOBUFS))
// 1354 return ret;
// 1355
// 1356 /* Exceeded system limit so clamp and retry */
// 1357
// 1358 arglen = sizeof(sotype);
// 1359 if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype,
// 1360 &arglen) < 0) {
// 1361 return -1;
// 1362 }
// 1363
// 1364 /*
// 1365 * We try to get tcp_maxbuf (and udp_max_buf) using
// 1366 * an ioctl() that isn't available on all versions of Solaris.
// 1367 * If that fails, we use the search algorithm in findMaxBuf()
// 1368 */
// 1369 if (!init_tcp_max_buf && sotype == SOCK_STREAM) {
// 1370 tcp_max_buf = net_getParam("/dev/tcp", "tcp_max_buf");
// 1371 if (tcp_max_buf == -1) {
// 1372 tcp_max_buf = findMaxBuf(fd, opt, SOCK_STREAM);
// 1373 if (tcp_max_buf == -1) {
// 1374 return -1;
// 1375 }
// 1376 }
// 1377 init_tcp_max_buf = 1;
// 1378 } else if (!init_udp_max_buf && sotype == SOCK_DGRAM) {
// 1379 udp_max_buf = net_getParam("/dev/udp", "udp_max_buf");
// 1380 if (udp_max_buf == -1) {
// 1381 udp_max_buf = findMaxBuf(fd, opt, SOCK_DGRAM);
// 1382 if (udp_max_buf == -1) {
// 1383 return -1;
// 1384 }
// 1385 }
// 1386 init_udp_max_buf = 1;
// 1387 }
// 1388
// 1389 maxbuf = (sotype == SOCK_STREAM) ? tcp_max_buf : udp_max_buf;
// 1390 bufsize = (int *)arg;
// 1391 if (*bufsize > maxbuf) {
// 1392 *bufsize = maxbuf;
// 1393 }
// 1394 }
// 1395 }
}
// 1427 #ifdef __linux__
if (IsDefined.__linux__()) {
// 1428 if (level == SOL_SOCKET && opt == SO_RCVBUF) {
if (level == Socket.SOL_SOCKET() && opt == Socket.SO_RCVBUF()) {
// 1429 int *bufsize = (int *)arg;
bufsize = (CIntPointer) arg;
// 1430 if (*bufsize < 1024) {
if (bufsize.read() < 1024) {
// 1431 *bufsize = 1024;
bufsize.write(1024);
}
}
}
// 1436 #if defined(_ALLBSD_SOURCE)
if (IsDefined._ALLBSD_SOURCE()) {
// 1442 if (level == SOL_SOCKET) {
if (level == Socket.SOL_SOCKET()) {
// 1443 if (opt == SO_SNDBUF || opt == SO_RCVBUF) {
if (opt == Socket.SO_SNDBUF() || opt == Socket.SO_RCVBUF()) {
// 1444 #ifdef KIPC_MAXSOCKBUF
if (IsDefined.sysctl_KIPC_MAXSOCKBUF()) {
// 1445 if (maxsockbuf == -1) {
if (maxsockbuf_Pointer.read() == -1) {
// 1446 mib[0] = CTL_KERN;
mib.write(0, DarwinSysctl.CTL_KERN());
// 1447 mib[1] = KERN_IPC;
mib.write(1, DarwinSysctl.KERN_IPC());
// 1448 mib[2] = KIPC_MAXSOCKBUF;
mib.write(2, DarwinSysctl.KIPC_MAXSOCKBUF());
// 1449 rlen = sizeof(maxsockbuf);
rlen_Pointer.write(maxsockbuf_size);
// 1450 if (sysctl(mib, 3, &maxsockbuf, &rlen, NULL, 0) == -1)
if (Sysctl.sysctl(mib, 3, maxsockbuf_Pointer, (WordPointer) rlen_Pointer, WordFactory.nullPointer(), 0) == -1) {
// 1451 maxsockbuf = 1024;
maxsockbuf_Pointer.write(1024);
}
// 1453 #if 1
if (true) {
// 1454 /* XXXBSD: This is a hack to workaround mb_max/mb_max_adj
// 1455 problem. It should be removed when kern.ipc.maxsockbuf
// 1456 will be real value. */
// 1457 maxsockbuf = (maxsockbuf/5)*4;
maxsockbuf_Pointer.write((maxsockbuf_Pointer.read() / 5) * 4);
}
// 1458 #endif
}
// 1460 #elif defined(__OpenBSD__)
} else if (IsDefined.__OpenBSD__()) {
VMError.unimplemented();
// 1461 maxsockbuf = SB_MAX;
// 1462 #else
} else {
VMError.unimplemented();
// 1463 maxsockbuf = 64 * 1024; /* XXX: NetBSD */
}
// 1464 #endif
// 1465
// 1466 bufsize = (int *)arg;
bufsize = (CIntPointer) arg;
// 1467 if (*bufsize > maxsockbuf) {
if (bufsize.read() > maxsockbuf_Pointer.read()) {
// 1468 *bufsize = maxsockbuf;
bufsize.write(maxsockbuf_Pointer.read());
}
// 1471 if (opt == SO_RCVBUF && *bufsize < 1024) {
if (opt == Socket.SO_RCVBUF() && bufsize.read() < 1024) {
// 1472 *bufsize = 1024;
bufsize.write(1024);
}
// 1474
}
}
}
// 1479 #if defined(_ALLBSD_SOURCE) || defined(_AIX)
if (IsDefined._AIX()) {
VMError.unimplemented();
// 1480 /*
// 1481 * On Solaris, SO_REUSEADDR will allow multiple datagram
// 1482 * sockets to bind to the same port. The network jck tests check
// 1483 * for this "feature", so we need to emulate it by turning on
// 1484 * SO_REUSEPORT as well for that combination.
// 1485 */
// 1486 if (level == SOL_SOCKET && opt == SO_REUSEADDR) {
// 1487 int sotype;
// 1488 socklen_t arglen;
// 1489
// 1490 arglen = sizeof(sotype);
// 1491 if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) < 0) {
// 1492 return -1;
// 1493 }
// 1494
// 1495 if (sotype == SOCK_DGRAM) {
// 1496 setsockopt(fd, level, SO_REUSEPORT, arg, len);
// 1497 }
// 1498 }
}
// 1501 return setsockopt(fd, level, opt, arg, len);
return Socket.setsockopt(fd, level, opt, arg, len);
}
Aggregations