Cleaned up the option mapping code a bit.

This commit is contained in:
Alexandre Julliard 2003-04-04 22:29:52 +00:00
parent 088bcf9ca5
commit 7b007b47ae
1 changed files with 58 additions and 70 deletions

View File

@ -243,67 +243,50 @@ static HANDLE _WSHeap = 0;
#define WS_FREE(ptr) \ #define WS_FREE(ptr) \
HeapFree(_WSHeap, 0, (ptr) ) HeapFree(_WSHeap, 0, (ptr) )
static INT _ws_sock_ops[] = #define MAP_OPTION(opt) { WS_##opt, opt }
{ WS_SO_DEBUG, WS_SO_REUSEADDR, WS_SO_KEEPALIVE, WS_SO_DONTROUTE,
WS_SO_BROADCAST, WS_SO_LINGER, WS_SO_OOBINLINE, WS_SO_SNDBUF, static const int ws_sock_map[][2] =
WS_SO_RCVBUF, WS_SO_ERROR, WS_SO_TYPE, {
MAP_OPTION( SO_DEBUG ),
MAP_OPTION( SO_REUSEADDR ),
MAP_OPTION( SO_KEEPALIVE ),
MAP_OPTION( SO_DONTROUTE ),
MAP_OPTION( SO_BROADCAST ),
MAP_OPTION( SO_LINGER ),
MAP_OPTION( SO_OOBINLINE ),
MAP_OPTION( SO_SNDBUF ),
MAP_OPTION( SO_RCVBUF ),
MAP_OPTION( SO_ERROR ),
MAP_OPTION( SO_TYPE ),
#ifdef SO_RCVTIMEO #ifdef SO_RCVTIMEO
WS_SO_RCVTIMEO, MAP_OPTION( SO_RCVTIMEO ),
#endif #endif
#ifdef SO_SNDTIMEO #ifdef SO_SNDTIMEO
WS_SO_SNDTIMEO, MAP_OPTION( SO_SNDTIMEO ),
#endif #endif
0 }; { 0, 0 }
static int _px_sock_ops[] =
{ SO_DEBUG, SO_REUSEADDR, SO_KEEPALIVE, SO_DONTROUTE, SO_BROADCAST,
SO_LINGER, SO_OOBINLINE, SO_SNDBUF, SO_RCVBUF, SO_ERROR, SO_TYPE,
#ifdef SO_RCVTIMEO
SO_RCVTIMEO,
#endif
#ifdef SO_SNDTIMEO
SO_SNDTIMEO,
#endif
};
static INT _ws_tcp_ops[] = {
#ifdef TCP_NODELAY
WS_TCP_NODELAY,
#endif
0
};
static int _px_tcp_ops[] = {
#ifdef TCP_NODELAY
TCP_NODELAY,
#endif
0
}; };
static const int _ws_ip_ops[] = static const int ws_tcp_map[][2] =
{ {
WS_IP_MULTICAST_IF, #ifdef TCP_NODELAY
WS_IP_MULTICAST_TTL, MAP_OPTION( TCP_NODELAY ),
WS_IP_MULTICAST_LOOP, #endif
WS_IP_ADD_MEMBERSHIP, { 0, 0 }
WS_IP_DROP_MEMBERSHIP,
WS_IP_OPTIONS,
WS_IP_HDRINCL,
WS_IP_TOS,
WS_IP_TTL,
0
}; };
static const int _px_ip_ops[] = static const int ws_ip_map[][2] =
{ {
IP_MULTICAST_IF, MAP_OPTION( IP_MULTICAST_IF ),
IP_MULTICAST_TTL, MAP_OPTION( IP_MULTICAST_TTL ),
IP_MULTICAST_LOOP, MAP_OPTION( IP_MULTICAST_LOOP ),
IP_ADD_MEMBERSHIP, MAP_OPTION( IP_ADD_MEMBERSHIP ),
IP_DROP_MEMBERSHIP, MAP_OPTION( IP_DROP_MEMBERSHIP ),
IP_OPTIONS, MAP_OPTION( IP_OPTIONS ),
IP_HDRINCL, MAP_OPTION( IP_HDRINCL ),
IP_TOS, MAP_OPTION( IP_TOS ),
IP_TTL, MAP_OPTION( IP_TTL ),
0 { 0, 0 }
}; };
static DWORD opentype_tls_index = -1; /* TLS index for SO_OPENTYPE flag */ static DWORD opentype_tls_index = -1; /* TLS index for SO_OPENTYPE flag */
@ -492,33 +475,38 @@ static int convert_sockopt(INT *level, INT *optname)
{ {
case WS_SOL_SOCKET: case WS_SOL_SOCKET:
*level = SOL_SOCKET; *level = SOL_SOCKET;
for(i=0; _ws_sock_ops[i]; i++) for(i=0; ws_sock_map[i][0]; i++)
if( _ws_sock_ops[i] == *optname ) break; {
if( _ws_sock_ops[i] ) { if( ws_sock_map[i][0] == *optname )
*optname = _px_sock_ops[i]; {
*optname = ws_sock_map[i][1];
return 1; return 1;
} }
}
FIXME("Unknown SOL_SOCKET optname 0x%x\n", *optname); FIXME("Unknown SOL_SOCKET optname 0x%x\n", *optname);
break; break;
case WS_IPPROTO_TCP: case WS_IPPROTO_TCP:
*level = IPPROTO_TCP; *level = IPPROTO_TCP;
for(i=0; _ws_tcp_ops[i]; i++) for(i=0; ws_tcp_map[i][0]; i++)
if ( _ws_tcp_ops[i] == *optname ) break; {
if( _ws_tcp_ops[i] ) { if ( ws_tcp_map[i][0] == *optname )
*optname = _px_tcp_ops[i]; {
*optname = ws_tcp_map[i][1];
return 1; return 1;
} }
}
FIXME("Unknown IPPROTO_TCP optname 0x%x\n", *optname); FIXME("Unknown IPPROTO_TCP optname 0x%x\n", *optname);
break; break;
case WS_IPPROTO_IP: case WS_IPPROTO_IP:
*level = IPPROTO_IP; *level = IPPROTO_IP;
for(i=0; _ws_ip_ops[i]; i++) { for(i=0; ws_ip_map[i][0]; i++)
if (_ws_ip_ops[i] == *optname ) break; {
} if (ws_ip_map[i][0] == *optname )
if( _ws_ip_ops[i] ) { {
*optname = _px_ip_ops[i]; *optname = ws_ip_map[i][1];
return 1; return 1;
} }
}
FIXME("Unknown IPPROTO_IP optname 0x%x\n", *optname); FIXME("Unknown IPPROTO_IP optname 0x%x\n", *optname);
break; break;
default: FIXME("Unimplemented or unknown socket level\n"); default: FIXME("Unimplemented or unknown socket level\n");