Author: mturk
Date: Tue Aug 9 18:36:19 2011
New Revision: 1155459
URL: http://svn.apache.org/viewvc?rev=1155459&view=rev
Log:
Implement partial read/write
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h?rev=1155459&r1=1155458&r2=1155459&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h Tue
Aug 9 18:36:19 2011
@@ -23,6 +23,8 @@
* Socket flags
*/
#define ACR_SO_RDEOF 0x0001
+#define ACR_SO_RPART 0x0002
+#define ACR_SO_WPART 0x0004
#define ACR_SO_NONBLOCK 0x0010
#define ACR_SO_BROADCAST 0x0020
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c?rev=1155459&r1=1155458&r2=1155459&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c Tue Aug
9 18:36:19 2011
@@ -216,9 +216,14 @@ ACR_NET_EXPORT(jint, SocketStream, read1
rc = ACR_ENOMEM;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_RPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_RPART);
+ goto waitio;
+ }
rd = r_read(sd, bb, len);
if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLIN);
if (rc != 0)
goto finally;
@@ -228,7 +233,8 @@ ACR_NET_EXPORT(jint, SocketStream, read1
rc = ACR_GET_NETOS_ERROR();
else if (rd == 0)
ss->fd->flags |= ACR_SO_RDEOF;
-
+ else if (ss->fd->timeout > 0 && rd < len)
+ ss->fd->flags |= ACR_SO_RPART;
finally:
sdrelease(ss);
if (rc == 0) {
@@ -277,9 +283,14 @@ ACR_NET_EXPORT(jint, SocketStream, read2
rc = ACR_EINVAL;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_RPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_RPART);
+ goto waitio;
+ }
rd = r_read(sd, bb + po, len);
if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLIN);
if (rc != 0)
goto finally;
@@ -289,6 +300,8 @@ ACR_NET_EXPORT(jint, SocketStream, read2
rc = ACR_GET_NETOS_ERROR();
else if (rd == 0)
ss->fd->flags |= ACR_SO_RDEOF;
+ else if (ss->fd->timeout > 0 && rd < len)
+ ss->fd->flags |= ACR_SO_RPART;
finally:
sdrelease(ss);
@@ -322,10 +335,14 @@ ACR_NET_EXPORT(jint, SocketStream, read3
rc = ACR_EINVAL;
goto finally;
}
-
+ if (ACR_HASFLAG(ss->fd, ACR_SO_RPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_RPART);
+ goto waitio;
+ }
rd = r_read(sd, bb + off, len);
if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLIN);
if (rc != 0)
goto finally;
@@ -335,6 +352,8 @@ ACR_NET_EXPORT(jint, SocketStream, read3
rc = ACR_GET_NETOS_ERROR();
else if (rd == 0)
ss->fd->flags |= ACR_SO_RDEOF;
+ else if (ss->fd->timeout > 0 && rd < len)
+ ss->fd->flags |= ACR_SO_RPART;
finally:
sdrelease(ss);
@@ -359,9 +378,14 @@ ACR_NET_EXPORT(jint, SocketStream, write
rc = ACR_EBADF;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
wr = r_write(sd, &ch, 1);
if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -369,6 +393,8 @@ ACR_NET_EXPORT(jint, SocketStream, write
}
if (wr == -1)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < 1)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (rc != 0) {
@@ -398,9 +424,14 @@ ACR_NET_EXPORT(jint, SocketStream, write
rc = ACR_EINVAL;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
wr = r_write(sd, bb + off, len);
if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -408,6 +439,8 @@ ACR_NET_EXPORT(jint, SocketStream, write
}
if (wr == -1)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (bb != 0)
@@ -439,9 +472,14 @@ ACR_NET_EXPORT(jint, SocketStream, write
rc = ACR_EINVAL;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
wr = r_write(sd, bb + po, len);
if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -449,6 +487,8 @@ ACR_NET_EXPORT(jint, SocketStream, write
}
if (wr == -1)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (rc != 0) {
@@ -478,9 +518,14 @@ ACR_NET_EXPORT(jint, SocketStream, write
rc = ACR_EINVAL;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
wr = r_write(sd, bb + off, len);
if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -488,6 +533,8 @@ ACR_NET_EXPORT(jint, SocketStream, write
}
if (wr == -1)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (rc != 0) {
@@ -549,12 +596,17 @@ ACR_NET_EXPORT(jlong, SocketStream, writ
iov[i].iov_len = (size_t)(*env)->GetArrayLength(env, boa[i]);
iov[i].iov_base = (void *)(*env)->GetByteArrayElements(env, boa[i], 0);
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
do {
wr = writev(sd, iov, len);
} while (wr == -1 && errno == EAGAIN);
if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -564,6 +616,8 @@ ACR_NET_EXPORT(jlong, SocketStream, writ
}
if (wr == -1)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (boa != 0) {
@@ -626,12 +680,17 @@ ACR_NET_EXPORT(jlong, SocketStream, writ
(*env)->DeleteLocalRef(env, bb);
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
do {
wr = writev(sd, iov, len);
} while (wr == -1 && errno == EAGAIN);
if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -641,6 +700,8 @@ ACR_NET_EXPORT(jlong, SocketStream, writ
}
if (wr == -1)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (iov != onstack)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c?rev=1155459&r1=1155458&r2=1155459&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c Tue Aug
9 18:36:19 2011
@@ -152,9 +152,14 @@ ACR_NET_EXPORT(jint, SocketStream, read0
}
if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
goto finally;
+ if (ACR_HASFLAG(ss->fd, ACR_SO_RPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_RPART);
+ goto waitio;
+ }
rd = recv(sd, &ch, 1, 0);
if (rd == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLIN);
if (rc != 0)
goto finally;
@@ -208,9 +213,14 @@ ACR_NET_EXPORT(jint, SocketStream, read1
rc = ACR_ENOMEM;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_RPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_RPART);
+ goto waitio;
+ }
rd = recv(sd, bb, len, 0);
if (rd == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLIN);
if (rc != 0)
goto finally;
@@ -220,6 +230,8 @@ ACR_NET_EXPORT(jint, SocketStream, read1
rc = ACR_GET_OS_ERROR();
else if (rd == 0)
ss->fd->flags |= ACR_SO_RDEOF;
+ else if (ss->fd->timeout > 0 && rd < len)
+ ss->fd->flags |= ACR_SO_RPART;
finally:
sdrelease(ss);
@@ -269,9 +281,14 @@ ACR_NET_EXPORT(jint, SocketStream, read2
rc = ACR_EINVAL;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_RPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_RPART);
+ goto waitio;
+ }
rd = recv(sd, bb + po, len, 0);
if (rd == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLIN);
if (rc != 0)
goto finally;
@@ -281,6 +298,8 @@ ACR_NET_EXPORT(jint, SocketStream, read2
rc = ACR_GET_NETOS_ERROR();
else if (rd == 0)
ss->fd->flags |= ACR_SO_RDEOF;
+ else if (ss->fd->timeout > 0 && rd < len)
+ ss->fd->flags |= ACR_SO_RPART;
finally:
sdrelease(ss);
@@ -314,10 +333,14 @@ ACR_NET_EXPORT(jint, SocketStream, read3
rc = ACR_EINVAL;
goto finally;
}
-
+ if (ACR_HASFLAG(ss->fd, ACR_SO_RPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_RPART);
+ goto waitio;
+ }
rd = recv(sd, bb + off, len, 0);
if (rd == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLIN);
if (rc != 0)
goto finally;
@@ -327,6 +350,8 @@ ACR_NET_EXPORT(jint, SocketStream, read3
rc = ACR_GET_NETOS_ERROR();
else if (rd == 0)
ss->fd->flags |= ACR_SO_RDEOF;
+ else if (ss->fd->timeout > 0 && rd < len)
+ ss->fd->flags |= ACR_SO_RPART;
finally:
sdrelease(ss);
@@ -351,9 +376,14 @@ ACR_NET_EXPORT(jint, SocketStream, write
rc = ACR_EBADF;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
wr = send(sd, &ch, 1, 0);
if (wr == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -361,6 +391,8 @@ ACR_NET_EXPORT(jint, SocketStream, write
}
if (wr == SOCKET_ERROR)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < 1)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (rc != 0) {
@@ -390,9 +422,14 @@ ACR_NET_EXPORT(jint, SocketStream, write
rc = ACR_EINVAL;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
wr = send(sd, bb + off, len, 0);
if (wr == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -400,6 +437,8 @@ ACR_NET_EXPORT(jint, SocketStream, write
}
if (wr == SOCKET_ERROR)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (bb != 0)
@@ -431,9 +470,14 @@ ACR_NET_EXPORT(jint, SocketStream, write
rc = ACR_EINVAL;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
wr = send(sd, bb + po, len, 0);
if (wr == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -441,6 +485,8 @@ ACR_NET_EXPORT(jint, SocketStream, write
}
if (wr == SOCKET_ERROR)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (rc != 0) {
@@ -470,9 +516,14 @@ ACR_NET_EXPORT(jint, SocketStream, write
rc = ACR_EINVAL;
goto finally;
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
wr = send(sd, bb + off, len, 0);
if (wr == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
@@ -480,6 +531,8 @@ ACR_NET_EXPORT(jint, SocketStream, write
}
if (wr == SOCKET_ERROR)
rc = ACR_GET_NETOS_ERROR();
+ else if (ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (rc != 0) {
@@ -542,15 +595,22 @@ ACR_NET_EXPORT(jlong, SocketStream, writ
iov[i].len = (u_long)(*env)->GetArrayLength(env, boa[i]);
iov[i].buf = (char *)(*env)->GetByteArrayElements(env, boa[i], 0);
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
if (WSASend(sd, iov, len, &wr, 0, 0, 0) == SOCKET_ERROR)
rc = WSAGetLastError();
if (rc != 0 && rc == WSAEWOULDBLOCK && ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
if (WSASend(sd, iov, len, &wr, 0, 0, 0) == SOCKET_ERROR)
rc = WSAGetLastError();
}
+ if (rc == 0 && ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (boa != 0) {
@@ -614,15 +674,22 @@ ACR_NET_EXPORT(jlong, SocketStream, writ
(*env)->DeleteLocalRef(env, bb);
}
+ if (ACR_HASFLAG(ss->fd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(ss->fd, ACR_SO_WPART);
+ goto waitio;
+ }
if (WSASend(sd, iov, len, &wr, 0, 0, 0) == SOCKET_ERROR)
rc = WSAGetLastError();
if (rc != 0 && rc == WSAEWOULDBLOCK && ss->fd->timeout > 0) {
+waitio:
rc = AcrWaitIO(sd, ss->fd->timeout, POLLOUT);
if (rc != 0)
goto finally;
if (WSASend(sd, iov, len, &wr, 0, 0, 0) == SOCKET_ERROR)
rc = WSAGetLastError();
}
+ if (rc == 0 && ss->fd->timeout > 0 && wr < len)
+ ss->fd->flags |= ACR_SO_WPART;
finally:
sdrelease(ss);
if (iov != onstack)