93 /* if heap exhausted resort to stack buffer */ 94 if (bufP == NULL) { 95 bufP = BUF; 96 buflen = MAX_BUFFER_LEN; 97 } 98 } 99 100 while(len > 0) { 101 int loff = 0; 102 int chunkLen = min(buflen, len); 103 int llen = chunkLen; 104 (*env)->GetByteArrayRegion(env, data, off, chunkLen, (jbyte *)bufP); 105 106 while(llen > 0) { 107 int n = NET_Send(fd, bufP + loff, llen, 0); 108 if (n > 0) { 109 llen -= n; 110 loff += n; 111 continue; 112 } 113 if (n == JVM_IO_INTR) { 114 JNU_ThrowByName(env, "java/io/InterruptedIOException", 0); 115 } else { 116 if (errno == ECONNRESET) { 117 JNU_ThrowByName(env, "sun/net/ConnectionResetException", 118 "Connection reset"); 119 } else { 120 NET_ThrowByNameWithLastError(env, "java/net/SocketException", 121 "Write failed"); 122 } 123 } 124 if (bufP != BUF) { 125 free(bufP); 126 } 127 return; 128 } 129 len -= chunkLen; 130 off += chunkLen; 131 } 132 133 if (bufP != BUF) { 134 free(bufP); 135 } 136 } | 93 /* if heap exhausted resort to stack buffer */ 94 if (bufP == NULL) { 95 bufP = BUF; 96 buflen = MAX_BUFFER_LEN; 97 } 98 } 99 100 while(len > 0) { 101 int loff = 0; 102 int chunkLen = min(buflen, len); 103 int llen = chunkLen; 104 (*env)->GetByteArrayRegion(env, data, off, chunkLen, (jbyte *)bufP); 105 106 while(llen > 0) { 107 int n = NET_Send(fd, bufP + loff, llen, 0); 108 if (n > 0) { 109 llen -= n; 110 loff += n; 111 continue; 112 } 113 if (errno == ECONNRESET) { 114 JNU_ThrowByName(env, "sun/net/ConnectionResetException", 115 "Connection reset"); 116 } else { 117 NET_ThrowByNameWithLastError(env, "java/net/SocketException", 118 "Write failed"); 119 } 120 if (bufP != BUF) { 121 free(bufP); 122 } 123 return; 124 } 125 len -= chunkLen; 126 off += chunkLen; 127 } 128 129 if (bufP != BUF) { 130 free(bufP); 131 } 132 } |