Search in sources :

Example 46 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class Util_jni method getHostByAddr.

@Substitute
@SuppressWarnings({ "static-method" })
public String getHostByAddr(byte[] addrArray) throws UnknownHostException {
    String ret = null;
    CCharPointer host = StackValue.get(Netdb.NI_MAXHOST() + 1);
    int error = 0;
    int len = 0;
    CCharPointer caddr = StackValue.get(16);
    NetinetIn.sockaddr_in him4 = StackValue.get(SizeOf.get(NetinetIn.sockaddr_in.class));
    NetinetIn.sockaddr_in6 him6 = StackValue.get(SizeOf.get(NetinetIn.sockaddr_in6.class));
    Socket.sockaddr sa;
    if (addrArray.length == 4) {
        /*
             * For IPv4 addresses construct a sockaddr_in structure.
             */
        int addr = 0;
        addr |= ((addrArray[0] << 24) & 0xff000000);
        addr |= ((addrArray[1] << 16) & 0xff0000);
        addr |= ((addrArray[2] << 8) & 0xff00);
        addr |= ((addrArray[3] << 0) & 0xff);
        LibC.memset(him4, WordFactory.signed(0), SizeOf.unsigned(NetinetIn.sockaddr_in.class));
        him4.sin_addr().set_s_addr(NetinetIn.htonl(addr));
        him4.set_sin_family(Socket.AF_INET());
        sa = (Socket.sockaddr) him4;
        len = SizeOf.get(NetinetIn.sockaddr_in.class);
    } else {
        /*
             * For IPv6 address construct a sockaddr_in6 structure.
             */
        try (PinnedObject pinnedAddrArray = PinnedObject.create(addrArray)) {
            CCharPointer addrArray0 = pinnedAddrArray.addressOfArrayElement(0);
            LibC.memcpy(caddr, addrArray0, WordFactory.unsigned(16));
        }
        LibC.memset(him6, WordFactory.signed(0), SizeOf.unsigned(NetinetIn.sockaddr_in6.class));
        LibC.memcpy(him6.sin6_addr(), caddr, SizeOf.unsigned(NetinetIn.in6_addr.class));
        him6.set_sin6_family(Socket.AF_INET6());
        sa = (Socket.sockaddr) him6;
        len = SizeOf.get(NetinetIn.sockaddr_in6.class);
    }
    error = Netdb.getnameinfo(sa, len, host, Netdb.NI_MAXHOST(), WordFactory.nullPointer(), 0, Netdb.NI_NAMEREQD());
    if (error == 0) {
        ret = CTypeConversion.toJavaString(host);
    }
    if (ret == null) {
        throw new UnknownHostException();
    }
    return ret;
}
Also used : UnknownHostException(java.net.UnknownHostException) PinnedObject(org.graalvm.nativeimage.PinnedObject) NetinetIn(com.oracle.svm.core.posix.headers.NetinetIn) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) ServerSocket(java.net.ServerSocket) Socket(com.oracle.svm.core.posix.headers.Socket) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 47 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class Util_jni method getAll.

// { Do not format quoted code: @formatter:off
// Translation of jdk/src/solaris/native/java/net/NetworkInterface.c?v=Java_1.8.0_40_b10.
// 410 /*
// 411  * Class:     java_net_NetworkInterface
// 412  * Method:    getAll
// 413  * Signature: ()[Ljava/net/NetworkInterface;
// 414  */
// 415 JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll
// 416     (JNIEnv *env, jclass cls) {
@Substitute
static NetworkInterface[] getAll() {
    // 417
    // 418     netif *ifs, *curr;
    JavaNetNetworkInterface.netif ifs;
    JavaNetNetworkInterface.netif curr;
    // 419     jobjectArray netIFArr;
    NetworkInterface[] netIFArr;
    // 420     jint arr_index, ifCount;
    int arr_index;
    int ifCount;
    // 421
    // 422     ifs = enumInterfaces(env);
    ifs = JavaNetNetworkInterface.enumInterfaces();
    // 423     if (ifs == NULL) {
    if (ifs == null) {
        // 424         return NULL;
        return null;
    }
    // 426
    // 427     /* count the interface */
    // 428     ifCount = 0;
    ifCount = 0;
    // 429     curr = ifs;
    curr = ifs;
    // 430     while (curr != NULL) {
    while (curr != null) {
        // 431         ifCount++;
        ifCount++;
        // 432         curr = curr->next;
        curr = curr.next;
    }
    // 434
    // 435     /* allocate a NetworkInterface array */
    // 436     netIFArr = (*env)->NewObjectArray(env, ifCount, cls, NULL);
    netIFArr = new NetworkInterface[ifCount];
    // 437     if (netIFArr == NULL) {
    /* Dead code. */
    // 438         freeif(ifs);
    // 439         return NULL;
    // 440     }
    // 441
    // 442     /*
    // 443      * Iterate through the interfaces, create a NetworkInterface instance
    // 444      * for each array element and populate the object.
    // 445      */
    // 446     curr = ifs;
    curr = ifs;
    // 447     arr_index = 0;
    arr_index = 0;
    // 448     while (curr != NULL) {
    while (curr != null) {
        // 449         jobject netifObj;
        NetworkInterface netifObj;
        // 450
        // 451         netifObj = createNetworkInterface(env, curr);
        netifObj = JavaNetNetworkInterface.createNetworkInterface(curr);
        // 452         if (netifObj == NULL) {
        if (netifObj == null) {
            // 454             return NULL;
            return null;
        }
        // 456
        // 457         /* put the NetworkInterface into the array */
        // 458         (*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj);
        netIFArr[arr_index++] = netifObj;
        // 459
        // 460         curr = curr->next;
        curr = curr.next;
    }
    // 464     return netIFArr;
    return netIFArr;
}
Also used : NetworkInterface(java.net.NetworkInterface) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 48 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class Util_jni method socketSetOption.

/* Do not re-format commented-out code: @formatter:off */
// 886 /*
// 887  * Class:     java_net_PlainSocketImpl
// 888  * Method:    socketSetOption
// 889  * Signature: (IZLjava/lang/Object;)V
// 890  */
// 891 JNIEXPORT void JNICALL
// 892 Java_java_net_PlainSocketImpl_socketSetOption(JNIEnv *env, jobject this,
// 893                                               jint cmd, jboolean on,
// 894                                               jobject value) {
@Substitute
void socketSetOption(int cmd, boolean on, Object value) throws SocketException {
    // 895     int fd;
    int fd;
    // 896     int level, optname, optlen;
    CIntPointer level_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
    CIntPointer optname_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
    int optlen;
    /* Translated as a WordPointer to the larger of the arms. */
    // 897     union {
    // 898         int i;
    // 899         struct linger ling;
    // 900     } optval;
    /* Guess which arm of the union is larger. Trust, but verify. */
    final int sizeof_optval = SizeOf.get(Socket.linger.class);
    VMError.guarantee(SizeOf.get(CIntPointer.class) <= sizeof_optval, "sizeof(int) <= sizeof(union optval)");
    VMError.guarantee(SizeOf.get(Socket.linger.class) <= sizeof_optval, "sizeof(struct linger) <= sizeof(union optval)");
    WordPointer optval_Pointer = StackValue.get(sizeof_optval);
    // 901
    // 902     /*
    // 903      * Check that socket hasn't been closed
    // 904      */
    // 905     fd = getFD(env, this);
    fd = Util_java_io_FileDescriptor.getFD(Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).fd);
    // 906     if (fd < 0) {
    if (fd < 0) {
        // 909         return;
        throw new SocketException("Socket closed");
    }
    // 915     if (cmd == java_net_SocketOptions_SO_TIMEOUT) {
    if (cmd == SocketOptions.SO_TIMEOUT) {
        // 916         return;
        return;
    }
    // 923     if (NET_MapSocketOption(cmd, &level, &optname)) {
    if (CTypeConversion.toBoolean(JavaNetNetUtilMD.NET_MapSocketOption(cmd, level_Pointer, optname_Pointer))) {
        // 925         return;
        throw new SocketException("Invalid option");
    }
    // 928     switch (cmd) {
    switch(cmd) {
        // 932         case java_net_SocketOptions_IP_TOS :
        case SocketOptions.SO_SNDBUF:
        case SocketOptions.SO_RCVBUF:
        case SocketOptions.SO_LINGER:
        case SocketOptions.IP_TOS:
            {
                /* Accessing values of java.lang.Integer the easy way. */
                Integer valueInteger = (Integer) value;
                // 942                 if (cmd == java_net_SocketOptions_SO_LINGER) {
                if (cmd == SocketOptions.SO_LINGER) {
                    // 943                     if (on) {
                    if (on) {
                        // 944                         optval.ling.l_onoff = 1;
                        ((Socket.linger) optval_Pointer).set_l_onoff(1);
                        // 945                         optval.ling.l_linger = (*env)->GetIntField(env, value, fid);
                        ((Socket.linger) optval_Pointer).set_l_linger(valueInteger.intValue());
                    } else {
                        // 947                         optval.ling.l_onoff = 0;
                        ((Socket.linger) optval_Pointer).set_l_onoff(0);
                        // 948                         optval.ling.l_linger = 0;
                        ((Socket.linger) optval_Pointer).set_l_linger(0);
                    }
                    // 950                     optlen = sizeof(optval.ling);
                    optlen = SizeOf.get(Socket.linger.class);
                    /* Copy to optval. */
                    LibC.memcpy(optval_Pointer, optval_Pointer, WordFactory.unsigned(optlen));
                } else {
                    // 952                     optval.i = (*env)->GetIntField(env, value, fid);
                    ((CIntPointer) optval_Pointer).write(valueInteger.intValue());
                    // 953                     optlen = sizeof(optval.i);
                    optlen = SizeOf.get(CIntPointer.class);
                    /* Copy to optval. */
                    LibC.memcpy(optval_Pointer, optval_Pointer, WordFactory.unsigned(optlen));
                }
                // 956                 break;
                break;
            }
        // 960         default :
        default:
            // 961             optval.i = (on ? 1 : 0);
            ((CIntPointer) optval_Pointer).write(on ? 1 : 0);
            // 962             optlen = sizeof(optval.i);
            optlen = SizeOf.get(CIntPointer.class);
            /* Copy to optval. */
            LibC.memcpy(optval_Pointer, optval_Pointer, WordFactory.unsigned(optlen));
    }
    // 966     if (NET_SetSockOpt(fd, level, optname, (const void *)&optval, optlen) < 0) {
    if (JavaNetNetUtilMD.NET_SetSockOpt(fd, level_Pointer.read(), optname_Pointer.read(), optval_Pointer, optlen) < 0) {
        // 968         if (errno == EINVAL) {
        if (Errno.errno() == Errno.EINVAL()) {
            // 974             return;
            throw new SocketException("Invalid option or socket reset by remote peer");
        }
        // 978                                       "Error setting socket option");
        throw new SocketException("Error setting socket option");
    }
}
Also used : SocketException(java.net.SocketException) CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) ServerSocket(java.net.ServerSocket) Socket(com.oracle.svm.core.posix.headers.Socket) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 49 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class Util_jni method socketConnect.

/* @formatter:on */
/* Do not re-format commented-out code: @formatter:off */
@Substitute
@SuppressWarnings({ "unused" })
void socketConnect(InetAddress iaObj, int port, int timeoutArg) throws IOException {
    /* local copy of "timeout" argument so it can be modified. */
    int timeout = timeoutArg;
    // 259    jint localport = (*env)->GetIntField(env, this, psi_localportID);
    int localport = Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).localport;
    // 260    int len = 0;
    CIntPointer len_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
    len_Pointer.write(0);
    // 262    /* fdObj is the FileDescriptor field on this */
    // 263    jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
    FileDescriptor fdObj = Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).fd;
    // 265    class clazz = (*env)->GetObjectClass(env, this);
    // 267    jobject fdLock;
    Object fdLock;
    // 269    jint trafficClass = (*env)->GetIntField(env, this, psi_trafficClassID);
    int trafficClass = Util_java_net_PlainSocketImpl.as_Target_java_net_AbstractPlainSocketImpl(this).trafficClass;
    // 271    /* fd is an int field on iaObj */
    // 272    jint fd;
    int fd;
    // 274    SOCKADDR him;
    Socket.sockaddr him = StackValue.get(JavaNetNetUtilMD.SOCKADDR_LEN());
    // 275    /* The result of the connection */
    // 276    int connect_rv = -1;
    CIntPointer connect_rv_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
    connect_rv_Pointer.write(-1);
    // 278    if (IS_NULL(fdObj)) {
    if (fdObj == null) {
        // 279    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
        throw new SocketException("Socket closed");
    // 280    return;
    } else {
        // 282    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
        fd = Util_java_io_FileDescriptor.getFD(fdObj);
    }
    // 284    if (IS_NULL(iaObj)) {
    if (iaObj == null) {
        // 285    JNU_ThrowNullPointerException(env, "inet address argument null.");
        throw new NullPointerException("inet address argument null.");
    // 286    return;
    }
    // 290    if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&him, &len, JNI_TRUE) != 0) {
    if (JavaNetNetUtilMD.NET_InetAddressToSockaddr(iaObj, port, him, len_Pointer, Util_jni.JNI_TRUE()) != 0) {
        // 291    return;
        return;
    }
    // 293    setDefaultScopeID(env, (struct sockaddr *)&him);
    JavaNetNetUtilMD.setDefaultScopeID(him);
    // 295 #ifdef AF_INET6
    if (IsDefined.socket_AF_INET6()) {
        // 296    if (trafficClass != 0 && ipv6_available()) {
        if ((trafficClass != 0) && JavaNetNetUtil.ipv6_available()) {
            // 297    NET_SetTrafficClass((struct sockaddr *)&him, trafficClass);
            JavaNetNetUtilMD.NET_SetTrafficClass(him, trafficClass);
        }
    }
    // 300    if (timeout <= 0) {
    if (timeout <= 0) {
        // 301    connect_rv = NET_Connect(fd, (struct sockaddr *)&him, len);
        connect_rv_Pointer.write(JavaNetNetUtilMD.NET_Connect(fd, him, len_Pointer.read()));
    // 302 #ifdef __solaris__
    // 303        if (connect_rv == JVM_IO_ERR && errno == EINPROGRESS ) {
    // 305            /* This can happen if a blocking connect is interrupted by a signal.
    // 306             * See 6343810.
    // 307             */
    // 308        while (1) {
    // 309 #ifndef USE_SELECT
    // 310                 {
    // 311                     struct pollfd pfd;
    // 312                     pfd.fd = fd;
    // 313                     pfd.events = POLLOUT;
    // 314
    // 315                     connect_rv = NET_Poll(&pfd, 1, -1);
    // 316                 }
    // 317 #else /* USE_SELECT */
    // 318                 {
    // 319                     fd_set wr, ex;
    // 320
    // 321                     FD_ZERO(&wr);
    // 322                     FD_SET(fd, &wr);
    // 323                     FD_ZERO(&ex);
    // 324                     FD_SET(fd, &ex);
    // 325
    // 326                     connect_rv = NET_Select(fd+1, 0, &wr, &ex, 0);
    // 327                 }
    // 328 #endif /* USE_SELECT */
    // 329
    // 330                 if (connect_rv == JVM_IO_ERR) {
    // 331                     if (errno == EINTR) {
    // 332                         continue;
    // 333                     } else {
    // 334                         break;
    // 335                     }
    // 336                 }
    // 337                 if (connect_rv > 0) {
    // 338                     int optlen;
    // 339                     /* has connection been established */
    // 340                     optlen = sizeof(connect_rv);
    // 341                     if (JVM_GetSockOpt(fd, SOL_SOCKET, SO_ERROR,
    // 342                                         (void*)&connect_rv, &optlen) <0) {
    // 343                         connect_rv = errno;
    // 344                     }
    // 345
    // 346                     if (connect_rv != 0) {
    // 347                         /* restore errno */
    // 348                         errno = connect_rv;
    // 349                         connect_rv = JVM_IO_ERR;
    // 350                     }
    // 351                     break;
    // 352                 }
    // 353             }
    // 354         }
    // 355 #endif /* __solaris__ */
    } else {
        // 357         /*
        // 358          * A timeout was specified. We put the socket into non-blocking
        // 359          * mode, connect, and then wait for the connection to be
        // 360          * established, fail, or timeout.
        // 361          */
        // 362         SET_NONBLOCKING(fd);
        Util_java_net_PlainSocketImpl.SET_NONBLOCKING(fd);
        // 364         /* no need to use NET_Connect as non-blocking */
        // 365         connect_rv = connect(fd, (struct sockaddr *)&him, len);
        connect_rv_Pointer.write(Socket.connect(fd, him, len_Pointer.read()));
        // 368         if (connect_rv != 0) {
        if (connect_rv_Pointer.read() != 0) {
            // 369             int optlen;
            CIntPointer optlen_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
            // 370             jlong prevTime = JVM_CurrentTimeMillis(env, 0);
            long prevTime = Target_java_lang_System.currentTimeMillis();
            // 372             if (errno != EINPROGRESS) {
            if (Errno.errno() != Errno.EINPROGRESS()) {
                // 374                              "connect failed");
                try {
                    /* FIXME: Not implementing NET_ThrowByNameWithLastError. */
                    throw new ConnectException("connect failed");
                } finally {
                    // 375                 SET_BLOCKING(fd);
                    Util_java_net_PlainSocketImpl.SET_BLOCKING(fd);
                // 376                 return;
                }
            }
            // 385             while (1) {
            while (true) {
                // 386                 jlong newTime;
                long newTime;
                /*
                     * I am assuming that USE_SELECT is not defined.
                     * Cf. https://bugs.openjdk.java.net/browse/JDK-8035949
                     */
                // 387 #ifndef USE_SELECT
                // 388                 {
                // 389                     struct pollfd pfd;
                Poll.pollfd pfd = StackValue.get(SizeOf.get(Poll.pollfd.class));
                // 390                     pfd.fd = fd;
                pfd.set_fd(fd);
                // 391                     pfd.events = POLLOUT;
                pfd.set_events(Poll.POLLOUT());
                // 393                     errno = 0;
                Errno.set_errno(0);
                // 394                     connect_rv = NET_Poll(&pfd, 1, timeout);
                connect_rv_Pointer.write(JavaNetNetUtilMD.NET_Poll(pfd, 1, timeout));
                // 414                 if (connect_rv >= 0) {
                if (connect_rv_Pointer.read() >= 0) {
                    // 415                     break;
                    break;
                }
                // 417                 if (errno != EINTR) {
                if (Errno.errno() != Errno.EINTR()) {
                    // 418                     break;
                    break;
                }
                // 421                 /*
                // 422                  * The poll was interrupted so adjust timeout and
                // 423                  * restart
                // 424                  */
                // 425                 newTime = JVM_CurrentTimeMillis(env, 0);
                newTime = Target_java_lang_System.currentTimeMillis();
                // 426                 timeout -= (newTime - prevTime);
                timeout -= (newTime - prevTime);
                // 427                 if (timeout <= 0) {
                if (timeout <= 0) {
                    // 428                     connect_rv = 0;
                    connect_rv_Pointer.write(0);
                    // 429                     break;
                    break;
                }
                // 431                 prevTime = newTime;
                prevTime = newTime;
            }
            // 435             if (connect_rv == 0) {
            if (connect_rv_Pointer.read() == 0) {
                try {
                    // 437                             "connect timed out");
                    throw new SocketTimeoutException("connect timed out");
                } finally {
                    // 439                 /*
                    // 440                  * Timeout out but connection may still be established.
                    // 441                  * At the high level it should be closed immediately but
                    // 442                  * just in case we make the socket blocking again and
                    // 443                  * shutdown input & output.
                    // 444                  */
                    // 445                 SET_BLOCKING(fd);
                    Util_java_net_PlainSocketImpl.SET_BLOCKING(fd);
                    // 446                 JVM_SocketShutdown(fd, 2);
                    VmPrimsJVM.JVM_SocketShutdown(fd, 2);
                // 447                 return;
                }
            }
            // 449
            // 450             /* has connection been established */
            // 451             optlen = sizeof(connect_rv);
            optlen_Pointer.write(SizeOf.get(CIntPointer.class));
            // 453                                &optlen) <0) {
            if (VmPrimsJVM.JVM_GetSockOpt(fd, Socket.SOL_SOCKET(), Socket.SO_ERROR(), (CCharPointer) connect_rv_Pointer, optlen_Pointer) < 0) {
                // 454                 connect_rv = errno;
                connect_rv_Pointer.write(Errno.errno());
            }
        }
        // 458         /* make socket blocking again */
        // 459         SET_BLOCKING(fd);
        Util_java_net_PlainSocketImpl.SET_BLOCKING(fd);
        // 462         if (connect_rv != 0) {
        if (connect_rv_Pointer.read() != 0) {
            // 463             errno = connect_rv;
            Errno.set_errno(connect_rv_Pointer.read());
            // 464             connect_rv = JVM_IO_ERR;
            connect_rv_Pointer.write(Target_jvm.JVM_IO_ERR());
        }
    }
    // 469     if (connect_rv < 0) {
    if (connect_rv_Pointer.read() < 0) {
        // 471 #ifdef __linux__
        if (IsDefined.__linux__()) {
            // 482         if (connect_rv == JVM_IO_ERR && errno == EINVAL) {
            if (connect_rv_Pointer.read() == Target_jvm.JVM_IO_ERR() && Errno.errno() == Errno.EINVAL()) {
                // 485             return;
                throw new SocketException("Invalid argument or cannot assign requested address");
            // 486         }
            }
        }
        // 488         if (connect_rv == JVM_IO_INTR) {
        if (connect_rv_Pointer.read() == Target_jvm.JVM_IO_INTR()) {
            // 490                             "operation interrupted");
            throw new InterruptedIOException("operation interrupted");
        // 491 #if defined(EPROTO)
        // 492         } else if (errno == EPROTO) {
        } else if (Errno.errno() == Errno.EPROTO()) {
            // 494                            "Protocol error");
            throw new ProtocolException("Protocol error");
        // 495 #endif
        // 496         } else if (errno == ECONNREFUSED) {
        } else if (Errno.errno() == Errno.ECONNREFUSED()) {
            // 498                            "Connection refused");
            throw new ConnectException("Connection refused");
        // 499         } else if (errno == ETIMEDOUT) {
        } else if (Errno.errno() == Errno.ETIMEDOUT()) {
            // 501                            "Connection timed out");
            throw new ConnectException("Connection timed out");
        // 502         } else if (errno == EHOSTUNREACH) {
        } else if (Errno.errno() == Errno.EHOSTUNREACH()) {
            // 504                            "Host unreachable");
            throw new NoRouteToHostException("Host unreachable");
        // 505         } else if (errno == EADDRNOTAVAIL) {
        } else if (Errno.errno() == Errno.EADDRNOTAVAIL()) {
            // 507                              "Address not available");
            throw new NoRouteToHostException("Address not available");
        // 508         } else if ((errno == EISCONN) || (errno == EBADF)) {
        } else if ((Errno.errno() == Errno.EISCONN()) || (Errno.errno() == Errno.EBADF())) {
            // 510                             "Socket closed");
            throw new SocketException("Socket closed");
        // 511         } else {
        } else {
            // 512             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "connect failed");
            throw new SocketException("connect failed");
        }
    // 514         return;
    /* Elided return because the "throw"s above do that. */
    }
    // 517     (*env)->SetIntField(env, fdObj, IO_fd_fdID, fd);
    Util_java_io_FileDescriptor.setFD(fdObj, fd);
    // 519     /* set the remote peer address and port */
    // 520     (*env)->SetObjectField(env, this, psi_addressID, iaObj);
    Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).address = iaObj;
    // 521     (*env)->SetIntField(env, this, psi_portID, port);
    Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).port = port;
    // 528     if (localport == 0) {
    if (localport == 0) {
        // 529         /* Now that we're a connected socket, let's extract the port number
        // 530          * that the system chose for us and store it in the Socket object.
        // 531          */
        // 532         len = SOCKADDR_LEN;
        len_Pointer.write(JavaNetNetUtilMD.SOCKADDR_LEN());
        // 533         if (JVM_GetSockName(fd, (struct sockaddr *)&him, &len) == -1) {
        if (VmPrimsJVM.JVM_GetSockName(fd, him, len_Pointer) == -1) {
            // 535                            "Error getting socket name");
            throw new SocketException("Error getting socket name");
        } else {
            // 537             localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
            localport = JavaNetNetUtilMD.NET_GetPortFromSockaddr(him);
            // 538             (*env)->SetIntField(env, this, psi_localportID, localport);
            Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).localport = localport;
        }
    }
}
Also used : SocketException(java.net.SocketException) InterruptedIOException(java.io.InterruptedIOException) ProtocolException(java.net.ProtocolException) CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) NoRouteToHostException(java.net.NoRouteToHostException) Util_java_io_FileDescriptor(com.oracle.svm.core.posix.PosixOSInterface.Util_java_io_FileDescriptor) FileDescriptor(java.io.FileDescriptor) SocketTimeoutException(java.net.SocketTimeoutException) Poll(com.oracle.svm.core.posix.headers.Poll) PinnedObject(org.graalvm.nativeimage.PinnedObject) ServerSocket(java.net.ServerSocket) Socket(com.oracle.svm.core.posix.headers.Socket) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) ConnectException(java.net.ConnectException) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 50 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class Util_jni method socketShutdown.

/* @formatter:on */
/* Do not re-format commented-out code: @formatter:off */
// jdk/src/solaris/classes/java/net/PlainSocketImpl.java?v=Java_1.8.0_40_b10
// 102 native void socketShutdown(int howto) throws IOException;
// 
// jdk/src/solaris/native/java/net/PlainSocketImpl.c?v=Java_1.8.0_40_b10
// 858 /*
// 859  * Class:     java_net_PlainSocketImpl
// 860  * Method:    socketShutdown
// 861  * Signature: (I)V
// 862  */
// 863 JNIEXPORT void JNICALL
// 864 Java_java_net_PlainSocketImpl_socketShutdown(JNIEnv *env, jobject this,
// 865                                              jint howto)
// 866 {
@Substitute
void socketShutdown(int howto) throws IOException {
    // 867
    // 868     jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
    FileDescriptor fdObj = Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).fd;
    // 869     jint fd;
    int fd;
    // 875     if (IS_NULL(fdObj)) {
    if (fdObj == null) {
        // 877                         "socket already closed");
        throw new SocketException("socket already closed");
    // 878         return;
    /* Unreachable! */
    } else {
        // 880         fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
        fd = Util_java_io_FileDescriptor.getFD(fdObj);
    }
    // 882     JVM_SocketShutdown(fd, howto);
    VmPrimsJVM.JVM_SocketShutdown(fd, howto);
}
Also used : SocketException(java.net.SocketException) Util_java_io_FileDescriptor(com.oracle.svm.core.posix.PosixOSInterface.Util_java_io_FileDescriptor) FileDescriptor(java.io.FileDescriptor) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

Substitute (com.oracle.svm.core.annotate.Substitute)69 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)18 SocketException (java.net.SocketException)11 IOException (java.io.IOException)10 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)10 PinnedObject (org.graalvm.nativeimage.PinnedObject)9 Util_java_io_FileDescriptor (com.oracle.svm.core.posix.PosixOSInterface.Util_java_io_FileDescriptor)8 FileDescriptor (java.io.FileDescriptor)8 CCharPointerHolder (org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder)8 ServerSocket (java.net.ServerSocket)7 Socket (com.oracle.svm.core.posix.headers.Socket)6 NativeTruffleContext (com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext)6 SignedWord (org.graalvm.word.SignedWord)6 InterruptedIOException (java.io.InterruptedIOException)5 Time.timeval (com.oracle.svm.core.posix.headers.Time.timeval)4 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)3 Stat.fstat (com.oracle.svm.core.posix.headers.Stat.fstat)3 Stat.stat (com.oracle.svm.core.posix.headers.Stat.stat)3 Time.timezone (com.oracle.svm.core.posix.headers.Time.timezone)3 LibFFI.ffi_cif (com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif)3