summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2003-11-30 16:47:29 +0000
committertrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2003-11-30 16:47:29 +0000
commit8e20cb325d5bc83551b9bf22b6067624dab86888 (patch)
tree047b6dd550e37aecbc1df713d6d54519bf4203b5
parent9309519700ca57eeb53c429eff122beb876a8c7b (diff)
downloadlibapr-8e20cb325d5bc83551b9bf22b6067624dab86888.tar.gz
Add apr_socket_type_get() for retrieving the type (e.g., stream)
of the socket. Submitted by: Philippe M. Chiasson <gozer cpan.org> Reviewed by: trawick git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64801 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES3
-rw-r--r--include/apr_network_io.h9
-rw-r--r--network_io/os2/sockets.c5
-rw-r--r--network_io/unix/sockets.c6
-rw-r--r--network_io/win32/sockets.c6
-rw-r--r--test/testsockets.c12
6 files changed, 40 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 9f8876ee1..2dc018355 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,9 @@ Changes for APR 1.1 [Deferring these features when 1.0 is rolled out.]
Changes with APR 1.0
+ *) Add apr_socket_type_get() for retrieving the type (e.g., stream)
+ of the socket. [Philippe M. Chiasson gozer cpan.org]
+
*) Removed deprecated interface apr_proc_other_child_check()
that behaved differently between win32 and unix.
The unix behavor is now accomplished with
diff --git a/include/apr_network_io.h b/include/apr_network_io.h
index 27e706f72..9449fdc81 100644
--- a/include/apr_network_io.h
+++ b/include/apr_network_io.h
@@ -727,7 +727,14 @@ APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr,
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
diff --git a/network_io/os2/sockets.c b/network_io/os2/sockets.c
index 66949b573..b58c046e7 100644
--- a/network_io/os2/sockets.c
+++ b/network_io/os2/sockets.c
@@ -240,6 +240,11 @@ APR_DECLARE(apr_status_t) apr_socket_connect(apr_socket_t *sock,
}
}
+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)
diff --git a/network_io/unix/sockets.c b/network_io/unix/sockets.c
index 1c1638932..52bf434c9 100644
--- a/network_io/unix/sockets.c
+++ b/network_io/unix/sockets.c
@@ -317,6 +317,12 @@ apr_status_t apr_socket_connect(apr_socket_t *sock, apr_sockaddr_t *sa)
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;
diff --git a/network_io/win32/sockets.c b/network_io/win32/sockets.c
index b03f8813c..55f31140f 100644
--- a/network_io/win32/sockets.c
+++ b/network_io/win32/sockets.c
@@ -401,6 +401,12 @@ APR_DECLARE(apr_status_t) apr_socket_connect(apr_socket_t *sock,
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 *sock)
{
diff --git a/test/testsockets.c b/test/testsockets.c
index 87f46a027..1ba2ea111 100644
--- a/test/testsockets.c
+++ b/test/testsockets.c
@@ -72,10 +72,16 @@ static void tcp_socket(CuTest *tc)
{
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 @@ static void udp_socket(CuTest *tc)
{
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);
}