88 if (len > MAX_HEAP_BUFFER_LEN) {
89 len = MAX_HEAP_BUFFER_LEN;
90 }
91 bufP = (char *)malloc((size_t)len);
92 if (bufP == NULL) {
93 /* allocation failed so use stack buffer */
94 bufP = BUF;
95 len = MAX_BUFFER_LEN;
96 }
97 }
98
99
100 if (timeout) {
101 if (timeout <= 5000 || !isRcvTimeoutSupported) {
102 int ret = NET_Timeout (fd, timeout);
103
104 if (ret <= 0) {
105 if (ret == 0) {
106 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
107 "Read timed out");
108 } else if (ret == JVM_IO_ERR) {
109 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
110 } else if (ret == JVM_IO_INTR) {
111 JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
112 "Operation interrupted");
113 }
114 if (bufP != BUF) {
115 free(bufP);
116 }
117 return -1;
118 }
119
120 /*check if the socket has been closed while we were in timeout*/
121 newfd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
122 if (newfd == -1) {
123 NET_ThrowSocketException(env, "Socket Closed");
124 if (bufP != BUF) {
125 free(bufP);
126 }
127 return -1;
128 }
129 }
130 }
131
132 nread = recv(fd, bufP, len, 0);
|
88 if (len > MAX_HEAP_BUFFER_LEN) {
89 len = MAX_HEAP_BUFFER_LEN;
90 }
91 bufP = (char *)malloc((size_t)len);
92 if (bufP == NULL) {
93 /* allocation failed so use stack buffer */
94 bufP = BUF;
95 len = MAX_BUFFER_LEN;
96 }
97 }
98
99
100 if (timeout) {
101 if (timeout <= 5000 || !isRcvTimeoutSupported) {
102 int ret = NET_Timeout (fd, timeout);
103
104 if (ret <= 0) {
105 if (ret == 0) {
106 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
107 "Read timed out");
108 } else if (ret == -1) {
109 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
110 }
111 if (bufP != BUF) {
112 free(bufP);
113 }
114 return -1;
115 }
116
117 /*check if the socket has been closed while we were in timeout*/
118 newfd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
119 if (newfd == -1) {
120 NET_ThrowSocketException(env, "Socket Closed");
121 if (bufP != BUF) {
122 free(bufP);
123 }
124 return -1;
125 }
126 }
127 }
128
129 nread = recv(fd, bufP, len, 0);
|