hotspot/src/os/bsd/vm/os_bsd.inline.hpp
changeset 27400 c5955f4b7c84
parent 26682 f339669ba825
child 34633 2a6c7c7b30a7
equal deleted inserted replaced
27246:49642d463211 27400:c5955f4b7c84
   179 
   179 
   180 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
   180 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
   181   return os::send(fd, buf, nBytes, flags);
   181   return os::send(fd, buf, nBytes, flags);
   182 }
   182 }
   183 
   183 
   184 inline int os::timeout(int fd, long timeout) {
       
   185   julong prevtime,newtime;
       
   186   struct timeval t;
       
   187 
       
   188   gettimeofday(&t, NULL);
       
   189   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
       
   190 
       
   191   for(;;) {
       
   192     struct pollfd pfd;
       
   193 
       
   194     pfd.fd = fd;
       
   195     pfd.events = POLLIN | POLLERR;
       
   196 
       
   197     int res = ::poll(&pfd, 1, timeout);
       
   198 
       
   199     if (res == OS_ERR && errno == EINTR) {
       
   200 
       
   201       // On Bsd any value < 0 means "forever"
       
   202 
       
   203       if(timeout >= 0) {
       
   204         gettimeofday(&t, NULL);
       
   205         newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
       
   206         timeout -= newtime - prevtime;
       
   207         if(timeout <= 0)
       
   208           return OS_OK;
       
   209         prevtime = newtime;
       
   210       }
       
   211     } else
       
   212       return res;
       
   213   }
       
   214 }
       
   215 
       
   216 inline int os::listen(int fd, int count) {
       
   217   return ::listen(fd, count);
       
   218 }
       
   219 
       
   220 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
   184 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
   221   RESTARTABLE_RETURN_INT(::connect(fd, him, len));
   185   RESTARTABLE_RETURN_INT(::connect(fd, him, len));
   222 }
   186 }
   223 
   187 
   224 inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
       
   225   // At least OpenBSD and FreeBSD can return EINTR from accept.
       
   226   RESTARTABLE_RETURN_INT(::accept(fd, him, len));
       
   227 }
       
   228 
       
   229 inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
       
   230                          sockaddr* from, socklen_t* fromlen) {
       
   231   RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
       
   232 }
       
   233 
       
   234 inline int os::sendto(int fd, char* buf, size_t len, uint flags,
       
   235                       struct sockaddr *to, socklen_t tolen) {
       
   236   RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
       
   237 }
       
   238 
       
   239 inline int os::socket_shutdown(int fd, int howto) {
       
   240   return ::shutdown(fd, howto);
       
   241 }
       
   242 
       
   243 inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
       
   244   return ::bind(fd, him, len);
       
   245 }
       
   246 
       
   247 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
       
   248   return ::getsockname(fd, him, len);
       
   249 }
       
   250 
       
   251 inline int os::get_host_name(char* name, int namelen) {
       
   252   return ::gethostname(name, namelen);
       
   253 }
       
   254 
       
   255 inline struct hostent* os::get_host_by_name(char* name) {
   188 inline struct hostent* os::get_host_by_name(char* name) {
   256   return ::gethostbyname(name);
   189   return ::gethostbyname(name);
   257 }
       
   258 
       
   259 inline int os::get_sock_opt(int fd, int level, int optname,
       
   260                             char *optval, socklen_t* optlen) {
       
   261   return ::getsockopt(fd, level, optname, optval, optlen);
       
   262 }
       
   263 
       
   264 inline int os::set_sock_opt(int fd, int level, int optname,
       
   265                             const char* optval, socklen_t optlen) {
       
   266   return ::setsockopt(fd, level, optname, optval, optlen);
       
   267 }
   190 }
   268 
   191 
   269 inline bool os::supports_monotonic_clock() {
   192 inline bool os::supports_monotonic_clock() {
   270 #ifdef __APPLE__
   193 #ifdef __APPLE__
   271   return true;
   194   return true;