Source Code Cross Referenced for TwoStacksPlainDatagramSocketImpl.java in  » 6.0-JDK-Platform » windows » java » net » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Platform » windows » java.net 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:        package java.net;
026:
027:        import java.io.IOException;
028:        import java.io.FileDescriptor;
029:
030:        /**
031:         * This class defines the plain DatagramSocketImpl that is used for all
032:         * Windows versions lower than Vista. It adds support for IPv6 on
033:         * these platforms where available.
034:         *
035:         * For backward compatibility windows platforms that do not have IPv6
036:         * support also use this implementation, and fd1 gets set to null
037:         * during socket creation.
038:         *
039:         * @version 1.2, 06/11/07
040:         * @author Chris Hegarty
041:         */
042:
043:        class TwoStacksPlainDatagramSocketImpl extends
044:                AbstractPlainDatagramSocketImpl {
045:            /* Used for IPv6 on Windows only */
046:            private FileDescriptor fd1;
047:
048:            /*
049:             * Needed for ipv6 on windows because we need to know
050:             * if the socket was bound to ::0 or 0.0.0.0, when a caller
051:             * asks for it. In this case, both sockets are used, but we
052:             * don't know whether the caller requested ::0 or 0.0.0.0
053:             * and need to remember it here.
054:             */
055:            private InetAddress anyLocalBoundAddr = null;
056:
057:            private int fduse = -1; /* saved between peek() and receive() calls */
058:
059:            /* saved between successive calls to receive, if data is detected
060:             * on both sockets at same time. To ensure that one socket is not
061:             * starved, they rotate using this field
062:             */
063:            private int lastfd = -1;
064:
065:            static {
066:                init();
067:            }
068:
069:            protected synchronized void create() throws SocketException {
070:                fd1 = new FileDescriptor();
071:                super .create();
072:            }
073:
074:            protected synchronized void bind(int lport, InetAddress laddr)
075:                    throws SocketException {
076:                super .bind(lport, laddr);
077:                if (laddr.isAnyLocalAddress()) {
078:                    anyLocalBoundAddr = laddr;
079:                }
080:            }
081:
082:            protected synchronized void receive(DatagramPacket p)
083:                    throws IOException {
084:                try {
085:                    receive0(p);
086:                } finally {
087:                    fduse = -1;
088:                }
089:            }
090:
091:            public Object getOption(int optID) throws SocketException {
092:                if (isClosed()) {
093:                    throw new SocketException("Socket Closed");
094:                }
095:
096:                if (optID == SO_BINDADDR) {
097:                    if (fd != null && fd1 != null) {
098:                        return anyLocalBoundAddr;
099:                    }
100:                    return socketGetOption(optID);
101:                } else
102:                    return super .getOption(optID);
103:            }
104:
105:            protected boolean isClosed() {
106:                return (fd == null && fd1 == null) ? true : false;
107:            }
108:
109:            protected void close() {
110:                if (fd != null || fd1 != null) {
111:                    datagramSocketClose();
112:                    fd = null;
113:                    fd1 = null;
114:                }
115:            }
116:
117:            /* Native methods */
118:
119:            protected synchronized native void bind0(int lport,
120:                    InetAddress laddr) throws SocketException;
121:
122:            protected native void send(DatagramPacket p) throws IOException;
123:
124:            protected synchronized native int peek(InetAddress i)
125:                    throws IOException;
126:
127:            protected synchronized native int peekData(DatagramPacket p)
128:                    throws IOException;
129:
130:            protected synchronized native void receive0(DatagramPacket p)
131:                    throws IOException;
132:
133:            protected native void setTimeToLive(int ttl) throws IOException;
134:
135:            protected native int getTimeToLive() throws IOException;
136:
137:            protected native void setTTL(byte ttl) throws IOException;
138:
139:            protected native byte getTTL() throws IOException;
140:
141:            protected native void join(InetAddress inetaddr,
142:                    NetworkInterface netIf) throws IOException;
143:
144:            protected native void leave(InetAddress inetaddr,
145:                    NetworkInterface netIf) throws IOException;
146:
147:            protected native void datagramSocketCreate() throws SocketException;
148:
149:            protected native void datagramSocketClose();
150:
151:            protected native void socketSetOption(int opt, Object val)
152:                    throws SocketException;
153:
154:            protected native Object socketGetOption(int opt)
155:                    throws SocketException;
156:
157:            protected native void connect0(InetAddress address, int port)
158:                    throws SocketException;
159:
160:            protected native void disconnect0(int family);
161:
162:            /**
163:             * Perform class load-time initializations.
164:             */
165:            private native static void init();
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.