Source Code Cross Referenced for OSNetworkSystem.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » platform » 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 » Apache Harmony Java SE » org package » org.apache.harmony.luni.platform 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.harmony.luni.platform;
019:
020:        import java.io.FileDescriptor;
021:        import java.io.IOException;
022:        import java.net.DatagramPacket;
023:        import java.net.InetAddress;
024:        import java.net.SocketException;
025:        import java.net.SocketImpl;
026:        import java.net.UnknownHostException;
027:        import java.nio.channels.Channel;
028:
029:        /*
030:         * 
031:         * This Class is used for native code wrap, the implement class of
032:         * INetworkSystem.
033:         * 
034:         */
035:        final class OSNetworkSystem implements  INetworkSystem {
036:
037:            // ----------------------------------------------------
038:            // Class Variables
039:            // ----------------------------------------------------
040:
041:            private static final int ERRORCODE_SOCKET_TIMEOUT = -209;
042:
043:            private static OSNetworkSystem ref = new OSNetworkSystem();
044:
045:            private static final int INETADDR_REACHABLE = 0;
046:
047:            private static boolean isNetworkInited = false;
048:
049:            // ----------------------------------------------------
050:            // Class Constructor
051:            // ----------------------------------------------------
052:
053:            // can not be instantiated.
054:            private OSNetworkSystem() {
055:                super ();
056:            }
057:
058:            /*
059:             * @return a static ref of this class
060:             */
061:            public static OSNetworkSystem getOSNetworkSystem() {
062:                return ref;
063:            }
064:
065:            // --------------------------------------------------
066:            // java codes that wrap native codes
067:            // --------------------------------------------------
068:
069:            public void createSocket(FileDescriptor fd, boolean preferIPv4Stack)
070:                    throws IOException {
071:                createSocketImpl(fd, preferIPv4Stack);
072:            }
073:
074:            public void createDatagramSocket(FileDescriptor fd,
075:                    boolean preferIPv4Stack) throws SocketException {
076:                createDatagramSocketImpl(fd, preferIPv4Stack);
077:            }
078:
079:            public int read(FileDescriptor aFD, byte[] data, int offset,
080:                    int count, int timeout) throws IOException {
081:                return readSocketImpl(aFD, data, offset, count, timeout);
082:            }
083:
084:            public int readDirect(FileDescriptor aFD, long address, int count,
085:                    int timeout) throws IOException {
086:                return readSocketDirectImpl(aFD, address, count, timeout);
087:            }
088:
089:            public int write(FileDescriptor aFD, byte[] data, int offset,
090:                    int count) throws IOException {
091:                return writeSocketImpl(aFD, data, offset, count);
092:            }
093:
094:            public int writeDirect(FileDescriptor aFD, long address, int count)
095:                    throws IOException {
096:                return writeSocketDirectImpl(aFD, address, count);
097:            }
098:
099:            public void setNonBlocking(FileDescriptor aFD, boolean block)
100:                    throws IOException {
101:                setNonBlockingImpl(aFD, block);
102:            }
103:
104:            public void connectDatagram(FileDescriptor aFD, int port,
105:                    int trafficClass, InetAddress inetAddress)
106:                    throws SocketException {
107:                connectDatagramImpl2(aFD, port, trafficClass, inetAddress);
108:            }
109:
110:            public int connect(FileDescriptor aFD, int trafficClass,
111:                    InetAddress inetAddress, int port) throws IOException {
112:                return connectSocketImpl(aFD, trafficClass, inetAddress, port);
113:            }
114:
115:            public int connectWithTimeout(FileDescriptor aFD, int timeout,
116:                    int trafficClass, InetAddress inetAddress, int port,
117:                    int step, Long context) throws IOException {
118:                return connectWithTimeoutSocketImpl(aFD, timeout, trafficClass,
119:                        inetAddress, port, step, context);
120:            }
121:
122:            public void connectStreamWithTimeoutSocket(FileDescriptor aFD,
123:                    int aport, int timeout, int trafficClass,
124:                    InetAddress inetAddress) throws IOException {
125:                connectStreamWithTimeoutSocketImpl(aFD, aport, timeout,
126:                        trafficClass, inetAddress);
127:            }
128:
129:            public void bind(FileDescriptor aFD, int port,
130:                    InetAddress inetAddress) throws SocketException {
131:                socketBindImpl(aFD, port, inetAddress);
132:            }
133:
134:            public boolean bind2(FileDescriptor aFD, int port,
135:                    boolean bindToDevice, InetAddress inetAddress)
136:                    throws SocketException {
137:                return socketBindImpl2(aFD, port, bindToDevice, inetAddress);
138:            }
139:
140:            public void accept(FileDescriptor fdServer, SocketImpl newSocket,
141:                    FileDescriptor fdnewSocket, int timeout) throws IOException {
142:                acceptSocketImpl(fdServer, newSocket, fdnewSocket, timeout);
143:            }
144:
145:            public int sendDatagram(FileDescriptor fd, byte[] data, int offset,
146:                    int length, int port, boolean bindToDevice,
147:                    int trafficClass, InetAddress inetAddress)
148:                    throws IOException {
149:                return sendDatagramImpl(fd, data, offset, length, port,
150:                        bindToDevice, trafficClass, inetAddress);
151:            }
152:
153:            public int sendDatagramDirect(FileDescriptor fd, long address,
154:                    int offset, int length, int port, boolean bindToDevice,
155:                    int trafficClass, InetAddress inetAddress)
156:                    throws IOException {
157:                return sendDatagramDirectImpl(fd, address, offset, length,
158:                        port, bindToDevice, trafficClass, inetAddress);
159:            }
160:
161:            public int sendDatagram2(FileDescriptor fd, byte[] data,
162:                    int offset, int length, int port, InetAddress inetAddress)
163:                    throws IOException {
164:                return sendDatagramImpl2(fd, data, offset, length, port,
165:                        inetAddress);
166:            }
167:
168:            public int receiveDatagram(FileDescriptor aFD,
169:                    DatagramPacket packet, byte[] data, int offset, int length,
170:                    int receiveTimeout, boolean peek) throws IOException {
171:                return receiveDatagramImpl(aFD, packet, data, offset, length,
172:                        receiveTimeout, peek);
173:            }
174:
175:            public int receiveDatagramDirect(FileDescriptor aFD,
176:                    DatagramPacket packet, long address, int offset,
177:                    int length, int receiveTimeout, boolean peek)
178:                    throws IOException {
179:                return receiveDatagramDirectImpl(aFD, packet, address, offset,
180:                        length, receiveTimeout, peek);
181:            }
182:
183:            public int recvConnectedDatagram(FileDescriptor aFD,
184:                    DatagramPacket packet, byte[] data, int offset, int length,
185:                    int receiveTimeout, boolean peek) throws IOException {
186:                return recvConnectedDatagramImpl(aFD, packet, data, offset,
187:                        length, receiveTimeout, peek);
188:            }
189:
190:            public int recvConnectedDatagramDirect(FileDescriptor aFD,
191:                    DatagramPacket packet, long address, int offset,
192:                    int length, int receiveTimeout, boolean peek)
193:                    throws IOException {
194:                return recvConnectedDatagramDirectImpl(aFD, packet, address,
195:                        offset, length, receiveTimeout, peek);
196:            }
197:
198:            public int peekDatagram(FileDescriptor aFD, InetAddress sender,
199:                    int receiveTimeout) throws IOException {
200:                return peekDatagramImpl(aFD, sender, receiveTimeout);
201:            }
202:
203:            public int sendConnectedDatagram(FileDescriptor fd, byte[] data,
204:                    int offset, int length, boolean bindToDevice)
205:                    throws IOException {
206:                return sendConnectedDatagramImpl(fd, data, offset, length,
207:                        bindToDevice);
208:            }
209:
210:            public int sendConnectedDatagramDirect(FileDescriptor fd,
211:                    long address, int offset, int length, boolean bindToDevice)
212:                    throws IOException {
213:                return sendConnectedDatagramDirectImpl(fd, address, offset,
214:                        length, bindToDevice);
215:            }
216:
217:            public void disconnectDatagram(FileDescriptor aFD)
218:                    throws SocketException {
219:                disconnectDatagramImpl(aFD);
220:            }
221:
222:            public void createMulticastSocket(FileDescriptor aFD,
223:                    boolean preferIPv4Stack) throws SocketException {
224:                createMulticastSocketImpl(aFD, preferIPv4Stack);
225:            }
226:
227:            public void createServerStreamSocket(FileDescriptor aFD,
228:                    boolean preferIPv4Stack) throws SocketException {
229:                createServerStreamSocketImpl(aFD, preferIPv4Stack);
230:            }
231:
232:            public int receiveStream(FileDescriptor aFD, byte[] data,
233:                    int offset, int count, int timeout) throws IOException {
234:                return receiveStreamImpl(aFD, data, offset, count, timeout);
235:            }
236:
237:            public int sendStream(FileDescriptor fd, byte[] data, int offset,
238:                    int count) throws IOException {
239:                return sendStreamImpl(fd, data, offset, count);
240:            }
241:
242:            public void shutdownInput(FileDescriptor descriptor)
243:                    throws IOException {
244:                shutdownInputImpl(descriptor);
245:            }
246:
247:            public void shutdownOutput(FileDescriptor descriptor)
248:                    throws IOException {
249:                shutdownOutputImpl(descriptor);
250:            }
251:
252:            public boolean supportsUrgentData(FileDescriptor fd) {
253:                return supportsUrgentDataImpl(fd);
254:            }
255:
256:            public void sendUrgentData(FileDescriptor fd, byte value) {
257:                sendUrgentDataImpl(fd, value);
258:            }
259:
260:            public int availableStream(FileDescriptor aFD)
261:                    throws SocketException {
262:                return availableStreamImpl(aFD);
263:            }
264:
265:            public void acceptStreamSocket(FileDescriptor fdServer,
266:                    SocketImpl newSocket, FileDescriptor fdnewSocket,
267:                    int timeout) throws IOException {
268:                acceptStreamSocketImpl(fdServer, newSocket, fdnewSocket,
269:                        timeout);
270:            }
271:
272:            public void createStreamSocket(FileDescriptor aFD,
273:                    boolean preferIPv4Stack) throws SocketException {
274:                createStreamSocketImpl(aFD, preferIPv4Stack);
275:            }
276:
277:            public void listenStreamSocket(FileDescriptor aFD, int backlog)
278:                    throws SocketException {
279:                listenStreamSocketImpl(aFD, backlog);
280:            }
281:
282:            public boolean isReachableByICMP(final InetAddress dest,
283:                    InetAddress source, final int ttl, final int timeout) {
284:                return INETADDR_REACHABLE == isReachableByICMPImpl(dest,
285:                        source, ttl, timeout);
286:            }
287:
288:            /**
289:             * Select the given file descriptors for read and write operations.
290:             * 
291:             * The file descriptors passed in as readFDs will be selected for read-ready
292:             * operations, and those in the writeFDs will be selected for write-ready
293:             * operations. A file descriptor can appear in either or both array, and
294:             * must not be <code>null</code>. If the file descriptor is closed during
295:             * the select the behavior depends upon the underlying OS.
296:             * 
297:             * Upon return the result is a single array of length
298:             * <code>readFDs.length</code> + <code>writeFDs.length</code> laid out
299:             * as the result of the select operation on the corresponding file
300:             * descriptors.
301:             * 
302:             * @param readChannels
303:             *            all channels interested in read and accept
304:             * @param writeChannels
305:             *            all channels interested in write and connect
306:             * @param timeout
307:             *            timeout in millis
308:             * @returns int array, each element describes the corresponding state of the
309:             *          descriptor in the read and write arrays.
310:             * @throws SocketException
311:             */
312:            public int[] select(FileDescriptor[] readFDs,
313:                    FileDescriptor[] writeFDs, long timeout)
314:                    throws SocketException {
315:                int countRead = readFDs.length;
316:                int countWrite = writeFDs.length;
317:                int result = 0;
318:                if (0 == countRead + countWrite) {
319:                    return (new int[0]);
320:                }
321:                int[] flags = new int[countRead + countWrite];
322:
323:                assert validateFDs(readFDs, writeFDs) : "Invalid file descriptor arrays";
324:
325:                // handle timeout in native
326:                result = selectImpl(readFDs, writeFDs, countRead, countWrite,
327:                        flags, timeout);
328:
329:                if (0 <= result) {
330:                    return flags;
331:                }
332:                if (ERRORCODE_SOCKET_TIMEOUT == result) {
333:                    return new int[0];
334:                }
335:                throw new SocketException();
336:            }
337:
338:            /*
339:             * Used to check if the file descriptor arrays are valid before passing them
340:             * into the select native call.
341:             */
342:            private boolean validateFDs(FileDescriptor[] readFDs,
343:                    FileDescriptor[] writeFDs) {
344:                for (FileDescriptor fd : readFDs) {
345:                    // Also checks fd not null
346:                    if (!fd.valid()) {
347:                        return false;
348:                    }
349:                }
350:                for (FileDescriptor fd : writeFDs) {
351:                    if (!fd.valid()) {
352:                        return false;
353:                    }
354:                }
355:                return true;
356:            }
357:
358:            public InetAddress getSocketLocalAddress(FileDescriptor aFD,
359:                    boolean preferIPv6Addresses) {
360:                return getSocketLocalAddressImpl(aFD, preferIPv6Addresses);
361:            }
362:
363:            /*
364:             * Query the IP stack for the local port to which this socket is bound.
365:             * 
366:             * @param aFD the socket descriptor @param preferIPv6Addresses address
367:             * preference for nodes that support both IPv4 and IPv6 @return int the
368:             * local port to which the socket is bound
369:             */
370:            public int getSocketLocalPort(FileDescriptor aFD,
371:                    boolean preferIPv6Addresses) {
372:                return getSocketLocalPortImpl(aFD, preferIPv6Addresses);
373:            }
374:
375:            /*
376:             * Query the IP stack for the nominated socket option.
377:             * 
378:             * @param aFD the socket descriptor @param opt the socket option type
379:             * @return the nominated socket option value
380:             * 
381:             * @throws SocketException if the option is invalid
382:             */
383:            public Object getSocketOption(FileDescriptor aFD, int opt)
384:                    throws SocketException {
385:                return getSocketOptionImpl(aFD, opt);
386:            }
387:
388:            /*
389:             * Set the nominated socket option in the IP stack.
390:             * 
391:             * @param aFD the socket descriptor @param opt the option selector @param
392:             * optVal the nominated option value
393:             * 
394:             * @throws SocketException if the option is invalid or cannot be set
395:             */
396:            public void setSocketOption(FileDescriptor aFD, int opt,
397:                    Object optVal) throws SocketException {
398:                setSocketOptionImpl(aFD, opt, optVal);
399:            }
400:
401:            public int getSocketFlags() {
402:                return getSocketFlagsImpl();
403:            }
404:
405:            /*
406:             * Close the socket in the IP stack.
407:             * 
408:             * @param aFD the socket descriptor
409:             */
410:            public void socketClose(FileDescriptor aFD) throws IOException {
411:                socketCloseImpl(aFD);
412:            }
413:
414:            public InetAddress getHostByAddr(byte[] addr)
415:                    throws UnknownHostException {
416:                return getHostByAddrImpl(addr);
417:            }
418:
419:            public InetAddress getHostByName(String addr,
420:                    boolean preferIPv6Addresses) throws UnknownHostException {
421:                return getHostByNameImpl(addr, preferIPv6Addresses);
422:            }
423:
424:            public void setInetAddress(InetAddress sender, byte[] address) {
425:                setInetAddressImpl(sender, address);
426:            }
427:
428:            // ---------------------------------------------------
429:            // Native Codes
430:            // ---------------------------------------------------
431:
432:            static native void createSocketImpl(FileDescriptor fd,
433:                    boolean preferIPv4Stack);
434:
435:            /*
436:             * Allocate a datagram socket in the IP stack. The socket is associated with
437:             * the <code>aFD</code>.
438:             * 
439:             * @param aFD the FileDescriptor to associate with the socket @param
440:             * preferIPv4Stack IP stack preference if underlying platform is V4/V6
441:             * @exception SocketException upon an allocation error
442:             */
443:            static native void createDatagramSocketImpl(FileDescriptor aFD,
444:                    boolean preferIPv4Stack) throws SocketException;
445:
446:            static native int readSocketImpl(FileDescriptor aFD, byte[] data,
447:                    int offset, int count, int timeout) throws IOException;
448:
449:            static native int readSocketDirectImpl(FileDescriptor aFD,
450:                    long address, int count, int timeout) throws IOException;
451:
452:            static native int writeSocketImpl(FileDescriptor fd, byte[] data,
453:                    int offset, int count) throws IOException;
454:
455:            static native int writeSocketDirectImpl(FileDescriptor fd,
456:                    long address, int count) throws IOException;
457:
458:            static native void setNonBlockingImpl(FileDescriptor aFD,
459:                    boolean block);
460:
461:            static native int connectSocketImpl(FileDescriptor aFD,
462:                    int trafficClass, InetAddress inetAddress, int port);
463:
464:            static native int connectWithTimeoutSocketImpl(FileDescriptor aFD,
465:                    int timeout, int trafficClass, InetAddress hostname,
466:                    int port, int step, Long context);
467:
468:            static native void connectStreamWithTimeoutSocketImpl(
469:                    FileDescriptor aFD, int aport, int timeout,
470:                    int trafficClass, InetAddress inetAddress)
471:                    throws IOException;
472:
473:            static native void socketBindImpl(FileDescriptor aFD, int port,
474:                    InetAddress inetAddress) throws SocketException;
475:
476:            static native void listenStreamSocketImpl(FileDescriptor aFD,
477:                    int backlog) throws SocketException;
478:
479:            static native int availableStreamImpl(FileDescriptor aFD)
480:                    throws SocketException;
481:
482:            static native void acceptSocketImpl(FileDescriptor fdServer,
483:                    SocketImpl newSocket, FileDescriptor fdnewSocket,
484:                    int timeout) throws IOException;
485:
486:            static native boolean supportsUrgentDataImpl(FileDescriptor fd);
487:
488:            static native void sendUrgentDataImpl(FileDescriptor fd, byte value);
489:
490:            /*
491:             * Connect the socket to a port and address
492:             * 
493:             * @param aFD the FileDescriptor to associate with the socket @param port
494:             * the port to connect to @param trafficClass the traffic Class to be used
495:             * then the connection is made @param inetAddress address to connect to.
496:             * 
497:             * @exception SocketException if the connect fails
498:             */
499:            static native void connectDatagramImpl2(FileDescriptor aFD,
500:                    int port, int trafficClass, InetAddress inetAddress)
501:                    throws SocketException;
502:
503:            /*
504:             * Disconnect the socket to a port and address
505:             * 
506:             * @param aFD the FileDescriptor to associate with the socket
507:             * 
508:             * @exception SocketException if the disconnect fails
509:             */
510:            static native void disconnectDatagramImpl(FileDescriptor aFD)
511:                    throws SocketException;
512:
513:            /*
514:             * Allocate a datagram socket in the IP stack. The socket is associated with
515:             * the <code>aFD</code>.
516:             * 
517:             * @param aFD the FileDescriptor to associate with the socket @param
518:             * preferIPv4Stack IP stack preference if underlying platform is V4/V6
519:             * @exception SocketException upon an allocation error
520:             */
521:
522:            /*
523:             * Bind the socket to the port/localhost in the IP stack.
524:             * 
525:             * @param aFD the socket descriptor @param port the option selector @param
526:             * bindToDevice bind the socket to the specified interface @param
527:             * inetAddress address to connect to. @return if bind successful @exception
528:             * SocketException thrown if bind operation fails
529:             */
530:            static native boolean socketBindImpl2(FileDescriptor aFD, int port,
531:                    boolean bindToDevice, InetAddress inetAddress)
532:                    throws SocketException;
533:
534:            /*
535:             * Peek on the socket, update <code>sender</code> address and answer the
536:             * sender port.
537:             * 
538:             * @param aFD the socket FileDescriptor @param sender an InetAddress, to be
539:             * updated with the sender's address @param receiveTimeout the maximum
540:             * length of time the socket should block, reading @return int the sender
541:             * port
542:             * 
543:             * @exception IOException upon an read error or timeout
544:             */
545:            static native int peekDatagramImpl(FileDescriptor aFD,
546:                    InetAddress sender, int receiveTimeout) throws IOException;
547:
548:            /*
549:             * Recieve data on the socket into the specified buffer. The packet fields
550:             * <code>data</code> & <code>length</code> are passed in addition to
551:             * <code>packet</code> to eliminate the JNI field access calls.
552:             * 
553:             * @param aFD the socket FileDescriptor @param packet the DatagramPacket to
554:             * receive into @param data the data buffer of the packet @param offset the
555:             * offset in the data buffer @param length the length of the data buffer in
556:             * the packet @param receiveTimeout the maximum length of time the socket
557:             * should block, reading @param peek indicates to peek at the data @return
558:             * number of data received @exception IOException upon an read error or
559:             * timeout
560:             */
561:            static native int receiveDatagramImpl(FileDescriptor aFD,
562:                    DatagramPacket packet, byte[] data, int offset, int length,
563:                    int receiveTimeout, boolean peek) throws IOException;
564:
565:            static native int receiveDatagramDirectImpl(FileDescriptor aFD,
566:                    DatagramPacket packet, long address, int offset,
567:                    int length, int receiveTimeout, boolean peek)
568:                    throws IOException;
569:
570:            /*
571:             * Recieve data on the connected socket into the specified buffer. The
572:             * packet fields <code>data</code> & <code>length</code> are passed in
573:             * addition to <code>packet</code> to eliminate the JNI field access
574:             * calls.
575:             * 
576:             * @param aFD the socket FileDescriptor @param packet the DatagramPacket to
577:             * receive into @param data the data buffer of the packet @param offset the
578:             * offset in the data buffer @param length the length of the data buffer in
579:             * the packet @param receiveTimeout the maximum length of time the socket
580:             * should block, reading @param peek indicates to peek at the data @return
581:             * number of data received @exception IOException upon an read error or
582:             * timeout
583:             */
584:            static native int recvConnectedDatagramImpl(FileDescriptor aFD,
585:                    DatagramPacket packet, byte[] data, int offset, int length,
586:                    int receiveTimeout, boolean peek) throws IOException;
587:
588:            static native int recvConnectedDatagramDirectImpl(
589:                    FileDescriptor aFD, DatagramPacket packet, long address,
590:                    int offset, int length, int receiveTimeout, boolean peek)
591:                    throws IOException;
592:
593:            /*
594:             * Send the <code>data</code> to the nominated target <code>address</code>
595:             * and <code>port</code>. These values are derived from the
596:             * DatagramPacket to reduce the field calls within JNI.
597:             * 
598:             * @param fd the socket FileDescriptor @param data the data buffer of the
599:             * packet @param offset the offset in the data buffer @param length the
600:             * length of the data buffer in the packet @param port the target host port
601:             * @param bindToDevice if bind to device @param trafficClass the traffic
602:             * class to be used when the datagram is sent @param inetAddress address to
603:             * connect to. @return number of data send
604:             * 
605:             * @exception IOException upon an read error or timeout
606:             */
607:            static native int sendDatagramImpl(FileDescriptor fd, byte[] data,
608:                    int offset, int length, int port, boolean bindToDevice,
609:                    int trafficClass, InetAddress inetAddress)
610:                    throws IOException;
611:
612:            static native int sendDatagramDirectImpl(FileDescriptor fd,
613:                    long address, int offset, int length, int port,
614:                    boolean bindToDevice, int trafficClass,
615:                    InetAddress inetAddress) throws IOException;
616:
617:            /*
618:             * Send the <code>data</code> to the address and port to which the was
619:             * connnected and <code>port</code>.
620:             * 
621:             * @param fd the socket FileDescriptor @param data the data buffer of the
622:             * packet @param offset the offset in the data buffer @param length the
623:             * length of the data buffer in the packet @param bindToDevice not used,
624:             * current kept in case needed as was the case for sendDatagramImpl @return
625:             * number of data send @exception IOException upon an read error or timeout
626:             */
627:            static native int sendConnectedDatagramImpl(FileDescriptor fd,
628:                    byte[] data, int offset, int length, boolean bindToDevice)
629:                    throws IOException;
630:
631:            static native int sendConnectedDatagramDirectImpl(
632:                    FileDescriptor fd, long address, int offset, int length,
633:                    boolean bindToDevice) throws IOException;
634:
635:            /*
636:             * Answer the result of attempting to create a server stream socket in the
637:             * IP stack. Any special options required for server sockets will be set by
638:             * this method.
639:             * 
640:             * @param aFD the socket FileDescriptor @param preferIPv4Stack if use IPV4
641:             * @exception SocketException if an error occurs while creating the socket
642:             */
643:            static native void createServerStreamSocketImpl(FileDescriptor aFD,
644:                    boolean preferIPv4Stack) throws SocketException;
645:
646:            /*
647:             * Answer the result of attempting to create a multicast socket in the IP
648:             * stack. Any special options required for server sockets will be set by
649:             * this method.
650:             * 
651:             * @param aFD the socket FileDescriptor @param preferIPv4Stack if use IPV4
652:             * @exception SocketException if an error occurs while creating the socket
653:             */
654:            static native void createMulticastSocketImpl(FileDescriptor aFD,
655:                    boolean preferIPv4Stack) throws SocketException;
656:
657:            /*
658:             * Recieve at most <code>count</code> bytes into the buffer <code>data</code>
659:             * at the <code>offset</code> on the socket.
660:             * 
661:             * @param aFD the socket FileDescriptor @param data the receive buffer
662:             * @param offset the offset into the buffer @param count the max number of
663:             * bytes to receive @param timeout the max time the read operation should
664:             * block waiting for data @return int the actual number of bytes read
665:             * @throws IOException @exception SocketException if an error occurs while
666:             * reading
667:             */
668:            static native int receiveStreamImpl(FileDescriptor aFD,
669:                    byte[] data, int offset, int count, int timeout)
670:                    throws IOException;
671:
672:            /*
673:             * Send <code>count</code> bytes from the buffer <code>data</code> at
674:             * the <code>offset</code>, on the socket.
675:             * 
676:             * @param fd
677:             * 
678:             * @param data the send buffer @param offset the offset into the buffer
679:             * @param count the number of bytes to receive @return int the actual number
680:             * of bytes sent @throws IOException @exception SocketException if an error
681:             * occurs while writing
682:             */
683:            static native int sendStreamImpl(FileDescriptor fd, byte[] data,
684:                    int offset, int count) throws IOException;
685:
686:            private native void shutdownInputImpl(FileDescriptor descriptor)
687:                    throws IOException;
688:
689:            private native void shutdownOutputImpl(FileDescriptor descriptor)
690:                    throws IOException;
691:
692:            static native void acceptStreamSocketImpl(FileDescriptor fdServer,
693:                    SocketImpl newSocket, FileDescriptor fdnewSocket,
694:                    int timeout) throws IOException;
695:
696:            static native void createStreamSocketImpl(FileDescriptor aFD,
697:                    boolean preferIPv4Stack) throws SocketException;
698:
699:            static native int sendDatagramImpl2(FileDescriptor fd, byte[] data,
700:                    int offset, int length, int port, InetAddress inetAddress)
701:                    throws IOException;
702:
703:            static native int selectImpl(FileDescriptor[] readfd,
704:                    FileDescriptor[] writefd, int cread, int cwirte,
705:                    int[] flags, long timeout);
706:
707:            static native InetAddress getSocketLocalAddressImpl(
708:                    FileDescriptor aFD, boolean preferIPv6Addresses);
709:
710:            /*
711:             * Query the IP stack for the local port to which this socket is bound.
712:             * 
713:             * @param aFD the socket descriptor @param preferIPv6Addresses address
714:             * preference for nodes that support both IPv4 and IPv6 @return int the
715:             * local port to which the socket is bound
716:             */
717:            static native int getSocketLocalPortImpl(FileDescriptor aFD,
718:                    boolean preferIPv6Addresses);
719:
720:            /*
721:             * Query the IP stack for the nominated socket option.
722:             * 
723:             * @param aFD the socket descriptor @param opt the socket option type
724:             * @return the nominated socket option value
725:             * 
726:             * @throws SocketException if the option is invalid
727:             */
728:            static native Object getSocketOptionImpl(FileDescriptor aFD, int opt)
729:                    throws SocketException;
730:
731:            /*
732:             * Set the nominated socket option in the IP stack.
733:             * 
734:             * @param aFD the socket descriptor @param opt the option selector @param
735:             * optVal the nominated option value
736:             * 
737:             * @throws SocketException if the option is invalid or cannot be set
738:             */
739:            static native void setSocketOptionImpl(FileDescriptor aFD, int opt,
740:                    Object optVal) throws SocketException;
741:
742:            static native int getSocketFlagsImpl();
743:
744:            /*
745:             * Close the socket in the IP stack.
746:             * 
747:             * @param aFD the socket descriptor
748:             */
749:            static native void socketCloseImpl(FileDescriptor aFD);
750:
751:            static native InetAddress getHostByAddrImpl(byte[] addr)
752:                    throws UnknownHostException;
753:
754:            static native InetAddress getHostByNameImpl(String addr,
755:                    boolean preferIPv6Addresses) throws UnknownHostException;
756:
757:            native void setInetAddressImpl(InetAddress sender, byte[] address);
758:
759:            native int isReachableByICMPImpl(InetAddress addr,
760:                    InetAddress local, int ttl, int timeout);
761:
762:            native Channel inheritedChannelImpl();
763:
764:            public Channel inheritedChannel() {
765:                return inheritedChannelImpl();
766:            }
767:
768:            public void oneTimeInitialization(boolean jcl_supports_ipv6) {
769:                if (!isNetworkInited) {
770:                    oneTimeInitializationImpl(jcl_supports_ipv6);
771:                    isNetworkInited = true;
772:                }
773:            }
774:
775:            native void oneTimeInitializationImpl(boolean jcl_supports_ipv6);
776:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.