wrowe 2002/07/14 23:10:00
Modified: network_io/unix sockopt.c
network_io/os2 sockopt.c
Log:
Straightforward implementations of apr_socket_timeout_set/get, right
from the current apr_get/setsockopt implementations for OS2/Unix.
Revision Changes Path
1.53 +44 -0 apr/network_io/unix/sockopt.c
Index: sockopt.c
===================================================================
RCS file: /home/cvs/apr/network_io/unix/sockopt.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- sockopt.c 17 May 2002 18:10:52 -0000 1.52
+++ sockopt.c 15 Jul 2002 06:10:00 -0000 1.53
@@ -110,6 +110,40 @@
return APR_SUCCESS;
}
+
+APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock,
apr_interval_time_t t)
+{
+ /* If our timeout is positive or zero and our last timeout was
+ * negative, then we need to ensure that we are non-blocking.
+ * Conversely, if our timeout is negative and we had a positive
+ * or zero timeout, we must make sure our socket is blocking.
+ * We want to avoid calling fcntl more than necessary on the socket,
+ */
+ if (on >= 0 && sock->timeout < 0){
+ if (apr_is_option_set(sock->netmask, APR_SO_NONBLOCK) != 1){
+ if ((stat = sononblock(sock->socketdes)) != APR_SUCCESS){
+ return stat;
+ }
+ }
+ }
+ else if (on < 0 && sock->timeout >= 0){
+ if (apr_is_option_set(sock->netmask, APR_SO_NONBLOCK) != 0){
+ if ((stat = soblock(sock->socketdes)) != APR_SUCCESS) {
+ return stat;
+ }
+ }
+ }
+ /* must disable the incomplete read support if we change to a
+ * blocking socket.
+ */
+ if (on == 0) {
+ sock->netmask &= ~APR_INCOMPLETE_READ;
+ }
+ sock->timeout = t;
+ apr_set_option(&sock->netmask, APR_SO_TIMEOUT, t);
+}
+
+
apr_status_t apr_setsocketopt(apr_socket_t *sock, apr_int32_t opt,
apr_int32_t on)
{
int one;
@@ -188,6 +222,7 @@
#endif
}
if (opt & APR_SO_TIMEOUT) {
+ /* XXX: To be deprecated */
/* If our timeout is positive or zero and our last timeout was
* negative, then we need to ensure that we are non-blocking.
* Conversely, if our timeout is negative and we had a positive
@@ -284,10 +319,19 @@
return APR_SUCCESS;
}
+
+APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock,
apr_interval_time_t *t)
+{
+ *t = sock->timeout;
+ return APR_SUCCESS;
+}
+
+
apr_status_t apr_getsocketopt(apr_socket_t *sock, apr_int32_t opt,
apr_int32_t *on)
{
switch(opt) {
case APR_SO_TIMEOUT:
+ /* XXX: To be deprecated */
*on = sock->timeout;
break;
default:
1.25 +15 -1 apr/network_io/os2/sockopt.c
Index: sockopt.c
===================================================================
RCS file: /home/cvs/apr/network_io/os2/sockopt.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- sockopt.c 13 Mar 2002 20:39:24 -0000 1.24
+++ sockopt.c 15 Jul 2002 06:10:00 -0000 1.25
@@ -67,6 +67,13 @@
#include <sys/so_ioctl.h>
+APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock,
apr_interval_time_t t)
+{
+ sock->timeout = on;
+ return APR_SUCCESS;
+}
+
+
APR_DECLARE(apr_status_t) apr_setsocketopt(apr_socket_t *sock, apr_int32_t
opt, apr_int32_t on)
{
int one;
@@ -112,6 +119,7 @@
}
}
if (opt & APR_SO_TIMEOUT) {
+ /* XXX: To be deprecated */
sock->timeout = on;
}
if (opt & APR_TCP_NODELAY) {
@@ -123,11 +131,18 @@
}
+APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock,
apr_interval_time_t *t)
+{
+ *t = sock->timeout;
+ return APR_SUCCESS;
+}
+
APR_DECLARE(apr_status_t) apr_getsocketopt(apr_socket_t *sock, apr_int32_t
opt, apr_int32_t *on)
{
switch(opt) {
case APR_SO_TIMEOUT:
+ /* XXX: To be deprecated */
*on = sock->timeout;
break;
default:
@@ -135,7 +150,6 @@
}
return APR_SUCCESS;
}
-
APR_DECLARE(apr_status_t) apr_gethostname(char *buf, apr_int32_t len,
apr_pool_t *cont)