181 }
182
183 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
184 size_t res;
185 RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
186 return res;
187 }
188
189 inline int os::close(int fd) {
190 RESTARTABLE_RETURN_INT(::close(fd));
191 }
192
193 inline int os::socket_close(int fd) {
194 RESTARTABLE_RETURN_INT(::close(fd));
195 }
196
197 inline int os::socket(int domain, int type, int protocol) {
198 return ::socket(domain, type, protocol);
199 }
200
201 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
202 RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
203 }
204
205 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
206 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
207 }
208
209 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
210 return os::send(fd, buf, nBytes, flags);
211 }
212
213 inline int os::timeout(int fd, long timeout) {
214 julong prevtime,newtime;
215 struct timeval t;
216
217 gettimeofday(&t, NULL);
218 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
219
220 for(;;) {
221 struct pollfd pfd;
222
223 pfd.fd = fd;
224 pfd.events = POLLIN | POLLERR;
225
226 int res = ::poll(&pfd, 1, timeout);
227
228 if (res == OS_ERR && errno == EINTR) {
229
230 // On Bsd any value < 0 means "forever"
231
232 if(timeout >= 0) {
233 gettimeofday(&t, NULL);
234 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
235 timeout -= newtime - prevtime;
236 if(timeout <= 0)
237 return OS_OK;
238 prevtime = newtime;
239 }
240 } else
241 return res;
242 }
243 }
244
245 inline int os::listen(int fd, int count) {
246 return ::listen(fd, count);
247 }
248
249 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
250 RESTARTABLE_RETURN_INT(::connect(fd, him, len));
251 }
252
253 inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
254 // At least OpenBSD and FreeBSD can return EINTR from accept.
255 RESTARTABLE_RETURN_INT(::accept(fd, him, len));
256 }
257
258 inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
259 sockaddr* from, socklen_t* fromlen) {
260 RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
261 }
262
263 inline int os::sendto(int fd, char* buf, size_t len, uint flags,
264 struct sockaddr *to, socklen_t tolen) {
265 RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
266 }
267
268 inline int os::socket_shutdown(int fd, int howto) {
269 return ::shutdown(fd, howto);
270 }
271
272 inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
273 return ::bind(fd, him, len);
274 }
275
276 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
277 return ::getsockname(fd, him, len);
278 }
279
280 inline int os::get_host_name(char* name, int namelen) {
281 return ::gethostname(name, namelen);
282 }
283
284 inline struct hostent* os::get_host_by_name(char* name) {
285 return ::gethostbyname(name);
286 }
287
288 inline int os::get_sock_opt(int fd, int level, int optname,
289 char *optval, socklen_t* optlen) {
290 return ::getsockopt(fd, level, optname, optval, optlen);
291 }
292
293 inline int os::set_sock_opt(int fd, int level, int optname,
294 const char* optval, socklen_t optlen) {
295 return ::setsockopt(fd, level, optname, optval, optlen);
296 }
297 #endif // OS_BSD_VM_OS_BSD_INLINE_HPP
|
181 }
182
183 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
184 size_t res;
185 RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
186 return res;
187 }
188
189 inline int os::close(int fd) {
190 RESTARTABLE_RETURN_INT(::close(fd));
191 }
192
193 inline int os::socket_close(int fd) {
194 RESTARTABLE_RETURN_INT(::close(fd));
195 }
196
197 inline int os::socket(int domain, int type, int protocol) {
198 return ::socket(domain, type, protocol);
199 }
200
201 inline int os::recv(int fd, char* buf, int nBytes, int flags) {
202 RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
203 }
204
205 inline int os::send(int fd, char* buf, int nBytes, int flags) {
206 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
207 }
208
209 inline int os::raw_send(int fd, char* buf, int nBytes, int flags) {
210 return os::send(fd, buf, nBytes, flags);
211 }
212
213 inline int os::timeout(int fd, long timeout) {
214 julong prevtime,newtime;
215 struct timeval t;
216
217 gettimeofday(&t, NULL);
218 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
219
220 for(;;) {
221 struct pollfd pfd;
222
223 pfd.fd = fd;
224 pfd.events = POLLIN | POLLERR;
225
226 int res = ::poll(&pfd, 1, timeout);
227
228 if (res == OS_ERR && errno == EINTR) {
229
230 // On Bsd any value < 0 means "forever"
231
232 if(timeout >= 0) {
233 gettimeofday(&t, NULL);
234 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
235 timeout -= newtime - prevtime;
236 if(timeout <= 0)
237 return OS_OK;
238 prevtime = newtime;
239 }
240 } else
241 return res;
242 }
243 }
244
245 inline int os::listen(int fd, int count) {
246 return ::listen(fd, count);
247 }
248
249 inline int os::connect(int fd, struct sockaddr* him, int len) {
250 RESTARTABLE_RETURN_INT(::connect(fd, him, len));
251 }
252
253 inline int os::accept(int fd, struct sockaddr* him, int* len) {
254 // At least OpenBSD and FreeBSD can return EINTR from accept.
255 RESTARTABLE_RETURN_INT(::accept(fd, him, len));
256 }
257
258 inline int os::recvfrom(int fd, char* buf, int nBytes, int flags,
259 sockaddr* from, int* fromlen) {
260 RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
261 }
262
263 inline int os::sendto(int fd, char* buf, int len, int flags,
264 struct sockaddr *to, int tolen) {
265 RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
266 }
267
268 inline int os::socket_shutdown(int fd, int howto) {
269 return ::shutdown(fd, howto);
270 }
271
272 inline int os::bind(int fd, struct sockaddr* him, int len) {
273 return ::bind(fd, him, len);
274 }
275
276 inline int os::get_sock_name(int fd, struct sockaddr* him, int* len) {
277 return ::getsockname(fd, him, len);
278 }
279
280 inline int os::get_host_name(char* name, int namelen) {
281 return ::gethostname(name, namelen);
282 }
283
284 inline struct hostent* os::get_host_by_name(char* name) {
285 return ::gethostbyname(name);
286 }
287
288 inline int os::get_sock_opt(int fd, int level, int optname,
289 char *optval, int* optlen) {
290 return ::getsockopt(fd, level, optname, optval, optlen);
291 }
292
293 inline int os::set_sock_opt(int fd, int level, int optname,
294 const char* optval, int optlen) {
295 return ::setsockopt(fd, level, optname, optval, optlen);
296 }
297 #endif // OS_BSD_VM_OS_BSD_INLINE_HPP
|