Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/nio/ch/SocketChannelImpl.c
32288 views
/*1* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <netdb.h>26#include <sys/types.h>27#include <sys/socket.h>28#include <stdlib.h>29#include <errno.h>30#include <string.h>31#include <poll.h>3233#if __linux__34#include <netinet/in.h>35#endif3637#include "jni.h"38#include "jni_util.h"39#include "net_util.h"40#include "jvm.h"41#include "jlong.h"42#include "sun_nio_ch_SocketChannelImpl.h"43#include "nio_util.h"44#include "nio.h"454647JNIEXPORT jint JNICALL48Java_sun_nio_ch_SocketChannelImpl_checkConnect(JNIEnv *env, jobject this,49jobject fdo, jboolean block,50jboolean ready)51{52int error = 0;53socklen_t n = sizeof(int);54jint fd = fdval(env, fdo);55int result = 0;56struct pollfd poller;5758poller.revents = 1;59if (!ready) {60poller.fd = fd;61poller.events = POLLOUT;62poller.revents = 0;63result = poll(&poller, 1, block ? -1 : 0);64if (result < 0) {65JNU_ThrowIOExceptionWithLastError(env, "Poll failed");66return IOS_THROWN;67}68if (!block && (result == 0))69return IOS_UNAVAILABLE;70}7172if (poller.revents) {73errno = 0;74result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &n);75if (result < 0) {76handleSocketError(env, errno);77return JNI_FALSE;78} else if (error) {79handleSocketError(env, error);80return JNI_FALSE;81}82return 1;83}84return 0;85}8687JNIEXPORT jint JNICALL88Java_sun_nio_ch_SocketChannelImpl_sendOutOfBandData(JNIEnv* env, jclass this,89jobject fdo, jbyte b)90{91int n = send(fdval(env, fdo), (const void*)&b, 1, MSG_OOB);92return convertReturnVal(env, n, JNI_FALSE);93}949596