apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject svn commit: r416667 - in /apr/apr-util/trunk: include/apr_ssl.h include/private/apr_ssl_private.h ssl/apr_ssl_socket.c test/testssl.c
Date Fri, 23 Jun 2006 10:43:08 GMT
Author: dreid
Date: Fri Jun 23 03:43:03 2006
New Revision: 416667

URL: http://svn.apache.org/viewvc?rev=416667&view=rev
Log:
Add basis of pollset support.

This basically just allows us to pass ssl sockets to a pollset, which is
possible as they are essentially just apr_socket with an additional layer.
Hopefully this apporach will work for all the libs we need to support.

Tidy up test app and add very basic pollset support. This test needs to be rewritten
to actually do something useful.

Modified:
    apr/apr-util/trunk/include/apr_ssl.h
    apr/apr-util/trunk/include/private/apr_ssl_private.h
    apr/apr-util/trunk/ssl/apr_ssl_socket.c
    apr/apr-util/trunk/test/testssl.c

Modified: apr/apr-util/trunk/include/apr_ssl.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/include/apr_ssl.h?rev=416667&r1=416666&r2=416667&view=diff
==============================================================================
--- apr/apr-util/trunk/include/apr_ssl.h (original)
+++ apr/apr-util/trunk/include/apr_ssl.h Fri Jun 23 03:43:03 2006
@@ -22,6 +22,7 @@
 #include "apr_errno.h"
 #include "apr_pools.h"
 #include "apr_network_io.h"
+#include "apr_poll.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -211,6 +212,28 @@
  */
 APU_DECLARE(apr_status_t) apr_ssl_socket_raw_error(apr_ssl_socket_t *);
 
+
+/**
+ * @fn apr_status_t apr_pollset_add_ssl_socket(apr_pollset_t *pollset
+                                               apr_ssl_socket_t *sock)
+ * @brief Add an ssl socket to a pollset.
+ * @param pollset The pollset to add the socket to.
+ * @param sock The ssl socket to add.
+ * @note This fucntion adds the socket with APR_POLLIN and APR_POLLOUT
+ *       set.
+ */
+APU_DECLARE(apr_status_t) apr_pollset_add_ssl_socket(apr_pollset_t *,
+                                                     apr_ssl_socket_t *);
+
+/**
+ * @fn apr_status_t apr_pollset_remove_ssl_socket(apr_pollset_t *pollset,
+                                                  apr_ssl_socket_t *sock)
+ * @brief remove an ssl socket from a pollset.
+ * @param pollset The pollset to remove the socket from.
+ * @param sock The ssl socket to remove.
+ */
+APU_DECLARE(apr_status_t) apr_pollset_remove_ssl_socket(apr_pollset_t *,
+                                                        apr_ssl_socket_t *);
 
 /** @} */
 #ifdef __cplusplus

Modified: apr/apr-util/trunk/include/private/apr_ssl_private.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/include/private/apr_ssl_private.h?rev=416667&r1=416666&r2=416667&view=diff
==============================================================================
--- apr/apr-util/trunk/include/private/apr_ssl_private.h (original)
+++ apr/apr-util/trunk/include/private/apr_ssl_private.h Fri Jun 23 03:43:03 2006
@@ -38,15 +38,17 @@
  * SSL factory structure
  */
 struct apr_ssl_factory {
-    apr_pool_t *pool;
+    apr_pool_t     *pool;
     apu_ssl_data_t *sslData;
 };
 
 struct apr_ssl_socket {
-    apr_pool_t *pool;
-    apr_socket_t *plain;
+    apr_pool_t        *pool;
+    apr_socket_t      *plain;
     apr_ssl_factory_t *factory;
-    int connected;
+    apr_pollfd_t      *poll;
+    int                connected;
+
     apu_ssl_socket_data_t *sslData;
 };
 

Modified: apr/apr-util/trunk/ssl/apr_ssl_socket.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/ssl/apr_ssl_socket.c?rev=416667&r1=416666&r2=416667&view=diff
==============================================================================
--- apr/apr-util/trunk/ssl/apr_ssl_socket.c (original)
+++ apr/apr-util/trunk/ssl/apr_ssl_socket.c Fri Jun 23 03:43:03 2006
@@ -163,6 +163,39 @@
     return apu_ssl_raw_error(sock);
 }
 
+APU_DECLARE(apr_status_t) apr_pollset_add_ssl_socket(apr_pollset_t *pollset,
+                                                     apr_ssl_socket_t *sock)
+{
+    apr_status_t rv;
+    if (sock->poll)
+        /* socket is already in a pollset - return an error... */
+        return EALREADY;
+
+    sock->poll = apr_pcalloc(sock->pool, sizeof(*sock->poll));
+
+    sock->poll->desc_type = APR_POLL_SOCKET;
+    sock->poll->reqevents = APR_POLLIN | APR_POLLOUT;
+    sock->poll->desc.s = sock->plain;
+    sock->poll->client_data = sock->plain;
+    rv = apr_pollset_add(pollset, sock->poll);
+    if (rv != APR_SUCCESS)
+        sock->poll = NULL;
+    return rv;
+}
+
+
+
+APU_DECLARE(apr_status_t) apr_pollset_remove_ssl_socket(apr_pollset_t *pollset,
+                                                        apr_ssl_socket_t *sock)
+{
+    apr_status_t rv;
+    if (!sock->poll)
+        return EINVAL;
+    rv = apr_pollset_remove(pollset, sock->poll);
+    sock->poll = NULL;
+    return rv;
+}
+
 #else /* ! APU_HAVE_SSL */
 
 APU_DECLARE(apr_status_t) apr_ssl_socket_create(apr_ssl_socket_t **sock,
@@ -218,6 +251,18 @@
 }
 
 APU_DECLARE(apr_status_t) apr_ssl_socket_raw_error(apr_ssl_socket_t *sock)
+{
+    return APR_ENOTIMPL;
+}
+
+APU_DECLARE(apr_status_t) apr_pollset_add_ssl_socket(apr_pollset_t *pollset,
+                                                     apr_ssl_socket_t *sock)
+{
+    return APR_ENOTIMPL;
+}
+
+APU_DECLARE(apr_status_t) apr_pollset_remove_ssl_socket(apr_pollset_t *pollset,
+                                                        apr_ssl_socket_t *sock)
 {
     return APR_ENOTIMPL;
 }

Modified: apr/apr-util/trunk/test/testssl.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testssl.c?rev=416667&r1=416666&r2=416667&view=diff
==============================================================================
--- apr/apr-util/trunk/test/testssl.c (original)
+++ apr/apr-util/trunk/test/testssl.c Fri Jun 23 03:43:03 2006
@@ -52,7 +52,7 @@
     apr_ssl_factory_t *asf = NULL;
     apr_sockaddr_t *remoteSA;
     apr_status_t rv;
-    const char *libName;
+    apr_pollset_t *pollset;
 
 #ifdef APU_HAVE_SSL
 
@@ -62,6 +62,11 @@
 
     printf("SSL Library: %s\n", apr_ssl_library_name());
 
+    if (apr_pollset_create(&pollset, 1, pool, 0) != APR_SUCCESS) {
+        printf("Failed to create pollset!\n");
+        exit(1);
+    }
+
     if (apr_ssl_factory_create(&asf, NULL, NULL, NULL, pool) != APR_SUCCESS) {
         fprintf(stderr, "Unable to create client factory\n");
 
@@ -83,6 +88,9 @@
                 rv = apr_ssl_socket_connect(sslSock, remoteSA);
                 printf("Connect = %s\n", (rv == APR_SUCCESS ? "OK" : "Failed"));
 
+                rv = apr_pollset_add_ssl_socket(pollset, sslSock);
+                printf("Pollset add = %s\n", (rv == APR_SUCCESS ? "OK" : "Failed"));
+
                 printf("send: %s\n",
                        (apr_ssl_socket_send(sslSock, "GET / HTTP/1.0\n\n", 
                                             &len) == APR_SUCCESS ?
@@ -93,6 +101,8 @@
                        (apr_ssl_socket_recv(sslSock, buffer, &len) == 
                           APR_SUCCESS ? "OK" : "Failed"),
                        buffer);
+                rv = apr_pollset_remove_ssl_socket(pollset, sslSock);
+                printf("Pollset remove = %s\n", (rv == APR_SUCCESS ? "OK" : "Failed"));
 
             }
 



Mime
View raw message