1 /*
2 * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <stdio.h>
27 #ifdef _WIN32
28 #include <winsock2.h>
29 #include <ws2tcpip.h>
30 #else
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <netinet/tcp.h>
35 #endif
36
37 /**
38 * Generates sun.nio.ch.SocketOptionRegistry, a class that maps Java-level
39 * socket options to the platform specific level and option.
40 */
41
42 static void out(char* s) {
43 printf("%s\n", s);
44 }
45
46 static void emit(const char *name, char * family, int level, int optname) {
47 printf(" map.put(new RegistryKey(%s, %s),", name, family);
48 printf(" new OptionKey(%d, %d));\n", level, optname);
49 }
50
51 static void emit_unspec(const char *name, int level, int optname) {
52 emit(name, "Net.UNSPEC", level, optname);
53 }
54
55 static void emit_inet(const char *name, int level, int optname) {
56 emit(name, "StandardProtocolFamily.INET", level, optname);
100 emit_unspec("StandardSocketOptions.SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE);
101 emit_unspec("StandardSocketOptions.SO_LINGER", SOL_SOCKET, SO_LINGER);
102 emit_unspec("StandardSocketOptions.SO_SNDBUF", SOL_SOCKET, SO_SNDBUF);
103 emit_unspec("StandardSocketOptions.SO_RCVBUF", SOL_SOCKET, SO_RCVBUF);
104 emit_unspec("StandardSocketOptions.SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR);
105 emit_unspec("StandardSocketOptions.TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY);
106
107 emit_inet("StandardSocketOptions.IP_TOS", IPPROTO_IP, IP_TOS);
108 emit_inet("StandardSocketOptions.IP_MULTICAST_IF", IPPROTO_IP, IP_MULTICAST_IF);
109 emit_inet("StandardSocketOptions.IP_MULTICAST_TTL", IPPROTO_IP, IP_MULTICAST_TTL);
110 emit_inet("StandardSocketOptions.IP_MULTICAST_LOOP", IPPROTO_IP, IP_MULTICAST_LOOP);
111
112 #ifdef AF_INET6
113 emit_inet6("StandardSocketOptions.IP_TOS", IPPROTO_IPV6, IPV6_TCLASS);
114 emit_inet6("StandardSocketOptions.IP_MULTICAST_IF", IPPROTO_IPV6, IPV6_MULTICAST_IF);
115 emit_inet6("StandardSocketOptions.IP_MULTICAST_TTL", IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
116 emit_inet6("StandardSocketOptions.IP_MULTICAST_LOOP", IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
117 #endif
118
119 emit_unspec("ExtendedSocketOption.SO_OOBINLINE", SOL_SOCKET, SO_OOBINLINE);
120
121 out(" return map; ");
122 out(" } ");
123 out(" } ");
124 out(" public static OptionKey findOption(SocketOption<?> name, ProtocolFamily family) { ");
125 out(" RegistryKey key = new RegistryKey(name, family); ");
126 out(" return LazyInitialization.options.get(key); ");
127 out(" } ");
128 out("} ");
129
130 return 0;
131 }
|
1 /*
2 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <stdio.h>
27 #ifdef _WIN32
28 #include <winsock2.h>
29 #include <ws2tcpip.h>
30 #else
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <netinet/tcp.h>
35 #endif
36
37 #if !defined(SO_QUICKACK)
38 #if defined(__linux__)
39 #define SO_QUICKACK 0xC /* Block/reenable quick ACKs. */
40 #else
41 #define SO_QUICKACK 0
42 #endif
43 #endif
44 /**
45 * Generates sun.nio.ch.SocketOptionRegistry, a class that maps Java-level
46 * socket options to the platform specific level and option.
47 */
48
49 static void out(char* s) {
50 printf("%s\n", s);
51 }
52
53 static void emit(const char *name, char * family, int level, int optname) {
54 printf(" map.put(new RegistryKey(%s, %s),", name, family);
55 printf(" new OptionKey(%d, %d));\n", level, optname);
56 }
57
58 static void emit_unspec(const char *name, int level, int optname) {
59 emit(name, "Net.UNSPEC", level, optname);
60 }
61
62 static void emit_inet(const char *name, int level, int optname) {
63 emit(name, "StandardProtocolFamily.INET", level, optname);
107 emit_unspec("StandardSocketOptions.SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE);
108 emit_unspec("StandardSocketOptions.SO_LINGER", SOL_SOCKET, SO_LINGER);
109 emit_unspec("StandardSocketOptions.SO_SNDBUF", SOL_SOCKET, SO_SNDBUF);
110 emit_unspec("StandardSocketOptions.SO_RCVBUF", SOL_SOCKET, SO_RCVBUF);
111 emit_unspec("StandardSocketOptions.SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR);
112 emit_unspec("StandardSocketOptions.TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY);
113
114 emit_inet("StandardSocketOptions.IP_TOS", IPPROTO_IP, IP_TOS);
115 emit_inet("StandardSocketOptions.IP_MULTICAST_IF", IPPROTO_IP, IP_MULTICAST_IF);
116 emit_inet("StandardSocketOptions.IP_MULTICAST_TTL", IPPROTO_IP, IP_MULTICAST_TTL);
117 emit_inet("StandardSocketOptions.IP_MULTICAST_LOOP", IPPROTO_IP, IP_MULTICAST_LOOP);
118
119 #ifdef AF_INET6
120 emit_inet6("StandardSocketOptions.IP_TOS", IPPROTO_IPV6, IPV6_TCLASS);
121 emit_inet6("StandardSocketOptions.IP_MULTICAST_IF", IPPROTO_IPV6, IPV6_MULTICAST_IF);
122 emit_inet6("StandardSocketOptions.IP_MULTICAST_TTL", IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
123 emit_inet6("StandardSocketOptions.IP_MULTICAST_LOOP", IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
124 #endif
125
126 emit_unspec("ExtendedSocketOption.SO_OOBINLINE", SOL_SOCKET, SO_OOBINLINE);
127 emit_unspec("jdk.net.ExtendedSocketOptions.SO_QUICKACK", SOL_SOCKET, SO_QUICKACK);
128
129 out(" return map; ");
130 out(" } ");
131 out(" } ");
132 out(" public static OptionKey findOption(SocketOption<?> name, ProtocolFamily family) { ");
133 out(" RegistryKey key = new RegistryKey(name, family); ");
134 out(" return LazyInitialization.options.get(key); ");
135 out(" } ");
136 out("} ");
137
138 return 0;
139 }
|