src/solaris/native/java/net/solaris_close.c

Print this page




  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  *
  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.
  24  */
  25 
  26 #include <errno.h>
  27 #include <sys/socket.h>
  28 #include <stropts.h>
  29 #include <unistd.h>
  30 


  31 /* Support for restartable system calls on Solaris. */
  32 
  33 #define RESTARTABLE_RETURN_INT(_cmd) do {             \
  34     int _result;                                      \
  35     if (1) {                                          \
  36         do {                                          \
  37             _result = _cmd;                           \
  38         } while((_result == -1) && (errno == EINTR)); \
  39         return _result;                               \
  40     }                                                 \
  41 } while(0)
  42 
  43 int NET_Read(int s, void* buf, size_t len) {
  44     RESTARTABLE_RETURN_INT(recv(s, buf, len, 0));
  45 }
  46 
  47 int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
  48                  struct sockaddr *from, socklen_t *fromlen) {
  49     RESTARTABLE_RETURN_INT(recvfrom(s, buf, len, flags, from, fromlen));
  50 }


  74     RESTARTABLE_RETURN_INT(accept(s, addr, addrlen));
  75 }
  76 
  77 int NET_SocketClose(int fd) {
  78     return close(fd);
  79 }
  80 
  81 int NET_Dup2(int fd, int fd2) {
  82     return dup2(fd, fd2);
  83 }
  84 
  85 int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
  86     RESTARTABLE_RETURN_INT(poll(ufds, nfds, timeout));
  87 }
  88 
  89 int NET_Select(int s, fd_set *readfds, fd_set *writefds,
  90                fd_set *exceptfds, struct timeval *timeout) {
  91     RESTARTABLE_RETURN_INT(select(s, readfds, writefds, exceptfds, timeout));
  92 }
  93 
  94 int NET_Timeout(int s, long timeout) {
  95     int result;
  96     struct timeval t;
  97     long prevtime, newtime;
  98     struct pollfd pfd;
  99     pfd.fd = s;
 100     pfd.events = POLLIN;
 101 
 102     if (timeout > 0) {
 103         gettimeofday(&t, NULL);
 104         prevtime = (t.tv_sec * 1000)  +  t.tv_usec / 1000;
 105     }
 106 
 107     for(;;) {
 108         result = poll(&pfd, 1, timeout);
 109         if (result < 0 && errno == EINTR) {
 110             if (timeout > 0) {
 111                 gettimeofday(&t, NULL);
 112                 newtime = (t.tv_sec * 1000)  +  t.tv_usec /1000;
 113                 timeout -= newtime - prevtime;
 114                 if (timeout <= 0)


  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  *
  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.
  24  */
  25 
  26 #include <errno.h>
  27 #include <sys/socket.h>
  28 #include <stropts.h>
  29 #include <unistd.h>
  30 
  31 #include "jni.h"
  32 
  33 /* Support for restartable system calls on Solaris. */
  34 
  35 #define RESTARTABLE_RETURN_INT(_cmd) do {             \
  36     int _result;                                      \
  37     if (1) {                                          \
  38         do {                                          \
  39             _result = _cmd;                           \
  40         } while((_result == -1) && (errno == EINTR)); \
  41         return _result;                               \
  42     }                                                 \
  43 } while(0)
  44 
  45 int NET_Read(int s, void* buf, size_t len) {
  46     RESTARTABLE_RETURN_INT(recv(s, buf, len, 0));
  47 }
  48 
  49 int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
  50                  struct sockaddr *from, socklen_t *fromlen) {
  51     RESTARTABLE_RETURN_INT(recvfrom(s, buf, len, flags, from, fromlen));
  52 }


  76     RESTARTABLE_RETURN_INT(accept(s, addr, addrlen));
  77 }
  78 
  79 int NET_SocketClose(int fd) {
  80     return close(fd);
  81 }
  82 
  83 int NET_Dup2(int fd, int fd2) {
  84     return dup2(fd, fd2);
  85 }
  86 
  87 int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
  88     RESTARTABLE_RETURN_INT(poll(ufds, nfds, timeout));
  89 }
  90 
  91 int NET_Select(int s, fd_set *readfds, fd_set *writefds,
  92                fd_set *exceptfds, struct timeval *timeout) {
  93     RESTARTABLE_RETURN_INT(select(s, readfds, writefds, exceptfds, timeout));
  94 }
  95 
  96 int NET_Timeout(JNIEnv *unused, int s, long timeout) {
  97     int result;
  98     struct timeval t;
  99     long prevtime, newtime;
 100     struct pollfd pfd;
 101     pfd.fd = s;
 102     pfd.events = POLLIN;
 103 
 104     if (timeout > 0) {
 105         gettimeofday(&t, NULL);
 106         prevtime = (t.tv_sec * 1000)  +  t.tv_usec / 1000;
 107     }
 108 
 109     for(;;) {
 110         result = poll(&pfd, 1, timeout);
 111         if (result < 0 && errno == EINTR) {
 112             if (timeout > 0) {
 113                 gettimeofday(&t, NULL);
 114                 newtime = (t.tv_sec * 1000)  +  t.tv_usec /1000;
 115                 timeout -= newtime - prevtime;
 116                 if (timeout <= 0)