src/java.base/unix/native/libnio/ch/SocketChannelImpl.c
changeset 48750 ffbb784a8873
parent 47216 71c04702a3d5
child 49141 ac95c7a76132
equal deleted inserted replaced
48749:fd40b0b3d849 48750:ffbb784a8873
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    45 #include "nio.h"
    45 #include "nio.h"
    46 
    46 
    47 
    47 
    48 JNIEXPORT jint JNICALL
    48 JNIEXPORT jint JNICALL
    49 Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv *env, jobject this,
    49 Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv *env, jobject this,
    50                                                jobject fdo, jboolean block,
    50                                                jobject fdo, jboolean block)
    51                                                jboolean ready)
       
    52 {
    51 {
    53     int error = 0;
    52     int error = 0;
    54     socklen_t n = sizeof(int);
    53     socklen_t n = sizeof(int);
    55     jint fd = fdval(env, fdo);
    54     jint fd = fdval(env, fdo);
    56     int result = 0;
    55     int result = 0;
    57     struct pollfd poller;
    56     struct pollfd poller;
    58 
    57 
    59     poller.revents = 1;
    58     poller.fd = fd;
    60     if (!ready) {
    59     poller.events = POLLOUT;
    61         poller.fd = fd;
    60     poller.revents = 0;
    62         poller.events = POLLOUT;
    61     result = poll(&poller, 1, block ? -1 : 0);
    63         poller.revents = 0;
    62     if (result < 0) {
    64         result = poll(&poller, 1, block ? -1 : 0);
    63         JNU_ThrowIOExceptionWithLastError(env, "Poll failed");
    65         if (result < 0) {
    64         return IOS_THROWN;
    66             JNU_ThrowIOExceptionWithLastError(env, "Poll failed");
       
    67             return IOS_THROWN;
       
    68         }
       
    69         if (!block && (result == 0))
       
    70             return IOS_UNAVAILABLE;
       
    71     }
    65     }
       
    66     if (!block && (result == 0))
       
    67        return IOS_UNAVAILABLE;
    72 
    68 
    73     if (poller.revents) {
    69     if (poller.revents) {
    74         errno = 0;
    70         errno = 0;
    75         result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &n);
    71         result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &n);
    76         if (result < 0) {
    72         if (result < 0) {