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

Print this page




  83     }
  84 
  85     /*
  86      * If the read is greater than our stack allocated buffer then
  87      * we allocate from the heap (up to a limit)
  88      */
  89     if (len > MAX_BUFFER_LEN) {
  90         if (len > MAX_HEAP_BUFFER_LEN) {
  91             len = MAX_HEAP_BUFFER_LEN;
  92         }
  93         bufP = (char *)malloc((size_t)len);
  94         if (bufP == NULL) {
  95             bufP = BUF;
  96             len = MAX_BUFFER_LEN;
  97         }
  98     } else {
  99         bufP = BUF;
 100     }
 101 
 102     if (timeout) {
 103         nread = NET_Timeout(fd, timeout);
 104         if (nread <= 0) {
 105             if (nread == 0) {


 106                 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
 107                             "Read timed out");
 108             } else if (nread == -1) {
 109                 if (errno == EBADF) {
 110                      JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
 111                  } else {
 112                      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 113                                                   "select/poll failed");
 114                  }
 115             }
 116             if (bufP != BUF) {
 117                 free(bufP);
 118             }
 119             return -1;
 120         }
 121     }
 122 
 123     nread = NET_Read(fd, bufP, len);
 124 
 125     if (nread <= 0) {




  83     }
  84 
  85     /*
  86      * If the read is greater than our stack allocated buffer then
  87      * we allocate from the heap (up to a limit)
  88      */
  89     if (len > MAX_BUFFER_LEN) {
  90         if (len > MAX_HEAP_BUFFER_LEN) {
  91             len = MAX_HEAP_BUFFER_LEN;
  92         }
  93         bufP = (char *)malloc((size_t)len);
  94         if (bufP == NULL) {
  95             bufP = BUF;
  96             len = MAX_BUFFER_LEN;
  97         }
  98     } else {
  99         bufP = BUF;
 100     }
 101 
 102     if (timeout) {
 103         nread = NET_Timeout(env, fd, timeout);
 104         if (nread <= 0) {
 105             if ((*env)->ExceptionCheck(env)) {
 106                 // fall-through, to potentially free, then return
 107             } else if (nread == 0) {
 108                 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
 109                             "Read timed out");
 110             } else if (nread == -1) {
 111                 if (errno == EBADF) {
 112                      JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
 113                  } else {
 114                      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
 115                                                   "select/poll failed");
 116                  }
 117             }
 118             if (bufP != BUF) {
 119                 free(bufP);
 120             }
 121             return -1;
 122         }
 123     }
 124 
 125     nread = NET_Read(fd, bufP, len);
 126 
 127     if (nread <= 0) {