You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/28 18:50:27 UTC
svn commit: r819640 -
/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
Author: mturk
Date: Mon Sep 28 16:50:26 2009
New Revision: 819640
URL: http://svn.apache.org/viewvc?rev=819640&view=rev
Log:
Port APR wait_for_io_or_timeout
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c?rev=819640&r1=819639&r2=819640&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c Mon Sep 28 16:50:26 2009
@@ -240,6 +240,23 @@
return fdo;
}
+static int wait_for_io_or_timeout(acr_file_t *f, int for_read)
+{
+ int rc, timeout = (int)(f->timeout / 1000);
+ f->ppoll.fd = f->fd;
+ f->ppoll.events = for_read ? POLLIN : POLLOUT;
+
+ do {
+ rc = poll(&f->ppoll, 1, timeout);
+ } while (rc == -1 && errno == EINTR);
+ if (rc == 0)
+ return ACR_TIMEUP;
+ else if (rc > 0)
+ return ACR_SUCCESS;
+ else
+ return errno;
+}
+
ACR_IO_EXPORT_DECLARE(jint, FileSystemProvider, read0)(ACR_JNISTDARGS,
jint file)
{
@@ -258,7 +275,14 @@
rd = r_read(f->fd, &c, 1);
if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
f->timeout != 0) {
-
+ int rc;
+ if ((rc = wait_for_io_or_timeout(f, 1))) {
+ f->err = rc;
+ return rc == ACR_TIMEUP ? 0 : -1;
+ }
+ else {
+ rd = r_read(f->fd, &c, 1);
+ }
}
if (rd == -1)
f->err = ACR_GET_OS_ERROR();