You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bj...@apache.org on 2010/04/06 20:53:23 UTC
svn commit: r931271 - in /apr/apr/trunk/file_io/os2: pipe.c readwrite.c
Author: bjh
Date: Tue Apr 6 18:53:22 2010
New Revision: 931271
URL: http://svn.apache.org/viewvc?rev=931271&view=rev
Log:
OS/2: Add support for writing to a non-blocking pipe with time out.
Modified:
apr/apr/trunk/file_io/os2/pipe.c
apr/apr/trunk/file_io/os2/readwrite.c
Modified: apr/apr/trunk/file_io/os2/pipe.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/pipe.c?rev=931271&r1=931270&r2=931271&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/pipe.c (original)
+++ apr/apr/trunk/file_io/os2/pipe.c Tue Apr 6 18:53:22 2010
@@ -89,6 +89,25 @@ APR_DECLARE(apr_status_t) apr_file_pipe_
apr_pool_cleanup_register(pool, *in, apr_file_cleanup, apr_pool_cleanup_null);
(*out) = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t));
+ rc = DosCreateEventSem(NULL, &(*out)->pipeSem, DC_SEM_SHARED, FALSE);
+
+ if (rc) {
+ DosClose(filedes[0]);
+ DosClose(filedes[1]);
+ DosCloseEventSem((*in)->pipeSem);
+ return APR_FROM_OS_ERROR(rc);
+ }
+
+ rc = DosSetNPipeSem(filedes[1], (HSEM)(*out)->pipeSem, 1);
+
+ if (rc) {
+ DosClose(filedes[0]);
+ DosClose(filedes[1]);
+ DosCloseEventSem((*in)->pipeSem);
+ DosCloseEventSem((*out)->pipeSem);
+ return APR_FROM_OS_ERROR(rc);
+ }
+
(*out)->pool = pool;
(*out)->filedes = filedes[1];
(*out)->fname = apr_pstrdup(pool, pipename);
Modified: apr/apr/trunk/file_io/os2/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/readwrite.c?rev=931271&r1=931270&r2=931271&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/readwrite.c (original)
+++ apr/apr/trunk/file_io/os2/readwrite.c Tue Apr 6 18:53:22 2010
@@ -191,6 +191,10 @@ APR_DECLARE(apr_status_t) apr_file_write
file_unlock(thefile);
return rv;
} else {
+ if (thefile->pipe) {
+ DosResetEventSem(thefile->pipeSem, &rc);
+ }
+
if (thefile->flags & APR_FOPEN_APPEND) {
FILELOCK all = { 0, 0x7fffffff };
ULONG newpos;
@@ -207,6 +211,21 @@ APR_DECLARE(apr_status_t) apr_file_write
}
} else {
rc = DosWrite(thefile->filedes, buf, *nbytes, &byteswritten);
+
+ if (thefile->pipe && rc == 0 && *nbytes > 0 && byteswritten == 0) {
+ /* Pipe is full, wait or timeout */
+ int rcwait = DosWaitEventSem(thefile->pipeSem, thefile->timeout >= 0 ? thefile->timeout / 1000 : SEM_INDEFINITE_WAIT);
+
+ if (rcwait == 0) {
+ rc = DosWrite(thefile->filedes, buf, *nbytes, &byteswritten);
+ }
+ else if (rcwait == ERROR_TIMEOUT) {
+ return APR_TIMEUP;
+ }
+ else {
+ rc = rcwait;
+ }
+ }
}
if (rc) {