Mercurial > hg > graal-jvmci-8
comparison src/os/linux/vm/hpi_linux.hpp @ 0:a61af66fc99e jdk7-b24
Initial load
author | duke |
---|---|
date | Sat, 01 Dec 2007 00:00:00 +0000 |
parents | |
children | 2a1a77d3458f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a61af66fc99e |
---|---|
1 /* | |
2 * Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved. | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // | |
26 // Because the interruptible IO has been dropped for HotSpot/Linux, | |
27 // the following HPI interface is very different from HotSparc. | |
28 // | |
29 | |
30 #include <unistd.h> | |
31 #include <sys/socket.h> | |
32 #include <sys/poll.h> | |
33 #include <sys/ioctl.h> | |
34 #include <netdb.h> | |
35 | |
36 // HPI_FileInterface | |
37 | |
38 inline int hpi::close(int fd) { | |
39 return ::close(fd); | |
40 } | |
41 | |
42 inline size_t hpi::read(int fd, void *buf, unsigned int nBytes) { | |
43 size_t res; | |
44 RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); | |
45 return res; | |
46 } | |
47 | |
48 inline size_t hpi::write(int fd, const void *buf, unsigned int nBytes) { | |
49 size_t res; | |
50 RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); | |
51 return res; | |
52 } | |
53 | |
54 | |
55 // HPI_SocketInterface | |
56 | |
57 inline int hpi::socket_close(int fd) { | |
58 return ::close(fd); | |
59 } | |
60 | |
61 inline int hpi::socket(int domain, int type, int protocol) { | |
62 return ::socket(domain, type, protocol); | |
63 } | |
64 | |
65 inline int hpi::recv(int fd, char *buf, int nBytes, int flags) { | |
66 RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags)); | |
67 } | |
68 | |
69 inline int hpi::send(int fd, char *buf, int nBytes, int flags) { | |
70 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags)); | |
71 } | |
72 | |
73 inline int hpi::timeout(int fd, long timeout) { | |
74 julong prevtime,newtime; | |
75 struct timeval t; | |
76 | |
77 gettimeofday(&t, NULL); | |
78 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; | |
79 | |
80 for(;;) { | |
81 struct pollfd pfd; | |
82 | |
83 pfd.fd = fd; | |
84 pfd.events = POLLIN | POLLERR; | |
85 | |
86 int res = ::poll(&pfd, 1, timeout); | |
87 | |
88 if (res == OS_ERR && errno == EINTR) { | |
89 | |
90 // On Linux any value < 0 means "forever" | |
91 | |
92 if(timeout >= 0) { | |
93 gettimeofday(&t, NULL); | |
94 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; | |
95 timeout -= newtime - prevtime; | |
96 if(timeout <= 0) | |
97 return OS_OK; | |
98 prevtime = newtime; | |
99 } | |
100 } else | |
101 return res; | |
102 } | |
103 } | |
104 | |
105 inline int hpi::listen(int fd, int count) { | |
106 return ::listen(fd, count); | |
107 } | |
108 | |
109 inline int hpi::connect(int fd, struct sockaddr *him, int len) { | |
110 RESTARTABLE_RETURN_INT(::connect(fd, him, len)); | |
111 } | |
112 | |
113 inline int hpi::accept(int fd, struct sockaddr *him, int *len) { | |
114 // This cast is from int to unsigned int on linux. Since we | |
115 // only pass the parameter "len" around the vm and don't try to | |
116 // fetch it's value, this cast is safe for now. The java.net group | |
117 // may need and want to change this interface someday if socklen_t goes | |
118 // to 64 bits on some platform that we support. | |
119 // Linux doc says this can't return EINTR, unlike accept() on Solaris | |
120 | |
121 return ::accept(fd, him, (socklen_t *)len); | |
122 } | |
123 | |
124 inline int hpi::recvfrom(int fd, char *buf, int nBytes, int flags, | |
125 sockaddr *from, int *fromlen) { | |
126 RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen)); | |
127 } | |
128 | |
129 inline int hpi::sendto(int fd, char *buf, int len, int flags, | |
130 struct sockaddr *to, int tolen) { | |
131 RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen)); | |
132 } | |
133 | |
134 inline int hpi::socket_available(int fd, jint *pbytes) { | |
135 // Linux doc says EINTR not returned, unlike Solaris | |
136 int ret = ::ioctl(fd, FIONREAD, pbytes); | |
137 | |
138 //%% note ioctl can return 0 when successful, JVM_SocketAvailable | |
139 // is expected to return 0 on failure and 1 on success to the jdk. | |
140 return (ret < 0) ? 0 : 1; | |
141 } | |
142 | |
143 | |
144 // following methods have been updated to avoid problems in | |
145 // hpi's sockets calls based on sys_api_td.c (JDK1.3) | |
146 | |
147 /* | |
148 HPIDECL(socket_shutdown, "socket_shutdown", _socket, SocketShutdown, | |
149 int, "%d", | |
150 (int fd, int howto), | |
151 ("fd = %d, howto = %d", fd, howto), | |
152 (fd, howto)); | |
153 */ | |
154 inline int hpi::socket_shutdown(int fd, int howto){ | |
155 return ::shutdown(fd, howto); | |
156 } | |
157 | |
158 /* | |
159 HPIDECL(bind, "bind", _socket, Bind, | |
160 int, "%d", | |
161 (int fd, struct sockaddr *him, int len), | |
162 ("fd = %d, him = %p, len = %d", | |
163 fd, him, len), | |
164 (fd, him, len)); | |
165 */ | |
166 inline int hpi::bind(int fd, struct sockaddr *him, int len){ | |
167 return ::bind(fd, him, len); | |
168 } | |
169 | |
170 /* | |
171 HPIDECL(get_sock_name, "get_sock_name", _socket, GetSocketName, | |
172 int, "%d", | |
173 (int fd, struct sockaddr *him, int *len), | |
174 ("fd = %d, him = %p, len = %p", | |
175 fd, him, len), | |
176 (fd, him, len)); | |
177 */ | |
178 inline int hpi::get_sock_name(int fd, struct sockaddr *him, int *len){ | |
179 return ::getsockname(fd, him, (socklen_t *)len); | |
180 } | |
181 | |
182 /* | |
183 HPIDECL(get_host_name, "get_host_name", _socket, GetHostName, int, "%d", | |
184 (char *hostname, int namelen), | |
185 ("hostname = %p, namelen = %d", | |
186 hostname, namelen), | |
187 (hostname, namelen)); | |
188 */ | |
189 inline int hpi::get_host_name(char* name, int namelen){ | |
190 return ::gethostname(name, namelen); | |
191 } | |
192 | |
193 /* | |
194 HPIDECL(get_sock_opt, "get_sock_opt", _socket, SocketGetOption, int, "%d", | |
195 (int fd, int level, int optname, char *optval, int* optlen), | |
196 ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %p", | |
197 fd, level, optname, optval, optlen), | |
198 (fd, level, optname, optval, optlen)); | |
199 */ | |
200 inline int hpi::get_sock_opt(int fd, int level, int optname, | |
201 char *optval, int* optlen){ | |
202 return ::getsockopt(fd, level, optname, optval, (socklen_t *)optlen); | |
203 } | |
204 | |
205 /* | |
206 HPIDECL(set_sock_opt, "set_sock_opt", _socket, SocketSetOption, int, "%d", | |
207 (int fd, int level, int optname, const char *optval, int optlen), | |
208 ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %d", | |
209 fd, level, optname, optval, optlen), | |
210 (fd, level, optname, optval, optlen)); | |
211 */ | |
212 inline int hpi::set_sock_opt(int fd, int level, int optname, | |
213 const char *optval, int optlen){ | |
214 return ::setsockopt(fd, level, optname, optval, optlen); | |
215 } | |
216 | |
217 | |
218 // Reconciliation History | |
219 // hpi_solaris.hpp 1.9 99/08/30 16:31:23 | |
220 // End |