Skip to content

Commit 3ae1c24

Browse files
author
Brian Havard
committed
Hide apr_wait_for_io_or_timeout() from public view and add instead
apr_socket_wait() and apr_file_pipe_wait(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@933338 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2477f7e commit 3ae1c24

File tree

13 files changed

+175
-41
lines changed

13 files changed

+175
-41
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-*- coding: utf-8 -*-
22
Changes for APR 2.0.0
33

4+
*) Hide apr_wait_for_io_or_timeout() from public view and add instead
5+
apr_socket_wait() and apr_file_pipe_wait(). [Brian Havard]
6+
47
*) Add apr_hash_this_key(), apr_hash_this_key_len(), and
58
apr_hash_this_val() for easier access to those attributes from
69
a hash iterator. [Hyrum K. Wright <hyrum_wright mail.utexas.edu>]

file_io/os2/pipe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
8181
(*in)->fname = apr_pstrdup(pool, pipename);
8282
(*in)->isopen = TRUE;
8383
(*in)->buffered = FALSE;
84-
(*in)->flags = 0;
84+
(*in)->flags = APR_FOPEN_READ;
8585
(*in)->pipe = 1;
8686
(*in)->timeout = -1;
8787
(*in)->blocking = BLK_ON;
@@ -113,7 +113,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
113113
(*out)->fname = apr_pstrdup(pool, pipename);
114114
(*out)->isopen = TRUE;
115115
(*out)->buffered = FALSE;
116-
(*out)->flags = 0;
116+
(*out)->flags = APR_FOPEN_WRITE;
117117
(*out)->pipe = 1;
118118
(*out)->timeout = -1;
119119
(*out)->blocking = BLK_ON;

file_io/os2/readwrite.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,31 @@ apr_status_t apr_file_check_read(apr_file_t *fd)
409409

410410

411411

412+
APR_DECLARE(apr_status_t) apr_file_pipe_wait(apr_file_t *pipe, apr_wait_type_t direction)
413+
{
414+
int rc;
415+
416+
if (!pipe->pipe) {
417+
/* No support for waiting on a regular file */
418+
return APR_ENOTIMPL;
419+
}
420+
421+
if (((pipe->flags & APR_FOPEN_READ) > 0) != (direction == APR_WAIT_READ)) {
422+
/* Attempt to wait for read from the write end of the pipe or vica versa */
423+
return APR_EINVAL;
424+
}
425+
426+
rc = DosWaitEventSem(pipe->pipeSem, pipe->timeout >= 0 ? pipe->timeout / 1000 : SEM_INDEFINITE_WAIT);
427+
428+
if (rc == ERROR_TIMEOUT) {
429+
return APR_TIMEUP;
430+
}
431+
432+
return APR_FROM_OS_ERROR(rc);
433+
}
434+
435+
436+
412437
APR_DECLARE(apr_status_t) apr_file_rotating_check(apr_file_t *thefile)
413438
{
414439
return APR_ENOTIMPL;

file_io/unix/readwrite.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,10 @@ APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
562562
}
563563
return rv;
564564
}
565+
566+
567+
568+
APR_DECLARE(apr_status_t) apr_file_pipe_wait(apr_file_t *thepipe, apr_wait_type_t direction)
569+
{
570+
return apr_wait_for_io_or_timeout(thepipe, NULL, direction == APR_WAIT_READ);
571+
}

include/apr_file_io.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,16 @@ APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len,
568568
*/
569569
APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile);
570570

571+
/**
572+
* Wait for a pipe to be ready for input or output
573+
* @param thepipe the pipe to wait on
574+
* @param direction whether to wait for reading or writing to be ready
575+
* Can be either APR_WAIT_READ or APR_WAIT_WRITE
576+
* @remark Will time out if thepipe has a time out set for it
577+
*/
578+
APR_DECLARE(apr_status_t) apr_file_pipe_wait(apr_file_t *thepipe,
579+
apr_wait_type_t direction);
580+
571581
/**
572582
* Flush the file's buffer.
573583
* @param thefile The file descriptor to flush

include/apr_general.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ extern "C" {
6767
/** signal numbers typedef */
6868
typedef int apr_signum_t;
6969

70+
/* Type of I/O to wait for */
71+
typedef enum { APR_WAIT_READ, APR_WAIT_WRITE } apr_wait_type_t;
72+
7073
/**
7174
* Finding offsets of elements within structures.
7275
* Taken from the X code... they've sweated portability of this stuff

include/apr_network_io.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,16 @@ APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock,
620620
APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock,
621621
char *buf, apr_size_t *len);
622622

623+
/**
624+
* Wait for a socket to be ready for input or output
625+
* @param sock the socket to wait on
626+
* @param direction whether to wait for reading or writing to be ready
627+
* @remark Will time out if socket has a time out set for it
628+
* @remark direction can be either APR_WAIT_READ or APR_WAIT_WRITE
629+
*/
630+
APR_DECLARE(apr_status_t) apr_socket_wait(apr_socket_t *sock,
631+
apr_wait_type_t direction);
632+
623633
/**
624634
* Setup socket options for the specified socket
625635
* @param sock The socket to set up.

network_io/os2/sendrecv.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,21 @@ APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t *sock,
153153
*len = rv;
154154
return APR_SUCCESS;
155155
}
156+
157+
158+
159+
APR_DECLARE(apr_status_t) apr_socket_wait(apr_socket_t *sock, apr_wait_type_t direction)
160+
{
161+
int pollsocket = sock->socketdes;
162+
int wait_rc = select(&pollsocket, direction == APR_WAIT_READ,
163+
direction == APR_WAIT_WRITE, 0, sock->timeout / 1000);
164+
165+
if (wait_rc == 0) {
166+
return APR_TIMEUP;
167+
}
168+
else if (wait_rc < 0) {
169+
return APR_FROM_OS_ERROR(sock_errno());
170+
}
171+
172+
return APR_SUCCESS;
173+
}

network_io/unix/sendrecv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ apr_status_t apr_socket_sendv(apr_socket_t * sock, const struct iovec *vec,
235235
#endif
236236
}
237237

238+
apr_status_t apr_socket_wait(apr_socket_t *sock, apr_wait_type_t direction)
239+
{
240+
return apr_wait_for_io_or_timeout(NULL, sock, direction == APR_WAIT_READ);
241+
}
242+
238243
#if APR_HAS_SENDFILE
239244

240245
/* TODO: Verify that all platforms handle the fd the same way,

0 commit comments

Comments
 (0)