jdk/src/java.base/unix/native/libnet/net_util_md.h
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 23879 jdk/src/solaris/native/java/net/net_util_md.h@284802a2d355
child 36115 0676e37a0b9c
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13999
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef NET_UTILS_MD_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define NET_UTILS_MD_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <netdb.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <netinet/in.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <sys/poll.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
23048
cf8cda42cd52 8036584: Review comments from 8035897
chegar
parents: 23043
diff changeset
    37
int NET_Timeout(int s, long timeout);
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    38
int NET_Read(int s, void* buf, size_t len);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    39
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    40
                 struct sockaddr *from, socklen_t *fromlen);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    41
int NET_ReadV(int s, const struct iovec * vector, int count);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    42
int NET_Send(int s, void *msg, int len, unsigned int flags);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    43
int NET_SendTo(int s, const void *msg, int len,  unsigned  int
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    44
               flags, const struct sockaddr *to, int tolen);
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    45
int NET_Writev(int s, const struct iovec * vector, int count);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    46
int NET_Connect(int s, struct sockaddr *addr, int addrlen);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    47
int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    48
int NET_SocketClose(int s);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    49
int NET_Dup2(int oldfd, int newfd);
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    50
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents: 22607
diff changeset
    51
int NET_SocketAvailable(int s, jint *pbytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    53
void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    54
                                               const char* hostname,
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    55
                                               int gai_error);
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    56
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    57
                                  const char *defaultDetail);
6670
ae13809f3ce7 6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents: 5506
diff changeset
    58
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    59
#define NET_WAIT_READ    0x01
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    60
#define NET_WAIT_WRITE   0x02
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    61
#define NET_WAIT_CONNECT 0x04
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    63
jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Macros and constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
/*
2938
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    70
 * On 64-bit JDKs we use a much larger stack and heap buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 */
2938
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    72
#ifdef _LP64
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    73
#define MAX_BUFFER_LEN 65536
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    74
#define MAX_HEAP_BUFFER_LEN 131072
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    75
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#define MAX_BUFFER_LEN 8192
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#define MAX_HEAP_BUFFER_LEN 65536
2938
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    78
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#ifdef AF_INET6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#define SOCKADDR        union { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                            struct sockaddr_in him4; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                            struct sockaddr_in6 him6; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#define SOCKADDR_LEN    (ipv6_available() ? sizeof(SOCKADDR) : \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                         sizeof(struct sockaddr_in))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 2938
diff changeset
    92
#define SOCKADDR        union { struct sockaddr_in him4; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#define SOCKADDR_LEN    sizeof(SOCKADDR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *  Utilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 */
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   100
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
#ifdef __linux__
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   102
int kernelIsV24();
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   103
#ifdef AF_INET6
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   104
int getDefaultIPv6Interface(struct in6_addr *target_addr);
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   105
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   108
#ifdef __solaris__
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   109
int net_getParam(char *driver, char *param);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   110
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   111
#ifndef SO_FLOW_SLA
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   112
#define SO_FLOW_SLA 0x1018
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   113
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   114
#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   115
#pragma pack(4)
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   116
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   118
/*
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   119
 * Used with the setsockopt(SO_FLOW_SLA, ...) call to set
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   120
 * per socket service level properties.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   121
 * When the application uses per-socket API, we will enforce the properties
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   122
 * on both outbound and inbound packets.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   123
 *
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   124
 * For now, only priority and maxbw are supported in SOCK_FLOW_PROP_VERSION1.
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   125
 */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   126
typedef struct sock_flow_props_s {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   127
        int             sfp_version;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   128
        uint32_t        sfp_mask;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   129
        int             sfp_priority;   /* flow priority */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   130
        uint64_t        sfp_maxbw;      /* bandwidth limit in bps */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   131
        int             sfp_status;     /* flow create status for getsockopt */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   132
} sock_flow_props_t;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   133
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   134
#define SOCK_FLOW_PROP_VERSION1 1
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   135
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   136
/* bit mask values for sfp_mask */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   137
#define SFP_MAXBW       0x00000001      /* Flow Bandwidth Limit */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   138
#define SFP_PRIORITY    0x00000008      /* Flow priority */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   139
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   140
/* possible values for sfp_priority */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   141
#define SFP_PRIO_NORMAL 1
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   142
#define SFP_PRIO_HIGH   2
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   143
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   144
#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   145
#pragma pack()
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   146
#endif /* _LONG_LONG_ALIGNMENT */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   147
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   148
#endif /* SO_FLOW_SLA */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   149
#endif /* __solaris__ */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   150
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   151
JNIEXPORT jboolean JNICALL NET_IsFlowSupported();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents: 23048
diff changeset
   152
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
#endif /* NET_UTILS_MD_H */