< prev index next >

src/java.base/solaris/native/libnet/solaris_close.c

Print this page




  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 }
  51 
  52 int NET_ReadV(int s, const struct iovec * vector, int count) {
  53     RESTARTABLE_RETURN_INT(readv(s, vector, count));
  54 }
  55 
  56 int NET_WriteV(int s, const struct iovec * vector, int count) {
  57     RESTARTABLE_RETURN_INT(writev(s, vector, count));
  58 }
  59 
  60 int NET_Send(int s, void *msg, int len, unsigned int flags) {
  61     RESTARTABLE_RETURN_INT(send(s, msg, len, flags));
  62 }
  63 
  64 int NET_SendTo(int s, const void *msg, int len,  unsigned  int flags,
  65                const struct sockaddr *to, int tolen) {
  66     RESTARTABLE_RETURN_INT(sendto(s, msg, len, flags, to, tolen));


  69 int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
  70     RESTARTABLE_RETURN_INT(connect(s, addr, addrlen));
  71 }
  72 
  73 int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
  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_Timeout(int s, long timeout) {
  90     int result;
  91     struct timeval t;
  92     long prevtime, newtime;
  93     struct pollfd pfd;
  94     pfd.fd = s;
  95     pfd.events = POLLIN;
  96 
  97     if (timeout > 0) {
  98         gettimeofday(&t, NULL);
  99         prevtime = (t.tv_sec * 1000)  +  t.tv_usec / 1000;
 100     }
 101 
 102     for(;;) {
 103         result = poll(&pfd, 1, timeout);
 104         if (result < 0 && errno == EINTR) {
 105             if (timeout > 0) {
 106                 gettimeofday(&t, NULL);
 107                 newtime = (t.tv_sec * 1000)  +  t.tv_usec /1000;
 108                 timeout -= newtime - prevtime;
 109                 if (timeout <= 0)
 110                     return 0;
 111                 prevtime = newtime;
 112             }
 113         } else {
 114             return result;
 115         }
 116     }
 117 }


  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_NonBlockingRead(int s, void* buf, size_t len) {
  48     RESTARTABLE_RETURN_INT(recv(s, buf, len, MSG_DONTWAIT));
  49 }
  50 
  51 int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
  52                  struct sockaddr *from, socklen_t *fromlen) {
  53     RESTARTABLE_RETURN_INT(recvfrom(s, buf, len, flags, from, fromlen));
  54 }
  55 
  56 int NET_ReadV(int s, const struct iovec * vector, int count) {
  57     RESTARTABLE_RETURN_INT(readv(s, vector, count));
  58 }
  59 
  60 int NET_WriteV(int s, const struct iovec * vector, int count) {
  61     RESTARTABLE_RETURN_INT(writev(s, vector, count));
  62 }
  63 
  64 int NET_Send(int s, void *msg, int len, unsigned int flags) {
  65     RESTARTABLE_RETURN_INT(send(s, msg, len, flags));
  66 }
  67 
  68 int NET_SendTo(int s, const void *msg, int len,  unsigned  int flags,
  69                const struct sockaddr *to, int tolen) {
  70     RESTARTABLE_RETURN_INT(sendto(s, msg, len, flags, to, tolen));


  73 int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
  74     RESTARTABLE_RETURN_INT(connect(s, addr, addrlen));
  75 }
  76 
  77 int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
  78     RESTARTABLE_RETURN_INT(accept(s, addr, addrlen));
  79 }
  80 
  81 int NET_SocketClose(int fd) {
  82     return close(fd);
  83 }
  84 
  85 int NET_Dup2(int fd, int fd2) {
  86     return dup2(fd, fd2);
  87 }
  88 
  89 int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
  90     RESTARTABLE_RETURN_INT(poll(ufds, nfds, timeout));
  91 }
  92 
  93 int NET_Timeout0(int s, long timeout,long currentTime) {
  94     int result;
  95     struct timeval t;
  96     long prevtime = currentTime, newtime;
  97     struct pollfd pfd;
  98     pfd.fd = s;
  99     pfd.events = POLLIN;
 100     





 101     for(;;) {
 102         result = poll(&pfd, 1, timeout);
 103         if (result < 0 && errno == EINTR) {
 104             if (timeout > 0) {
 105                 gettimeofday(&t, NULL);
 106                 newtime = (t.tv_sec * 1000)  +  t.tv_usec /1000;
 107                 timeout -= newtime - prevtime;
 108                 if (timeout <= 0)
 109                     return 0;
 110                 prevtime = newtime;
 111             }
 112         } else {
 113             return result;
 114         }
 115     }
 116 }
< prev index next >