summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormturk <mturk@13f79535-47bb-0310-9956-ffa450edef68>2021-11-19 18:09:55 +0000
committermturk <mturk@13f79535-47bb-0310-9956-ffa450edef68>2021-11-19 18:09:55 +0000
commit3a2ba9ca4f6f2f488e05e38a6b21c12203a3b191 (patch)
treef06803725ed9f4bdbe08ed0e54d0d8ce70dc09ee
parenteba6dd842f850a4c17e72388f1fcfee75fc95133 (diff)
downloadlibapr-3a2ba9ca4f6f2f488e05e38a6b21c12203a3b191.tar.gz
Use enum instead multiple booleans
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1895181 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--file_io/win32/pipe.c14
-rw-r--r--file_io/win32/readwrite.c15
-rw-r--r--include/arch/win32/apr_arch_file_io.h8
3 files changed, 20 insertions, 17 deletions
diff --git a/file_io/win32/pipe.c b/file_io/win32/pipe.c
index 18f6d4a97..16bb58665 100644
--- a/file_io/win32/pipe.c
+++ b/file_io/win32/pipe.c
@@ -43,7 +43,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe,
thepipe->timeout = timeout;
return APR_SUCCESS;
}
- if (!thepipe->pipe) {
+ if (thepipe->ftype != APR_FILETYPE_PIPE) {
return APR_ENOTIMPL;
}
if (timeout && !(thepipe->pOverlapped)) {
@@ -92,7 +92,7 @@ static apr_status_t file_pipe_create(apr_file_t **in,
(*in) = (apr_file_t *)apr_pcalloc(pool_in, sizeof(apr_file_t));
(*in)->pool = pool_in;
(*in)->fname = NULL;
- (*in)->pipe = 1;
+ (*in)->ftype = APR_FILETYPE_PIPE;
(*in)->timeout = -1;
(*in)->ungetchar = -1;
(*in)->eof_hit = 0;
@@ -107,7 +107,7 @@ static apr_status_t file_pipe_create(apr_file_t **in,
(*out) = (apr_file_t *)apr_pcalloc(pool_out, sizeof(apr_file_t));
(*out)->pool = pool_out;
(*out)->fname = NULL;
- (*out)->pipe = 1;
+ (*out)->ftype = APR_FILETYPE_PIPE;
(*out)->timeout = -1;
(*out)->ungetchar = -1;
(*out)->eof_hit = 0;
@@ -264,7 +264,7 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
{
(*file) = apr_pcalloc(pool, sizeof(apr_file_t));
(*file)->pool = pool;
- (*file)->pipe = 1;
+ (*file)->ftype = APR_FILETYPE_PIPE;
(*file)->timeout = -1;
(*file)->ungetchar = -1;
(*file)->filehand = *thefile;
@@ -446,7 +446,7 @@ apr_status_t apr_file_socket_pipe_create(apr_file_t **in,
(*in) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
(*in)->pool = p;
(*in)->fname = NULL;
- (*in)->socket = 1;
+ (*in)->ftype = APR_FILETYPE_SOCKET;
(*in)->timeout = 0; /* read end of the pipe is non-blocking */
(*in)->ungetchar = -1;
(*in)->eof_hit = 0;
@@ -460,7 +460,7 @@ apr_status_t apr_file_socket_pipe_create(apr_file_t **in,
(*out) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
(*out)->pool = p;
(*out)->fname = NULL;
- (*out)->socket = 1;
+ (*out)->ftype = APR_FILETYPE_SOCKET;
(*out)->timeout = -1;
(*out)->ungetchar = -1;
(*out)->eof_hit = 0;
@@ -482,7 +482,7 @@ apr_status_t apr_file_socket_pipe_create(apr_file_t **in,
apr_status_t apr_file_socket_pipe_close(apr_file_t *file)
{
apr_status_t stat;
- if (!file->socket)
+ if (file->ftype != APR_FILETYPE_SOCKET)
return apr_file_close(file);
if ((stat = socket_pipe_cleanup(file)) == APR_SUCCESS) {
apr_pool_cleanup_kill(file->pool, file, socket_pipe_cleanup);
diff --git a/file_io/win32/readwrite.c b/file_io/win32/readwrite.c
index 8b92213af..10c86ae01 100644
--- a/file_io/win32/readwrite.c
+++ b/file_io/win32/readwrite.c
@@ -33,7 +33,6 @@
static apr_status_t read_with_timeout(apr_file_t *file, void *buf, apr_size_t len_in, apr_size_t *nbytes)
{
apr_status_t rv;
- int pipe_or_socket = (file->pipe || file->socket);
DWORD len = (DWORD)len_in;
DWORD bytesread = 0;
@@ -42,7 +41,7 @@ static apr_status_t read_with_timeout(apr_file_t *file, void *buf, apr_size_t le
/* Peek at the pipe. If there is no data available, return APR_EAGAIN.
* If data is available, go ahead and read it.
*/
- if (file->pipe) {
+ if (file->ftype == APR_FILETYPE_PIPE) {
DWORD bytes;
if (!PeekNamedPipe(file->filehand, NULL, 0, NULL, &bytes, NULL)) {
rv = apr_get_os_error();
@@ -70,12 +69,12 @@ static apr_status_t read_with_timeout(apr_file_t *file, void *buf, apr_size_t le
}
}
- if (file->pOverlapped && !pipe_or_socket) {
+ if (file->pOverlapped && file->ftype == APR_FILETYPE_FILE) {
file->pOverlapped->Offset = (DWORD)file->filePtr;
file->pOverlapped->OffsetHigh = (DWORD)(file->filePtr >> 32);
}
- if (file->socket && !file->pOverlapped) {
+ if (file->ftype == APR_FILETYPE_SOCKET) {
WSABUF wsaData;
DWORD flags = 0;
@@ -428,7 +427,7 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a
apr_thread_mutex_unlock(thefile->mutex);
}
}
- else if (thefile->socket && !thefile->pOverlapped) {
+ else if (thefile->ftype == APR_FILETYPE_SOCKET) {
WSABUF wsaData;
DWORD flags = 0;
@@ -445,9 +444,7 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a
*nbytes = bwrote;
}
else {
- int pipe_or_socket = (thefile->pipe || thefile->socket);
-
- if (pipe_or_socket) {
+ if (thefile->ftype != APR_FILETYPE_FILE) {
rv = WriteFile(thefile->filehand, buf, (DWORD)*nbytes, &bwrote,
thefile->pOverlapped);
}
@@ -581,7 +578,7 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a
}
}
}
- if (rv == APR_SUCCESS && thefile->pOverlapped && !pipe_or_socket) {
+ if (rv == APR_SUCCESS && thefile->pOverlapped && thefile->ftype == APR_FILETYPE_FILE) {
thefile->filePtr += *nbytes;
}
}
diff --git a/include/arch/win32/apr_arch_file_io.h b/include/arch/win32/apr_arch_file_io.h
index 6b94c94e9..f3ca4feeb 100644
--- a/include/arch/win32/apr_arch_file_io.h
+++ b/include/arch/win32/apr_arch_file_io.h
@@ -159,10 +159,16 @@ apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile,
/* for apr_poll.c */
#define filedes filehand
+typedef enum {
+ APR_FILETYPE_FILE = 0,
+ APR_FILETYPE_PIPE,
+ APR_FILETYPE_SOCKET
+} apr_filetype_e;
+
struct apr_file_t {
apr_pool_t *pool;
HANDLE filehand;
- BOOLEAN pipe, socket; /* Is this a pipe, a socket or a file? */
+ apr_filetype_e ftype; /* Is this a pipe, a socket or a file? */
OVERLAPPED *pOverlapped;
apr_interval_time_t timeout;
apr_int32_t flags;