Path: blob/master/src/java.base/unix/native/libnio/ch/nio_util.h
41133 views
/*1* Copyright (c) 2001, 2020, 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 "jni.h"26#include "jni_util.h"27#include "jvm.h"28#include "jlong.h"29#include <errno.h>30#include <sys/types.h>31#include <sys/un.h>3233#define RESTARTABLE(_cmd, _result) do { \34do { \35_result = _cmd; \36} while((_result == -1) && (errno == EINTR)); \37} while(0)3839/* Defines SO_REUSEPORT */40#ifndef SO_REUSEPORT41#ifdef __linux__42#define SO_REUSEPORT 1543#elif defined(AIX) || defined(MACOSX)44#define SO_REUSEPORT 0x020045#else46#define SO_REUSEPORT 047#endif48#endif4950/* 2 bytes to allow for null at end of string and null at start of string51* for abstract name52*/53#define MAX_UNIX_DOMAIN_PATH_LEN \54(int)(sizeof(((struct sockaddr_un *)0)->sun_path)-2)5556/* NIO utility procedures */575859/* Defined in IOUtil.c */6061jint fdval(JNIEnv *env, jobject fdo);62void setfdval(JNIEnv *env, jobject fdo, jint value);6364jint convertReturnVal(JNIEnv *env, jint n, jboolean reading);65jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean reading);666768/* Defined in Net.c */6970jint handleSocketError(JNIEnv *env, jint errorValue);7172/* Defined in UnixDomainSockets.c */7374jbyteArray sockaddrToUnixAddressBytes(JNIEnv *env,75struct sockaddr_un *sa,76socklen_t len);7778jint unixSocketAddressToSockaddr(JNIEnv *env,79jbyteArray uaddr,80struct sockaddr_un *sa,81int *len);82838485