Source Code Cross Referenced for NonblockingSocketImpl.java in  » Web-Server » Rimfaxe-Web-Server » seda » nbio » 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 » Web Server » Rimfaxe Web Server » seda.nbio 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright (c) 2001 by Matt Welsh and The Regents of the University of 
003:         * California. All rights reserved.
004:         *
005:         * Permission to use, copy, modify, and distribute this software and its
006:         * documentation for any purpose, without fee, and without written agreement is
007:         * hereby granted, provided that the above copyright notice and the following
008:         * two paragraphs appear in all copies of this software.
009:         * 
010:         * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011:         * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012:         * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013:         * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014:         * 
015:         * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016:         * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017:         * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
018:         * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019:         * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020:         *
021:         * Author: Matt Welsh <mdw@cs.berkeley.edu>
022:         * 
023:         */
024:
025:        package seda.nbio;
026:
027:        import java.io.*;
028:        import java.net.*;
029:
030:        class NonblockingSocketImpl {
031:
032:            private NBIOFileDescriptor fd;
033:            private InetAddress address;
034:            private int port;
035:            private int localport;
036:
037:            private native void nbSocketCreate(boolean stream);
038:
039:            private native void nbSocketConnect(InetAddress address, int port)
040:                    throws IOException;
041:
042:            private native boolean nbSocketConnectDone() throws SocketException;
043:
044:            private native void nbSocketBind(InetAddress address, int port)
045:                    throws IOException;
046:
047:            private native void nbSocketListen(int count) throws IOException;
048:
049:            private native int nbSocketAccept(NonblockingSocketImpl s,
050:                    boolean block) throws IOException;
051:
052:            private native int nbSocketAvailable() throws IOException;
053:
054:            private native void nbSocketClose() throws IOException;
055:
056:            private native int nbSendTo(DatagramPacket p) throws IOException;
057:
058:            private native int nbReceive(DatagramPacket p) throws IOException;
059:
060:            private native void nbDisconnect() throws SocketException;
061:
062:            // Multicast support
063:            private native void nbJoinGroup(InetAddress address)
064:                    throws IOException;
065:
066:            private native void nbLeaveGroup(InetAddress address)
067:                    throws IOException;
068:
069:            private native void nbSetTimeToLive(int ttl) throws IOException;
070:
071:            private native int nbGetTimeToLive() throws IOException;
072:
073:            private native void nbSetInterface(InetAddress address)
074:                    throws IOException;
075:
076:            private native void nbSeeLocalMessages(boolean state)
077:                    throws IOException;
078:
079:            NonblockingSocketImpl() {
080:                fd = new NBIOFileDescriptor();
081:            }
082:
083:            NonblockingSocketImpl(InetAddress address) {
084:                this ();
085:                this .address = address;
086:            }
087:
088:            protected void create(boolean stream) throws IOException {
089:                nbSocketCreate(stream);
090:            }
091:
092:            protected void connect(String host, int port) throws IOException {
093:                try {
094:                    InetAddress address = InetAddress.getByName(host);
095:                    this .address = address;
096:                    this .port = port;
097:                    try {
098:                        nbSocketConnect(address, port);
099:                        return;
100:                    } catch (IOException e) {
101:                        close();
102:                        throw e;
103:                    }
104:                } catch (UnknownHostException e) {
105:                    close();
106:                    throw e;
107:                }
108:            }
109:
110:            protected void connect(InetAddress address, int port)
111:                    throws IOException {
112:                this .address = address;
113:                this .port = port;
114:                try {
115:                    nbSocketConnect(address, port);
116:                } catch (IOException e) {
117:                    close();
118:                    throw e;
119:                }
120:            }
121:
122:            protected boolean connectDone() throws SocketException {
123:                return nbSocketConnectDone();
124:            }
125:
126:            protected void bind(InetAddress host, int port) throws IOException {
127:                nbSocketBind(host, port);
128:            }
129:
130:            protected void listen(int backlog) throws IOException {
131:                nbSocketListen(backlog);
132:            }
133:
134:            protected void accept(NonblockingSocketImpl s) throws IOException {
135:                if (nbSocketAccept(s, true) < 0)
136:                    throw new IOException("Blocking accept() returned error");
137:            }
138:
139:            protected int nbAccept(NonblockingSocketImpl s) throws IOException {
140:                return nbSocketAccept(s, false);
141:            }
142:
143:            protected InputStream getInputStream() throws IOException {
144:                return new NonblockingSocketInputStream(this );
145:            }
146:
147:            protected OutputStream getOutputStream() throws IOException {
148:                return new NonblockingSocketOutputStream(this );
149:            }
150:
151:            protected int available() throws IOException {
152:                return nbSocketAvailable();
153:            }
154:
155:            protected void close() throws IOException {
156:                if (fd != null) {
157:                    nbSocketClose();
158:                    fd = null;
159:                }
160:            }
161:
162:            protected void finalize() throws IOException {
163:                close();
164:            }
165:
166:            protected InetAddress getInetAddress() {
167:                return address;
168:            }
169:
170:            protected int getPort() {
171:                return port;
172:            }
173:
174:            protected int getLocalPort() {
175:                return localport;
176:            }
177:
178:            public void setOption(int optID, Object value)
179:                    throws SocketException {
180:                // XXX MDW Do nothing
181:            }
182:
183:            public Object getOption(int optID) throws SocketException {
184:                // XXX MDW Need to implement
185:                return new Boolean(false);
186:            }
187:
188:            protected int send(DatagramPacket p) throws IOException {
189:                return nbSendTo(p);
190:            }
191:
192:            protected int receive(DatagramPacket p) throws IOException {
193:                return nbReceive(p);
194:            }
195:
196:            protected void disconnect() throws IOException {
197:                nbDisconnect();
198:            }
199:
200:            public String toString() {
201:                return "NonblockingSocketImpl";
202:            }
203:
204:            protected NBIOFileDescriptor getFileDescriptor() {
205:                return fd;
206:            }
207:
208:            // Multicast support
209:            protected void joinGroup(InetAddress address) throws IOException {
210:                nbJoinGroup(address);
211:            }
212:
213:            protected void leaveGroup(InetAddress address) throws IOException {
214:                nbLeaveGroup(address);
215:            }
216:
217:            protected void setTimeToLive(int ttl) throws IOException {
218:                nbSetTimeToLive(ttl);
219:            }
220:
221:            protected int getTimeToLive() throws IOException {
222:                return nbGetTimeToLive();
223:            }
224:
225:            protected void setInterface(InetAddress addr) throws IOException {
226:                // null -> INADDR_ANY
227:                nbSetInterface(addr);
228:            }
229:
230:            protected void seeLocalMessages(boolean state) throws IOException {
231:                nbSeeLocalMessages(state);
232:            }
233:
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.