Currently, there is no way to differentiate between the different kinds of apr_socket_t (UDP vs TCP for example).
I suggest the following patch to allow apr_socket_t users to access the
type of the underlying socket.
Index: test/testsockets.c
===================================================================
RCS file: /home/cvspublic/apr/test/testsockets.c,v
retrieving revision 1.10
diff -u -I$Id: -r1.10 testsockets.c
--- test/testsockets.c 3 Sep 2003 14:43:53 -0000 1.10
+++ test/testsockets.c 26 Nov 2003 20:57:29 -0000
@@ -72,10 +72,16 @@
{
apr_status_t rv;
apr_socket_t *sock = NULL;
+ int type;
rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, 0, p);
CuAssertIntEquals(tc, APR_SUCCESS, rv);
CuAssertPtrNotNull(tc, sock);
+
+ rv = apr_socket_type_get(sock, &type);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, SOCK_STREAM, type);
+
apr_socket_close(sock);
}
@@ -83,10 +89,16 @@
{
apr_status_t rv;
apr_socket_t *sock = NULL;
+ int type;
rv = apr_socket_create(&sock, APR_INET, SOCK_DGRAM, 0, p);
CuAssertIntEquals(tc, APR_SUCCESS, rv);
CuAssertPtrNotNull(tc, sock);
+
+ rv = apr_socket_type_get(sock, &type);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, SOCK_DGRAM, type);
+
apr_socket_close(sock);
}
Index: include/apr_network_io.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_network_io.h,v
retrieving revision 1.148
diff -u -I$Id: -r1.148 apr_network_io.h
--- include/apr_network_io.h 20 Nov 2003 17:40:16 -0000 1.148
+++ include/apr_network_io.h 26 Nov 2003 20:57:29 -0000
@@ -727,7 +727,14 @@
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);
+
/**
* Given an apr_sockaddr_t and a service name, set the port for the service
* @param sockaddr The apr_sockaddr_t that will have its port set
Index: network_io/os2/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/os2/sockets.c,v
retrieving revision 1.67
diff -u -I$Id: -r1.67 sockets.c
--- network_io/os2/sockets.c 17 Nov 2003 01:41:18 -0000 1.67
+++ network_io/os2/sockets.c 26 Nov 2003 20:57:29 -0000
@@ -240,6 +240,11 @@
}
}
+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 *sock)
Index: network_io/unix/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/unix/sockets.c,v
retrieving revision 1.116
diff -u -I$Id: -r1.116 sockets.c
--- network_io/unix/sockets.c 24 Nov 2003 00:17:24 -0000 1.116
+++ network_io/unix/sockets.c 26 Nov 2003 20:57:29 -0000
@@ -317,6 +317,12 @@
return APR_SUCCESS;
}
+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)
{
sock_userdata_t *cur = sock->userdata;
Index: network_io/win32/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/win32/sockets.c,v
retrieving revision 1.102
diff -u -I$Id: -r1.102 sockets.c
--- network_io/win32/sockets.c 17 Nov 2003 19:54:08 -0000 1.102
+++ network_io/win32/sockets.c 26 Nov 2003 20:57:29 -0000
@@ -1,4 +1,4 @@
-/* ====================================================================
+ /* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
@@ -398,6 +398,12 @@
*/
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;
}
--
--------------------------------------------------------------------------------
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}'
signature.asc
Description: This is a digitally signed message part
