apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@cpan.org>
Subject [Patch] Adding apr_socket_type_get()
Date Thu, 17 Jul 2003 07:15:40 GMT
The following patch adds apr_socket_type_get(apr_socket_t *sock, int
*type) to the network_io API, to allow differentiating between UDP and
TCP sockets for example (SOCK_STREAM vs SOCK_DGRAM)

When dealing with a mix of UDP & TCP sockets, I need this to know if I
should call recvfrom() or not, for instance.

Simple enough IMHO. Thoughts?

Index: srclib/apr/include/apr_network_io.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_network_io.h,v
retrieving revision 1.128
diff -u -I'$Id' -I'$Revision' -U10 -r1.128 apr_network_io.h
--- srclib/apr/include/apr_network_io.h	15 Aug 2002 03:23:36 -0000	1.128
+++ srclib/apr/include/apr_network_io.h	12 Mar 2003 02:51:14 -0000
@@ -647,20 +647,28 @@
  *
  * @param addr1 One of the APR socket addresses.
  * @param addr2 The other APR socket address.
  * @remark The return value will be non-zero if the addresses
  * are equivalent.
  */
 APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,
                                     const apr_sockaddr_t *addr2);
 
 
+ /**
+ * Return the type of the socket.
+ * @param sock The socket to query.
+ * @param type The returned type (e.g., SOCK_STREAM).
+ */
+APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock,
+                                              int *type);
+
 #if APR_FILES_AS_SOCKETS || defined(DOXYGEN)
 
 /**
  * Convert a File type to a socket so that it can be used in a poll
operation.
  * @param newsock the newly created socket which represents a file.
  * @param file the file to mask as a socket.
  * @warning This is not available on all platforms.  Platforms that
have the
  *      ability to poll files for data to be read/written/exceptions
will
  *      have the APR_FILES_AS_SOCKETS macro defined as true.
  * @deprecated This function has been deprecated, because of the new
poll
Index: srclib/apr/network_io/os2/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/os2/sockets.c,v
retrieving revision 1.56
diff -u -I'$Id' -I'$Revision' -U10 -r1.56 sockets.c
--- srclib/apr/network_io/os2/sockets.c	30 Jul 2002 13:56:14 -0000	1.56
+++ srclib/apr/network_io/os2/sockets.c	12 Mar 2003 02:51:14 -0000
@@ -213,20 +213,25 @@
     }
     else {
         int namelen = sizeof(sock->local_addr->sa.sin);
         getsockname(sock->socketdes, (struct sockaddr
*)&sock->local_addr->sa.sin, 
                     &namelen);
         sock->remote_addr = sa;
         return APR_SUCCESS;
     }
 }
 
+APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock, int
*type)
+{
+    *type = sock->type;
+    return APR_SUCCESS;
+}
 
 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char
*key,
                                      apr_socket_t *socket)
 {
     return apr_pool_userdata_get(data, key, socket->cntxt);
 }
 
 
 
 APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *socket,
void *data, const char *key,
Index: srclib/apr/network_io/unix/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/unix/sockets.c,v
retrieving revision 1.101
diff -u -I'$Id' -I'$Revision' -U10 -r1.101 sockets.c
--- srclib/apr/network_io/unix/sockets.c	30 Jul 2002 13:56:14
-0000	1.101
+++ srclib/apr/network_io/unix/sockets.c	12 Mar 2003 02:51:14 -0000
@@ -293,20 +293,26 @@
          * one for the socket
          */
         sock->local_interface_unknown = 1;
     }
 #ifndef HAVE_POLL
     sock->connected=1;
 #endif
     return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock, int
*type)
+{
+    *type = sock->type;
+    return APR_SUCCESS;
+}
+
 apr_status_t apr_socket_data_get(void **data, const char *key,
apr_socket_t *sock)
 {
     return apr_pool_userdata_get(data, key, sock->cntxt);
 }
 
 apr_status_t apr_socket_data_set(apr_socket_t *sock, void *data, const
char *key,
                               apr_status_t (*cleanup) (void *))
 {
     return apr_pool_userdata_set(data, key, cleanup, sock->cntxt);
 }
Index: srclib/apr/network_io/win32/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/win32/sockets.c,v
retrieving revision 1.85
diff -u -I'$Id' -I'$Revision' -U10 -r1.85 sockets.c
--- srclib/apr/network_io/win32/sockets.c	30 Jul 2002 13:56:17
-0000	1.85
+++ srclib/apr/network_io/win32/sockets.c	12 Mar 2003 02:51:14 -0000
@@ -376,20 +376,26 @@
                 generic_inaddr_any,
                 sock->local_addr->ipaddr_len)) {
         /* not bound to specific local interface; connect() had to
assign
          * one for the socket
          */
         sock->local_interface_unknown = 1;
     }
     return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock, int
*type)
+{
+    *type = sock->type;
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char
*key,
                                              apr_socket_t *socket)
 {
     return apr_pool_userdata_get(data, key, socket->cntxt);
 }
 
 APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *socket,
void *data,
                                              const char *key,
                                              apr_status_t
(*cleanup)(void *))
 {

-- 
--------------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'


Mime
View raw message