Hopefully I didn't miss any comments on the mailing list last night
(where is that archive again?).

Here is enough to look at to make sure I didn't screw anything up.  I
added family and type parameters too so that APR doesn't have to bend
over backwards (i.e., use syscalls) to find that out.  We don't keep
the type anywhere yet but it is likely to become useful in the future.

Index: include/apr_portable.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_portable.h,v
retrieving revision 1.40
diff -u -r1.40 apr_portable.h
--- include/apr_portable.h      2000/11/26 03:00:03     1.40
+++ include/apr_portable.h      2000/12/03 14:28:26
@@ -275,6 +275,23 @@
                              apr_pool_t *cont);
 
 /**
+ * Create a socket from an existing descriptor and local and remote
+ * socket addresses.
+ * @param apr_sock The new socket that has been set up
+ * @param os_sock The os representation of a socket
+ * @param local The local socket address (or NULL if unknown)
+ * @param remote The remote socket address (or NULL if unknown)
+ * @param family The address family of the socket (e.g., APR_INET)
+ * @param type The type of the socket (e.g., SOCK_STREAM)
+ * @param cont The pool to use
+ * @tip If you only know the descriptor/handle or if it isn't really
+ *      a true socket, use apr_put_os_sock() instead.
+ */
+apr_status_t apr_make_os_sock(apr_socket_t **apr_sock, apr_os_sock_t *os_sock,
+                              struct sockaddr *local, struct sockaddr *remote,
+                              int family, int type, apr_pool_t *cont);
+
+/**
  * Convert the lock from os specific type to apr type
  * @param lock The apr lock we are converting to.
  * @param thelock The os specific lock to convert.
Index: network_io/unix/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/unix/sockets.c,v
retrieving revision 1.65
diff -u -r1.65 sockets.c
--- network_io/unix/sockets.c   2000/11/21 21:33:07     1.65
+++ network_io/unix/sockets.c   2000/12/03 14:28:28
@@ -282,6 +282,32 @@
     return APR_SUCCESS;
 }
 
+apr_status_t apr_make_os_sock(apr_socket_t **apr_sock, apr_os_sock_t *os_sock,
+                              struct sockaddr *local, struct sockaddr *remote,
+                              int family, int type, apr_pool_t *cont)
+{
+    alloc_socket(apr_sock, cont);
+    set_socket_vars(*apr_sock, family);
+    (*apr_sock)->timeout = -1;
+    (*apr_sock)->socketdes = *os_sock;
+    if (local) {
+        memcpy(&(*apr_sock)->local_addr->sa.sin, local, 
+               (*apr_sock)->local_addr->salen);
+    }
+    else {
+        (*apr_sock)->local_port_unknown = (*apr_sock)->local_interface_unknown 
= 1;
+    }
+    if (remote) {
+#ifndef HAVE_POLL
+        (*apr_sock)->connected = 1;
+#endif
+        memcpy(&(*apr_sock)->remote_addr->sa.sin, local, 
+               (*apr_sock)->remote_addr->salen);
+    }
+        
+    return APR_SUCCESS;
+}
+
 apr_status_t apr_put_os_sock(apr_socket_t **sock, apr_os_sock_t *thesock, 
                            apr_pool_t *cont)
 {


-- 
Jeff Trawick | [EMAIL PROTECTED] | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Reply via email to