You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by st...@apache.org on 2002/06/06 04:58:16 UTC
cvs commit: apr/network_io/win32 sockopt.c
stoddard 2002/06/05 19:58:16
Modified: include/arch/win32 networkio.h
network_io/win32 sockopt.c
Log:
win32 now passes testsockopt. Merge the Netware codepath
in apr_getsockopt with the win32 codepath.
Revision Changes Path
1.25 +9 -0 apr/include/arch/win32/networkio.h
Index: networkio.h
===================================================================
RCS file: /home/cvs/apr/include/arch/win32/networkio.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- networkio.h 4 Jun 2002 04:50:44 -0000 1.24
+++ networkio.h 6 Jun 2002 02:58:16 -0000 1.25
@@ -97,5 +97,14 @@
int apr_inet_pton(int af, const char *src, void *dst);
void apr_sockaddr_vars_set(apr_sockaddr_t *, int, apr_port_t);
+#define apr_is_option_set(mask, option) ((mask & option) ==option)
+#define apr_set_option(mask, option, on) \
+ do { \
+ if (on) \
+ *mask |= option; \
+ else \
+ *mask &= ~option; \
+ } while (0)
+
#endif /* ! NETWORK_IO_H */
1.38 +39 -58 apr/network_io/win32/sockopt.c
Index: sockopt.c
===================================================================
RCS file: /home/cvs/apr/network_io/win32/sockopt.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- sockopt.c 13 Mar 2002 20:39:25 -0000 1.37
+++ sockopt.c 6 Jun 2002 02:58:16 -0000 1.38
@@ -124,43 +124,61 @@
break;
}
case APR_SO_KEEPALIVE:
- if (setsockopt(sock->sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&one, sizeof(int)) == -1) {
- return apr_get_netos_error();
+ if (on != apr_is_option_set(sock->netmask, APR_SO_KEEPALIVE)) {
+ if (setsockopt(sock->sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&one, sizeof(int)) == -1) {
+ return apr_get_netos_error();
+ }
+ apr_set_option(&sock->netmask,APR_SO_KEEPALIVE, on);
}
break;
case APR_SO_DEBUG:
- if (setsockopt(sock->sock, SOL_SOCKET, SO_DEBUG, (void *)&one, sizeof(int)) == -1) {
- return apr_get_netos_error();
+ if (on != apr_is_option_set(sock->netmask, APR_SO_DEBUG)) {
+ if (setsockopt(sock->sock, SOL_SOCKET, SO_DEBUG, (void *)&one, sizeof(int)) == -1) {
+ return apr_get_netos_error();
+ }
+ apr_set_option(&sock->netmask, APR_SO_DEBUG, on);
}
break;
case APR_SO_REUSEADDR:
- if (setsockopt(sock->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(int)) == -1) {
- return apr_get_netos_error();
+ if (on != apr_is_option_set(sock->netmask, APR_SO_REUSEADDR)){
+ if (setsockopt(sock->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(int)) == -1) {
+ return apr_get_netos_error();
+ }
+ apr_set_option(&sock->netmask, APR_SO_REUSEADDR, on);
}
break;
case APR_SO_NONBLOCK:
- if (on) {
- if ((stat = sononblock(sock->sock)) != APR_SUCCESS)
- return stat;
- }
- else {
- if ((stat = soblock(sock->sock)) != APR_SUCCESS)
- return stat;
+ if (apr_is_option_set(sock->netmask, APR_SO_NONBLOCK) != on){
+ if (on) {
+ if ((stat = sononblock(sock->sock)) != APR_SUCCESS)
+ return stat;
+ }
+ else {
+ if ((stat = soblock(sock->sock)) != APR_SUCCESS)
+ return stat;
+ }
+ apr_set_option(&sock->netmask, APR_SO_NONBLOCK, on);
}
break;
case APR_SO_LINGER:
{
- struct linger li;
- li.l_onoff = on;
- li.l_linger = MAX_SECS_TO_LINGER;
- if (setsockopt(sock->sock, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(struct linger)) == -1) {
- return apr_get_netos_error();
+ if (apr_is_option_set(sock->netmask, APR_SO_LINGER) != on){
+ struct linger li;
+ li.l_onoff = on;
+ li.l_linger = MAX_SECS_TO_LINGER;
+ if (setsockopt(sock->sock, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(struct linger)) == -1) {
+ return apr_get_netos_error();
+ }
+ apr_set_option(&sock->netmask, APR_SO_LINGER, on);
}
break;
}
case APR_TCP_NODELAY:
- if (setsockopt(sock->sock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(int)) == -1) {
- return apr_get_netos_error();
+ if (apr_is_option_set(sock->netmask, APR_TCP_NODELAY) != on){
+ if (setsockopt(sock->sock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(int)) == -1) {
+ return apr_get_netos_error();
+ }
+ apr_set_option(&sock->netmask, APR_TCP_NODELAY, on);
}
break;
default:
@@ -173,9 +191,6 @@
APR_DECLARE(apr_status_t) apr_getsocketopt(apr_socket_t *sock,
apr_int32_t opt, apr_int32_t *on)
{
-#ifdef NETWARE
- int sol_opt = 0;
-
switch (opt) {
case APR_SO_TIMEOUT:
/* Convert from milliseconds (windows units) to microseconds
@@ -186,47 +201,13 @@
*on = sock->disconnected;
break;
case APR_SO_KEEPALIVE:
- sol_opt = SO_KEEPALIVE;
- break;
case APR_SO_DEBUG:
- sol_opt = SO_DEBUG;
- break;
case APR_SO_REUSEADDR:
- sol_opt = SO_REUSEADDR;
- break;
case APR_SO_NONBLOCK:
case APR_SO_LINGER:
default:
- return APR_ENOTIMPL;
- break;
- }
- if (sol_opt) {
- int sz = sizeof(apr_int32_t);
-
- if (getsockopt(sock->sock, SOL_SOCKET, sol_opt, (char *)on, &sz) == -1) {
- return apr_get_netos_error();
- }
- }
-#else
- switch (opt) {
- case APR_SO_TIMEOUT:
- /* Convert from milliseconds (windows units) to microseconds
- * (APR units) */
- *on = (apr_int32_t)(sock->timeout * 1000);
- break;
- case APR_SO_DISCONNECTED:
- *on = sock->disconnected;
- break;
- case APR_SO_KEEPALIVE:
- case APR_SO_DEBUG:
- case APR_SO_REUSEADDR:
- case APR_SO_NONBLOCK:
- case APR_SO_LINGER:
- default:
- return APR_ENOTIMPL;
- break;
+ *on = apr_is_option_set(sock->netmask, opt);
}
-#endif
return APR_SUCCESS;
}