author | ngmr |
Fri, 11 Nov 2011 14:40:18 +0000 | |
changeset 11032 | 235588f77727 |
parent 7668 | d4a77089c587 |
child 12047 | 320a714614e9 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#ifndef NET_UTILS_MD_H |
|
27 |
#define NET_UTILS_MD_H |
|
28 |
||
29 |
#include <sys/socket.h> |
|
30 |
#include <sys/types.h> |
|
31 |
#include <netdb.h> |
|
32 |
#include <netinet/in.h> |
|
33 |
#include <unistd.h> |
|
34 |
||
35 |
#ifndef USE_SELECT |
|
36 |
#include <sys/poll.h> |
|
37 |
#endif |
|
38 |
||
39 |
||
40 |
#ifdef __linux__ |
|
41 |
extern int NET_Timeout(int s, long timeout); |
|
42 |
extern int NET_Read(int s, void* buf, size_t len); |
|
43 |
extern int NET_RecvFrom(int s, void *buf, int len, unsigned int flags, |
|
44 |
struct sockaddr *from, int *fromlen); |
|
45 |
extern int NET_ReadV(int s, const struct iovec * vector, int count); |
|
46 |
extern int NET_Send(int s, void *msg, int len, unsigned int flags); |
|
47 |
extern int NET_SendTo(int s, const void *msg, int len, unsigned int |
|
48 |
flags, const struct sockaddr *to, int tolen); |
|
49 |
extern int NET_Writev(int s, const struct iovec * vector, int count); |
|
50 |
extern int NET_Connect(int s, struct sockaddr *addr, int addrlen); |
|
51 |
extern int NET_Accept(int s, struct sockaddr *addr, int *addrlen); |
|
52 |
extern int NET_SocketClose(int s); |
|
53 |
extern int NET_Dup2(int oldfd, int newfd); |
|
54 |
||
55 |
#ifdef USE_SELECT |
|
56 |
extern int NET_Select(int s, fd_set *readfds, fd_set *writefds, |
|
57 |
fd_set *exceptfds, struct timeval *timeout); |
|
58 |
#else |
|
59 |
extern int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout); |
|
60 |
#endif |
|
61 |
||
62 |
#else |
|
63 |
||
64 |
#define NET_Timeout JVM_Timeout |
|
65 |
#define NET_Read JVM_Read |
|
66 |
#define NET_RecvFrom JVM_RecvFrom |
|
67 |
#define NET_ReadV readv |
|
68 |
#define NET_Send JVM_Send |
|
69 |
#define NET_SendTo JVM_SendTo |
|
70 |
#define NET_WriteV writev |
|
71 |
#define NET_Connect JVM_Connect |
|
72 |
#define NET_Accept JVM_Accept |
|
73 |
#define NET_SocketClose JVM_SocketClose |
|
74 |
#define NET_Dup2 dup2 |
|
75 |
#define NET_Select select |
|
76 |
#define NET_Poll poll |
|
77 |
||
78 |
#endif |
|
79 |
||
80 |
#if defined(__linux__) && defined(AF_INET6) |
|
81 |
int getDefaultIPv6Interface(struct in6_addr *target_addr); |
|
82 |
#endif |
|
83 |
||
84 |
||
85 |
/* needed from libsocket on Solaris 8 */ |
|
86 |
||
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
87 |
typedef int (*getaddrinfo_f)(const char *nodename, const char *servname, |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
88 |
const struct addrinfo *hints, struct addrinfo **res); |
2 | 89 |
|
90 |
typedef void (*freeaddrinfo_f)(struct addrinfo *); |
|
91 |
||
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
92 |
typedef const char * (*gai_strerror_f)(int ecode); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
93 |
|
2 | 94 |
typedef int (*getnameinfo_f)(const struct sockaddr *, size_t, |
95 |
char *, size_t, char *, size_t, int); |
|
96 |
||
97 |
extern getaddrinfo_f getaddrinfo_ptr; |
|
98 |
extern freeaddrinfo_f freeaddrinfo_ptr; |
|
99 |
extern getnameinfo_f getnameinfo_ptr; |
|
100 |
||
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
101 |
void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env, |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
102 |
const char* hostname, |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
103 |
int gai_error); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
104 |
|
2 | 105 |
#define NET_WAIT_READ 0x01 |
106 |
#define NET_WAIT_WRITE 0x02 |
|
107 |
#define NET_WAIT_CONNECT 0x04 |
|
108 |
||
109 |
extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout); |
|
110 |
||
111 |
/************************************************************************ |
|
112 |
* Macros and constants |
|
113 |
*/ |
|
114 |
||
115 |
/* |
|
2938
b3338e271fcb
6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents:
2
diff
changeset
|
116 |
* On 64-bit JDKs we use a much larger stack and heap buffer. |
2 | 117 |
*/ |
2938
b3338e271fcb
6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents:
2
diff
changeset
|
118 |
#ifdef _LP64 |
b3338e271fcb
6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents:
2
diff
changeset
|
119 |
#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
|
120 |
#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
|
121 |
#else |
2 | 122 |
#define MAX_BUFFER_LEN 8192 |
123 |
#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
|
124 |
#endif |
2 | 125 |
|
126 |
#ifdef AF_INET6 |
|
127 |
||
128 |
#define SOCKADDR union { \ |
|
129 |
struct sockaddr_in him4; \ |
|
130 |
struct sockaddr_in6 him6; \ |
|
131 |
} |
|
132 |
||
133 |
#define SOCKADDR_LEN (ipv6_available() ? sizeof(SOCKADDR) : \ |
|
134 |
sizeof(struct sockaddr_in)) |
|
135 |
||
136 |
#else |
|
137 |
||
4814 | 138 |
#define SOCKADDR union { struct sockaddr_in him4; } |
2 | 139 |
#define SOCKADDR_LEN sizeof(SOCKADDR) |
140 |
||
141 |
#endif |
|
142 |
||
143 |
/************************************************************************ |
|
144 |
* Utilities |
|
145 |
*/ |
|
146 |
#ifdef __linux__ |
|
147 |
extern int kernelIsV22(); |
|
148 |
extern int kernelIsV24(); |
|
149 |
#endif |
|
150 |
||
151 |
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, |
|
152 |
const char *defaultDetail); |
|
153 |
||
154 |
||
155 |
#endif /* NET_UTILS_MD_H */ |