Skip to content

Commit

Permalink
With the removal of apr_poll(), the apr_wait_for_io_or_timeout() func…
Browse files Browse the repository at this point in the history
…tion

needed to be rebuilt. Specifically, it needs a pollset, but we don't want
to allocate that all the time. Thus, we need to create it once at socket
or file creation time, and then reuse that pollset.

NOTE: this makes the library compile, but some of the test programs may
not. I have also not verified this work yet (in favor of just getting it
to at least compile...)

For the apr_arch_*.h files, I added a pollset member to the file and
socket structures.

For the various open/dup/etc functions, I added the creation of that
pollset whenever a file or socket is created.
(I may have missed some and will verify further)

For the socket create and sendrecv function, I added the creation of the
pollset.
(again, may have missed some, but if everybody uses alloc_socket, then we
 should be okay)

* support/unix/waitio.c: rebuild in terms of the pollset


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64759 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
gstein committed Nov 17, 2003
1 parent 7a4b6a8 commit ca9b3cf
Show file tree
Hide file tree
Showing 22 changed files with 141 additions and 20 deletions.
9 changes: 9 additions & 0 deletions file_io/os2/filedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ static apr_status_t file_dup(apr_file_t **new_file, apr_file_t *old_file, apr_po
*new_file = dup_file;
}

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new)->pollset, 1, p, 0);

return APR_SUCCESS;
}

Expand Down Expand Up @@ -158,5 +162,10 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
old_file->filedes = -1;
apr_pool_cleanup_kill(old_file->pool, (void *)old_file,
apr_file_cleanup);

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new)->pollset, 1, p, 0);

return APR_SUCCESS;
}
9 changes: 9 additions & 0 deletions file_io/os2/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr
dafile->direction = 0;
dafile->pipe = FALSE;

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&dafile->pollset, 1, cont, 0);

if (!(flag & APR_FILE_NOCLEANUP)) {
apr_pool_cleanup_register(dafile->pool, dafile, apr_file_cleanup, apr_file_cleanup);
}
Expand Down Expand Up @@ -239,6 +243,11 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thef
if (rv)
return rv;
}

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new)->pollset, 1, cont, 0);

return APR_SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions file_io/os2/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
(*in)->pipe = 1;
(*in)->timeout = -1;
(*in)->blocking = BLK_ON;
(void) apr_pollset_create(&(*in)->pollset, 1, pool, 0);
apr_pool_cleanup_register(pool, *in, apr_file_cleanup, apr_pool_cleanup_null);

(*out) = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t));
Expand All @@ -135,6 +136,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
(*out)->pipe = 1;
(*out)->timeout = -1;
(*out)->blocking = BLK_ON;
(void) apr_pollset_create(&(*out)->pollset, 1, pool, 0);
apr_pool_cleanup_register(pool, *out, apr_file_cleanup, apr_pool_cleanup_null);

return APR_SUCCESS;
Expand Down Expand Up @@ -196,6 +198,7 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
(*file)->blocking = BLK_UNKNOWN; /* app needs to make a timeout call */
(*file)->timeout = -1;
(*file)->filedes = *thefile;
(void) apr_pollset_create(&(*file)->pollset, 1, pool, 0);

if (register_cleanup) {
apr_pool_cleanup_register(pool, *file, apr_file_cleanup,
Expand Down
9 changes: 9 additions & 0 deletions file_io/unix/filedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ static apr_status_t _file_dup(apr_file_t **new_file,
apr_unix_file_cleanup,
apr_unix_file_cleanup);

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0);

return APR_SUCCESS;
}

Expand Down Expand Up @@ -183,5 +187,10 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
old_file->filedes = -1;
apr_pool_cleanup_kill(old_file->pool, (void *)old_file,
apr_unix_file_cleanup);

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0);

return APR_SUCCESS;
}
4 changes: 4 additions & 0 deletions file_io/unix/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new,
(*new)->dataRead = 0;
(*new)->direction = 0;

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new)->pollset, 1, pool, 0);

if (!(flag & APR_FILE_NOCLEANUP)) {
apr_pool_cleanup_register((*new)->pool, (void *)(*new),
apr_unix_file_cleanup,
Expand Down
6 changes: 6 additions & 0 deletions file_io/unix/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
apr_unix_file_cleanup,
apr_pool_cleanup_null);
}

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*file)->pollset, 1, pool, 0);
return APR_SUCCESS;
}

Expand Down Expand Up @@ -229,6 +233,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
#if APR_HAS_THREADS
(*in)->thlock = NULL;
#endif
(void) apr_pollset_create(&(*in)->pollset, 1, pool, 0);

(*out) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
(*out)->pool = pool;
Expand All @@ -242,6 +247,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
#if APR_HAS_THREADS
(*out)->thlock = NULL;
#endif
(void) apr_pollset_create(&(*out)->pollset, 1, pool, 0);

apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup,
apr_pool_cleanup_null);
Expand Down
9 changes: 9 additions & 0 deletions file_io/win32/filedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file,
apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file), file_cleanup,
apr_pool_cleanup_null);

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0);

return APR_SUCCESS;
#endif /* !defined(_WIN32_WCE) */
}
Expand Down Expand Up @@ -190,5 +194,10 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
old_file->filehand = INVALID_HANDLE_VALUE;
apr_pool_cleanup_kill(old_file->pool, (void *)old_file,
file_cleanup);

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0);

return APR_SUCCESS;
}
8 changes: 8 additions & 0 deletions file_io/win32/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname,
}
}

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new)->pollset, 1, cont, 0);

if (!(flag & APR_FILE_NOCLEANUP)) {
apr_pool_cleanup_register((*new)->pool, (void *)(*new), file_cleanup,
apr_pool_cleanup_null);
Expand Down Expand Up @@ -575,6 +579,10 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file,
}
}

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*file)->pollset, 1, pool, 0);

/* XXX... we pcalloc above so all others are zeroed.
* Should we be testing if thefile is a handle to
* a PIPE and set up the mechanics appropriately?
Expand Down
2 changes: 2 additions & 0 deletions file_io/win32/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ apr_status_t apr_create_nt_pipe(apr_file_t **in, apr_file_t **out,
(*in)->dataRead = 0;
(*in)->direction = 0;
(*in)->pOverlapped = NULL;
(void) apr_pollset_create(&(*in)->pollset, 1, p, 0);

(*out) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
(*out)->pool = p;
Expand All @@ -161,6 +162,7 @@ apr_status_t apr_create_nt_pipe(apr_file_t **in, apr_file_t **out,
(*out)->dataRead = 0;
(*out)->direction = 0;
(*out)->pOverlapped = NULL;
(void) apr_pollset_create(&(*out)->pollset, 1, p, 0);

if (apr_os_level >= APR_WIN_NT) {
/* Create the read end of the pipe */
Expand Down
2 changes: 2 additions & 0 deletions include/apr_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ extern "C" {

/**
* Wait for IO to occur or timeout.
*
* Uses POOL for temporary allocations.
*/
apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
int for_read);
Expand Down
4 changes: 4 additions & 0 deletions include/arch/netware/apr_arch_file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "apr_file_info.h"
#include "apr_errno.h"
#include "apr_lib.h"
#include "apr_poll.h"

/* System headers the file I/O library needs */
#if APR_HAVE_FCNTL_H
Expand Down Expand Up @@ -120,6 +121,9 @@ struct apr_file_t {
enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking;
int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/

/* if there is a timeout set, then this pollset is used */
apr_pollset_t *pollset;

/* Stuff for buffered mode */
char *buffer;
int bufpos; /* Read/Write position in buffer */
Expand Down
4 changes: 4 additions & 0 deletions include/arch/os2/apr_arch_file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "apr_file_io.h"
#include "apr_file_info.h"
#include "apr_errno.h"
#include "apr_poll.h"

/* We have an implementation of mkstemp but it's not very multi-threading
* friendly & is part of the POSIX emulation rather than native so don't
Expand All @@ -83,6 +84,9 @@ struct apr_file_t {
HEV pipeSem;
enum { BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking;

/* if there is a timeout set, then this pollset is used */
apr_pollset_t *pollset;

/* Stuff for buffered mode */
char *buffer;
int bufpos; // Read/Write position in buffer
Expand Down
5 changes: 5 additions & 0 deletions include/arch/os2/apr_arch_networkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#include "apr_network_io.h"
#include "apr_general.h"
#include "apr_arch_os2calls.h"
#include "apr_poll.h"

#if APR_HAVE_NETDB_H
#include <netdb.h>
#endif
Expand All @@ -85,6 +87,9 @@ struct apr_socket_t {
apr_int32_t options;
apr_int32_t inherit;
sock_userdata_t *userdata;

/* if there is a timeout set, then this pollset is used */
apr_pollset_t *pollset;
};

/* Error codes returned from sock_errno() */
Expand Down
4 changes: 4 additions & 0 deletions include/arch/unix/apr_arch_file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "apr_errno.h"
#include "apr_lib.h"
#include "apr_thread_mutex.h"
#include "apr_poll.h"

/* System headers the file I/O library needs */
#if APR_HAVE_FCNTL_H
Expand Down Expand Up @@ -131,6 +132,9 @@ struct apr_file_t {
enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking;
int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/

/* if there is a timeout set, then this pollset is used */
apr_pollset_t *pollset;

/* Stuff for buffered mode */
char *buffer;
int bufpos; /* Read/Write position in buffer */
Expand Down
4 changes: 4 additions & 0 deletions include/arch/unix/apr_arch_networkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "apr_errno.h"
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_poll.h"

/* System headers the network I/O library needs */
#if APR_HAVE_SYS_TYPES_H
Expand Down Expand Up @@ -152,6 +153,9 @@ struct apr_socket_t {
apr_int32_t options;
apr_int32_t inherit;
sock_userdata_t *userdata;

/* if there is a timeout set, then this pollset is used */
apr_pollset_t *pollset;
};

const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size);
Expand Down
4 changes: 4 additions & 0 deletions include/arch/win32/apr_arch_file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "apr_file_info.h"
#include "apr_errno.h"
#include "apr_arch_misc.h"
#include "apr_poll.h"

#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
Expand Down Expand Up @@ -215,6 +216,9 @@ struct apr_file_t {
apr_off_t filePtr; // position in file of handle
apr_thread_mutex_t *mutex; // mutex semaphore, must be owned to access the above fields

/* if there is a timeout set, then this pollset is used */
apr_pollset_t *pollset;

/* Pipe specific info */
};

Expand Down
4 changes: 4 additions & 0 deletions include/arch/win32/apr_arch_networkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

#include "apr_network_io.h"
#include "apr_general.h"
#include "apr_poll.h"

typedef struct sock_userdata_t sock_userdata_t;
struct sock_userdata_t {
Expand All @@ -81,6 +82,9 @@ struct apr_socket_t {
apr_int32_t options;
apr_int32_t inherit;
sock_userdata_t *userdata;

/* if there is a timeout set, then this pollset is used */
apr_pollset_t *pollset;
};

#ifdef _WIN32_WCE
Expand Down
10 changes: 5 additions & 5 deletions network_io/beos/sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include "apr_arch_networkio.h"
#include "apr_time.h"

apr_status_t apr_wait_for_io_or_timeout(apr_socket_t *sock, int for_read)
static apr_status_t wait_for_io_or_timeout(apr_socket_t *sock, int for_read)
{
struct timeval tv, *tvptr;
fd_set fdset;
Expand Down Expand Up @@ -139,7 +139,7 @@ APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock, char *buf,
} while (rv == -1 && errno == EINTR);

if (rv == -1 && errno == EWOULDBLOCK && sock->timeout > 0) {
apr_status_t arv = apr_wait_for_io_or_timeout(sock, 1);
apr_status_t arv = wait_for_io_or_timeout(sock, 1);
if (arv != APR_SUCCESS) {
*len = 0;
return arv;
Expand Down Expand Up @@ -185,7 +185,7 @@ APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock,

if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)
&& sock->timeout != 0) {
apr_status_t arv = apr_wait_for_io_or_timeout(sock, 0);
apr_status_t arv = wait_for_io_or_timeout(sock, 0);
if (arv != APR_SUCCESS) {
*len = 0;
return arv;
Expand Down Expand Up @@ -226,7 +226,7 @@ APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from,

if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
sock->timeout != 0) {
apr_status_t arv = apr_wait_for_io_or_timeout(sock, 1);
apr_status_t arv = wait_for_io_or_timeout(sock, 1);
if (arv != APR_SUCCESS) {
*len = 0;
return arv;
Expand All @@ -249,4 +249,4 @@ APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from,
return APR_SUCCESS;
}

#endif
#endif /* ! BEOS_BONE */
6 changes: 6 additions & 0 deletions network_io/os2/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
(*new)->remote_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt,
sizeof(apr_sockaddr_t));
(*new)->remote_addr->pool = p;

/* Create a pollset with room for one descriptor. */
/* ### check return codes */
(void) apr_pollset_create(&(*new)->pollset, 1, p, 0);
}

APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock, int *protocol)
Expand All @@ -115,6 +119,7 @@ APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new, int family, int
int protocol, apr_pool_t *cont)
{
int downgrade = (family == AF_UNSPEC);
apr_pollfd_t pfd;

if (family == AF_UNSPEC) {
#if APR_HAVE_IPV6
Expand Down Expand Up @@ -143,6 +148,7 @@ APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new, int family, int
(*new)->nonblock = FALSE;
apr_pool_cleanup_register((*new)->cntxt, (void *)(*new),
socket_cleanup, apr_pool_cleanup_null);

return APR_SUCCESS;
}

Expand Down
Loading

0 comments on commit ca9b3cf

Please sign in to comment.