apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject svn commit: r933338 - in /apr/apr/trunk: ./ file_io/os2/ file_io/unix/ include/ include/private/ network_io/os2/ network_io/unix/ support/os2/ test/
Date Mon, 12 Apr 2010 18:10:49 GMT
Author: bjh
Date: Mon Apr 12 18:10:48 2010
New Revision: 933338

URL: http://svn.apache.org/viewvc?rev=933338&view=rev
Log:
Hide apr_wait_for_io_or_timeout() from public view and add instead
apr_socket_wait() and apr_file_pipe_wait().

Added:
    apr/apr/trunk/include/private/apr_support.h
      - copied unchanged from r931631, apr/apr/trunk/include/apr_support.h
Removed:
    apr/apr/trunk/include/apr_support.h
Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/file_io/os2/pipe.c
    apr/apr/trunk/file_io/os2/readwrite.c
    apr/apr/trunk/file_io/unix/readwrite.c
    apr/apr/trunk/include/apr_file_io.h
    apr/apr/trunk/include/apr_general.h
    apr/apr/trunk/include/apr_network_io.h
    apr/apr/trunk/network_io/os2/sendrecv.c
    apr/apr/trunk/network_io/unix/sendrecv.c
    apr/apr/trunk/support/os2/waitio.c
    apr/apr/trunk/test/testpipe.c
    apr/apr/trunk/test/testsock.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Mon Apr 12 18:10:48 2010
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) Hide apr_wait_for_io_or_timeout() from public view and add instead
+     apr_socket_wait() and apr_file_pipe_wait(). [Brian Havard]
+
   *) Add apr_hash_this_key(), apr_hash_this_key_len(), and 
      apr_hash_this_val() for easier access to those attributes from
      a hash iterator.  [Hyrum K. Wright <hyrum_wright mail.utexas.edu>]

Modified: apr/apr/trunk/file_io/os2/pipe.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/pipe.c?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/pipe.c (original)
+++ apr/apr/trunk/file_io/os2/pipe.c Mon Apr 12 18:10:48 2010
@@ -81,7 +81,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_
     (*in)->fname = apr_pstrdup(pool, pipename);
     (*in)->isopen = TRUE;
     (*in)->buffered = FALSE;
-    (*in)->flags = 0;
+    (*in)->flags = APR_FOPEN_READ;
     (*in)->pipe = 1;
     (*in)->timeout = -1;
     (*in)->blocking = BLK_ON;
@@ -113,7 +113,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_
     (*out)->fname = apr_pstrdup(pool, pipename);
     (*out)->isopen = TRUE;
     (*out)->buffered = FALSE;
-    (*out)->flags = 0;
+    (*out)->flags = APR_FOPEN_WRITE;
     (*out)->pipe = 1;
     (*out)->timeout = -1;
     (*out)->blocking = BLK_ON;

Modified: apr/apr/trunk/file_io/os2/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/readwrite.c?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/readwrite.c (original)
+++ apr/apr/trunk/file_io/os2/readwrite.c Mon Apr 12 18:10:48 2010
@@ -409,6 +409,31 @@ apr_status_t apr_file_check_read(apr_fil
 
 
 
+APR_DECLARE(apr_status_t) apr_file_pipe_wait(apr_file_t *pipe, apr_wait_type_t direction)
+{
+    int rc;
+
+    if (!pipe->pipe) {
+        /* No support for waiting on a regular file */
+        return APR_ENOTIMPL;
+    }
+
+    if (((pipe->flags & APR_FOPEN_READ) > 0) != (direction == APR_WAIT_READ)) {
+        /* Attempt to wait for read from the write end of the pipe or vica versa */
+        return APR_EINVAL;
+    }
+
+    rc = DosWaitEventSem(pipe->pipeSem, pipe->timeout >= 0 ? pipe->timeout /
1000 : SEM_INDEFINITE_WAIT);
+
+    if (rc == ERROR_TIMEOUT) {
+        return APR_TIMEUP;
+    }
+
+    return APR_FROM_OS_ERROR(rc);
+}
+
+
+
 APR_DECLARE(apr_status_t) apr_file_rotating_check(apr_file_t *thefile)
 {
     return APR_ENOTIMPL;

Modified: apr/apr/trunk/file_io/unix/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/readwrite.c?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/readwrite.c (original)
+++ apr/apr/trunk/file_io/unix/readwrite.c Mon Apr 12 18:10:48 2010
@@ -562,3 +562,10 @@ APR_DECLARE(apr_status_t) apr_file_gets(
     }
     return rv;
 }
+
+
+
+APR_DECLARE(apr_status_t) apr_file_pipe_wait(apr_file_t *thepipe, apr_wait_type_t direction)
+{
+    return apr_wait_for_io_or_timeout(thepipe, NULL, direction == APR_WAIT_READ);
+}

Modified: apr/apr/trunk/include/apr_file_io.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_file_io.h?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_file_io.h (original)
+++ apr/apr/trunk/include/apr_file_io.h Mon Apr 12 18:10:48 2010
@@ -569,6 +569,16 @@ APR_DECLARE(apr_status_t) apr_file_gets(
 APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile);
 
 /**
+ * Wait for a pipe to be ready for input or output
+ * @param thepipe the pipe to wait on
+ * @param direction whether to wait for reading or writing to be ready
+ *        Can be either APR_WAIT_READ or APR_WAIT_WRITE
+ * @remark Will time out if thepipe has a time out set for it
+ */
+APR_DECLARE(apr_status_t) apr_file_pipe_wait(apr_file_t *thepipe,
+                                             apr_wait_type_t direction);
+
+/**
  * Flush the file's buffer.
  * @param thefile The file descriptor to flush
  */

Modified: apr/apr/trunk/include/apr_general.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_general.h?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_general.h (original)
+++ apr/apr/trunk/include/apr_general.h Mon Apr 12 18:10:48 2010
@@ -67,6 +67,9 @@ extern "C" {
 /** signal numbers typedef */
 typedef int               apr_signum_t;
 
+/* Type of I/O to wait for */
+typedef enum { APR_WAIT_READ, APR_WAIT_WRITE } apr_wait_type_t;
+
 /**
  * Finding offsets of elements within structures.
  * Taken from the X code... they've sweated portability of this stuff

Modified: apr/apr/trunk/include/apr_network_io.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_network_io.h?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_network_io.h (original)
+++ apr/apr/trunk/include/apr_network_io.h Mon Apr 12 18:10:48 2010
@@ -621,6 +621,16 @@ APR_DECLARE(apr_status_t) apr_socket_rec
                                    char *buf, apr_size_t *len);
 
 /**
+ * Wait for a socket to be ready for input or output
+ * @param sock the socket to wait on
+ * @param direction whether to wait for reading or writing to be ready
+ * @remark Will time out if socket has a time out set for it
+ * @remark direction can be either APR_WAIT_READ or APR_WAIT_WRITE
+ */
+APR_DECLARE(apr_status_t) apr_socket_wait(apr_socket_t *sock, 
+                                          apr_wait_type_t direction);
+
+/**
  * Setup socket options for the specified socket
  * @param sock The socket to set up.
  * @param opt The option we would like to configure.  One of:

Modified: apr/apr/trunk/network_io/os2/sendrecv.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/network_io/os2/sendrecv.c?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/network_io/os2/sendrecv.c (original)
+++ apr/apr/trunk/network_io/os2/sendrecv.c Mon Apr 12 18:10:48 2010
@@ -153,3 +153,21 @@ APR_DECLARE(apr_status_t) apr_socket_sen
     *len = rv;
     return APR_SUCCESS;
 }
+
+
+
+APR_DECLARE(apr_status_t) apr_socket_wait(apr_socket_t *sock, apr_wait_type_t direction)
+{
+    int pollsocket = sock->socketdes;
+    int wait_rc = select(&pollsocket, direction == APR_WAIT_READ, 
+                         direction == APR_WAIT_WRITE, 0, sock->timeout / 1000);
+
+    if (wait_rc == 0) {
+        return APR_TIMEUP;
+    }
+    else if (wait_rc < 0) {
+        return APR_FROM_OS_ERROR(sock_errno());
+    }
+
+    return APR_SUCCESS;
+}

Modified: apr/apr/trunk/network_io/unix/sendrecv.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sendrecv.c?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/network_io/unix/sendrecv.c (original)
+++ apr/apr/trunk/network_io/unix/sendrecv.c Mon Apr 12 18:10:48 2010
@@ -235,6 +235,11 @@ do_select:
 #endif
 }
 
+apr_status_t apr_socket_wait(apr_socket_t *sock, apr_wait_type_t direction)
+{
+    return apr_wait_for_io_or_timeout(NULL, sock, direction == APR_WAIT_READ);
+}
+
 #if APR_HAS_SENDFILE
 
 /* TODO: Verify that all platforms handle the fd the same way,

Modified: apr/apr/trunk/support/os2/waitio.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/support/os2/waitio.c?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/support/os2/waitio.c (original)
+++ apr/apr/trunk/support/os2/waitio.c Mon Apr 12 18:10:48 2010
@@ -19,51 +19,14 @@
 #include "apr_errno.h"
 #include "apr_support.h"
 
-static apr_status_t wait_for_file(apr_file_t *f, int for_read)
-{
-    int rc;
-
-    if (!f->pipe) {
-        /* No support for waiting on a regular file */
-        return APR_ENOTIMPL;
-    }
-
-    rc = DosWaitEventSem(f->pipeSem, f->timeout >= 0 ? f->timeout / 1000 : SEM_INDEFINITE_WAIT);
-
-    if (rc == ERROR_TIMEOUT) {
-        return APR_TIMEUP;
-    }
-
-    return APR_FROM_OS_ERROR(rc);
-}
-
-
-
-static apr_status_t wait_for_socket(apr_socket_t *s, int for_read)
-{
-    int pollsocket = s->socketdes;
-    int wait_rc = select(&pollsocket, for_read != 0, for_read == 0, 0, s->timeout
/ 1000);
-
-    if (wait_rc == 0) {
-        return APR_TIMEUP;
-    }
-    else if (wait_rc < 0) {
-        return APR_FROM_OS_ERROR(sock_errno());
-    }
-
-    return APR_SUCCESS;
-}
-
-
-
 apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
                                         int for_read)
 {
     if (f) {
-        return wait_for_file(f, for_read);
+        return apr_file_pipe_wait(f, for_read ? APR_WAIT_READ : APR_WAIT_WRITE);
     }
     else if (s) {
-        return wait_for_socket(s, for_read);
+        return apr_socket_wait(s, for_read ? APR_WAIT_READ : APR_WAIT_WRITE);
     }
 
     /* Didn't specify a file or socket */

Modified: apr/apr/trunk/test/testpipe.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testpipe.c?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/test/testpipe.c (original)
+++ apr/apr/trunk/test/testpipe.c Mon Apr 12 18:10:48 2010
@@ -186,6 +186,35 @@ static void test_pipe_writefull(abts_cas
     ABTS_ASSERT(tc, "child terminated normally", why == APR_PROC_EXIT);
 }
 
+static void wait_pipe(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    apr_interval_time_t delay = 200000;
+    apr_time_t start_time;
+    apr_time_t end_time;
+    apr_size_t nbytes;
+
+    rv = apr_file_pipe_create(&readp, &writep, p);
+    APR_ASSERT_SUCCESS(tc, "Couldn't create pipe", rv);
+
+    rv = apr_file_pipe_timeout_set(readp, delay);
+    APR_ASSERT_SUCCESS(tc, "Couldn't set pipe timeout", rv);
+
+    start_time = apr_time_now();
+    rv = apr_file_pipe_wait(readp, APR_WAIT_READ);
+    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
+
+    end_time = apr_time_now();
+    ABTS_ASSERT(tc, "apr_file_pipe_wait() waited for the time out", end_time - start_time
>= delay);
+
+    nbytes = 4;
+    rv = apr_file_write(writep, "data", &nbytes);
+    APR_ASSERT_SUCCESS(tc, "Couldn't write to pipe", rv);
+
+    rv = apr_file_pipe_wait(readp, APR_WAIT_READ);
+    APR_ASSERT_SUCCESS(tc, "Wait for pipe failed", rv);
+}
+
 abts_suite *testpipe(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -199,6 +228,7 @@ abts_suite *testpipe(abts_suite *suite)
     abts_run_test(suite, read_write_notimeout, NULL);
     abts_run_test(suite, test_pipe_writefull, NULL);
     abts_run_test(suite, close_pipe, NULL);
+    abts_run_test(suite, wait_pipe, NULL);
 
     return suite;
 }

Modified: apr/apr/trunk/test/testsock.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testsock.c?rev=933338&r1=933337&r2=933338&view=diff
==============================================================================
--- apr/apr/trunk/test/testsock.c (original)
+++ apr/apr/trunk/test/testsock.c Mon Apr 12 18:10:48 2010
@@ -403,6 +403,64 @@ static void test_get_addr(abts_case *tc,
     apr_socket_close(ld);
 }
 
+static void test_wait(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    apr_socket_t *server;
+    apr_socket_t *server_connection;
+    apr_sockaddr_t *server_addr;
+    apr_socket_t *client;
+    apr_interval_time_t delay = 200000;
+    apr_time_t start_time;
+    apr_time_t end_time;
+    apr_size_t nbytes;
+    int connected = FALSE;
+
+    server = setup_socket(tc);
+    rv = apr_sockaddr_info_get(&server_addr, socket_name, socket_type, 8021, 0, p);
+    APR_ASSERT_SUCCESS(tc, "setting up sockaddr", rv);
+
+    rv = apr_socket_create(&client, server_addr->family, SOCK_STREAM, 0, p);
+    APR_ASSERT_SUCCESS(tc, "creating client socket", rv);
+
+    rv = apr_socket_timeout_set(client, 0);
+    APR_ASSERT_SUCCESS(tc, "setting client socket timeout", rv);
+
+    rv = apr_socket_connect(client, server_addr);
+
+    if (rv == APR_SUCCESS) {
+        connected = TRUE;
+    }
+    else {
+        ABTS_ASSERT(tc, "connecting client to server", APR_STATUS_IS_EINPROGRESS(rv));
+    }
+
+    rv = apr_socket_accept(&server_connection, server, p);
+    APR_ASSERT_SUCCESS(tc, "accepting client connection", rv);
+
+    if (!connected) {
+        rv = apr_socket_connect(client, server_addr);
+        APR_ASSERT_SUCCESS(tc, "connecting client to server", rv);
+    }
+
+    rv = apr_socket_timeout_set(client, delay);
+    APR_ASSERT_SUCCESS(tc, "setting client socket timeout", rv);
+
+    start_time = apr_time_now();
+    rv = apr_socket_wait(client, APR_WAIT_READ);
+    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
+
+    end_time = apr_time_now();
+    ABTS_ASSERT(tc, "apr_socket_wait() waited for the time out", end_time - start_time >=
delay);
+
+    nbytes = 4;
+    rv = apr_socket_send(server_connection, "data", &nbytes);
+    APR_ASSERT_SUCCESS(tc, "Couldn't write to client", rv);
+
+    rv = apr_socket_wait(client, APR_WAIT_READ);
+    APR_ASSERT_SUCCESS(tc, "Wait for socket failed", rv);
+}
+
 abts_suite *testsock(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -416,6 +474,7 @@ abts_suite *testsock(abts_suite *suite)
     abts_run_test(suite, test_timeout, NULL);
     abts_run_test(suite, test_print_addr, NULL);
     abts_run_test(suite, test_get_addr, NULL);
+    abts_run_test(suite, test_wait, NULL);
 #if APR_HAVE_SOCKADDR_UN
     socket_name = UNIX_SOCKET_NAME;
     socket_type = APR_UNIX;
@@ -423,6 +482,7 @@ abts_suite *testsock(abts_suite *suite)
     abts_run_test(suite, test_send, NULL);
     abts_run_test(suite, test_recv, NULL);
     abts_run_test(suite, test_timeout, NULL);
+    abts_run_test(suite, test_wait, NULL);
 #endif
     return suite;
 }



Mime
View raw message