Path: blob/master/src/java.base/unix/native/libnet/net_util_md.h
41119 views
/*1* Copyright (c) 1997, 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#ifndef NET_UTILS_MD_H26#define NET_UTILS_MD_H2728#ifdef ANDROID29#include <netinet/in.h>30#endif31#include <netdb.h>32#include <poll.h>33#include <sys/socket.h>3435/************************************************************************36* Macros and constants37*/3839#define NET_NSEC_PER_MSEC 100000040#define NET_NSEC_PER_SEC 100000000041#define NET_NSEC_PER_USEC 10004243/* in case NI_MAXHOST is not defined in netdb.h */44#ifndef NI_MAXHOST45#define NI_MAXHOST 102546#endif4748/* Defines SO_REUSEPORT */49#ifndef SO_REUSEPORT50#ifdef __linux__51#define SO_REUSEPORT 1552#elif defined(AIX) || defined(MACOSX)53#define SO_REUSEPORT 0x020054#else55#define SO_REUSEPORT 056#endif57#endif5859/*60* On 64-bit JDKs we use a much larger stack and heap buffer.61*/62#ifdef _LP6463#define MAX_BUFFER_LEN 6553664#define MAX_HEAP_BUFFER_LEN 13107265#else66#define MAX_BUFFER_LEN 819267#define MAX_HEAP_BUFFER_LEN 6553668#endif6970typedef union {71struct sockaddr sa;72struct sockaddr_in sa4;73struct sockaddr_in6 sa6;74} SOCKETADDRESS;7576/************************************************************************77* Functions78*/7980int NET_Timeout(JNIEnv *env, int s, long timeout, jlong nanoTimeStamp);81int NET_Read(int s, void* buf, size_t len);82int NET_NonBlockingRead(int s, void* buf, size_t len);83int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,84struct sockaddr *from, socklen_t *fromlen);85int NET_Send(int s, void *msg, int len, unsigned int flags);86int NET_SendTo(int s, const void *msg, int len, unsigned int87flags, const struct sockaddr *to, int tolen);88int NET_Connect(int s, struct sockaddr *addr, int addrlen);89int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen);90int NET_SocketClose(int s);91int NET_Dup2(int oldfd, int newfd);92int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);9394void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,95const char* hostname,96int gai_error);97void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,98const char *defaultDetail);99void NET_SetTrafficClass(SOCKETADDRESS *sa, int trafficClass);100101#endif /* NET_UTILS_MD_H */102103104