diff options
author | bjh <bjh@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-06 18:53:22 +0000 |
---|---|---|
committer | bjh <bjh@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-06 18:53:22 +0000 |
commit | 2797b228335a30e2ea93cba16083660105d03078 (patch) | |
tree | 3a10326564347a8755bb62045a5f037d08f4e0a8 /file_io/os2 | |
parent | 6192e5139465bb2f545fd3e48ded4aad0c604284 (diff) | |
download | libapr-2797b228335a30e2ea93cba16083660105d03078.tar.gz |
OS/2: Add support for writing to a non-blocking pipe with time out.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@931271 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/os2')
-rw-r--r-- | file_io/os2/pipe.c | 19 | ||||
-rw-r--r-- | file_io/os2/readwrite.c | 19 |
2 files changed, 38 insertions, 0 deletions
diff --git a/file_io/os2/pipe.c b/file_io/os2/pipe.c index c6aae5c7e..4715cf44e 100644 --- a/file_io/os2/pipe.c +++ b/file_io/os2/pipe.c @@ -89,6 +89,25 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out 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); diff --git a/file_io/os2/readwrite.c b/file_io/os2/readwrite.c index f460a91e5..381c26b62 100644 --- a/file_io/os2/readwrite.c +++ b/file_io/os2/readwrite.c @@ -191,6 +191,10 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a 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(apr_file_t *thefile, const void *buf, a } } 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) { |