OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / main / java / org / apache / harmony / luni / platform / INetworkSystem.java
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 // BEGIN android-note
19 // address length was changed from long to int for performance reasons.
20 // END android-note
21
22 package org.apache.harmony.luni.platform;
23
24 import java.io.FileDescriptor;
25 import java.io.IOException;
26 import java.net.DatagramPacket;
27 import java.net.InetAddress;
28 import java.net.SocketException;
29 import java.net.SocketImpl;
30
31 /*
32  * The interface for network methods.
33  */
34 public interface INetworkSystem {
35     public void accept(FileDescriptor serverFd, SocketImpl newSocket, FileDescriptor clientFd)
36             throws IOException;
37
38     public void bind(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException;
39
40     public int read(FileDescriptor fd, byte[] data, int offset, int count) throws IOException;
41
42     public int readDirect(FileDescriptor fd, int address, int count) throws IOException;
43
44     public int write(FileDescriptor fd, byte[] data, int offset, int count) throws IOException;
45
46     public int writeDirect(FileDescriptor fd, int address, int offset, int count) throws IOException;
47
48     public boolean connectNonBlocking(FileDescriptor fd, InetAddress inetAddress, int port)
49             throws IOException;
50     public boolean isConnected(FileDescriptor fd, int timeout) throws IOException;
51
52     public int send(FileDescriptor fd, byte[] data, int offset, int length,
53             int port, InetAddress inetAddress) throws IOException;
54     public int sendDirect(FileDescriptor fd, int address, int offset, int length,
55             int port, InetAddress inetAddress) throws IOException;
56
57     public int recv(FileDescriptor fd, DatagramPacket packet, byte[] data, int offset,
58             int length, boolean peek, boolean connected) throws IOException;
59     public int recvDirect(FileDescriptor fd, DatagramPacket packet, int address, int offset,
60             int length, boolean peek, boolean connected) throws IOException;
61
62     public void disconnectDatagram(FileDescriptor fd) throws SocketException;
63
64     public void socket(FileDescriptor fd, boolean stream) throws SocketException;
65
66     public void shutdownInput(FileDescriptor descriptor) throws IOException;
67
68     public void shutdownOutput(FileDescriptor descriptor) throws IOException;
69
70     public void sendUrgentData(FileDescriptor fd, byte value);
71
72     public void listen(FileDescriptor fd, int backlog) throws SocketException;
73
74     public void connect(FileDescriptor fd, InetAddress inetAddress, int port, int timeout)
75             throws SocketException;
76
77     public InetAddress getSocketLocalAddress(FileDescriptor fd);
78
79     /**
80      * Select the given file descriptors for read and write operations.
81      *
82      * <p>The first {@code numReadable} file descriptors of {@code readFDs} will
83      * be selected for read-ready operations. The first {@code numWritable} file
84      * descriptors in {@code writeFDs} will be selected for write-ready
85      * operations. A file descriptor can appear in either or both and must not
86      * be null. If the file descriptor is closed during the select the behavior
87      * depends upon the underlying OS.
88      *
89      * @param readFDs
90      *            all sockets interested in read and accept
91      * @param writeFDs
92      *            all sockets interested in write and connect
93      * @param numReadable
94      *            the size of the subset of readFDs to read or accept.
95      * @param numWritable
96      *            the size of the subset of writeFDs to write or connect
97      * @param timeout
98      *            timeout in milliseconds
99      * @param flags
100      *            for output. Length must be at least {@code numReadable
101      *            + numWritable}. Upon returning, each element describes the
102      *            state of the descriptor in the corresponding read or write
103      *            array. See {@code SelectorImpl.READABLE} and {@code
104      *            SelectorImpl.WRITEABLE}
105      * @return true
106      *            unless selection timed out or was interrupted
107      * @throws SocketException
108      */
109     public boolean select(FileDescriptor[] readFDs, FileDescriptor[] writeFDs,
110             int numReadable, int numWritable, long timeout, int[] flags)
111             throws SocketException;
112
113     /*
114      * Query the IP stack for the local port to which this socket is bound.
115      *
116      * @param fd the socket descriptor
117      * @return int the local port to which the socket is bound
118      */
119     public int getSocketLocalPort(FileDescriptor fd);
120
121     /*
122      * Query the IP stack for the nominated socket option.
123      *
124      * @param fd the socket descriptor @param opt the socket option type
125      * @return the nominated socket option value
126      *
127      * @throws SocketException if the option is invalid
128      */
129     public Object getSocketOption(FileDescriptor fd, int opt)
130             throws SocketException;
131
132     /*
133      * Set the nominated socket option in the IP stack.
134      *
135      * @param fd the socket descriptor @param opt the option selector @param
136      * optVal the nominated option value
137      *
138      * @throws SocketException if the option is invalid or cannot be set
139      */
140     public void setSocketOption(FileDescriptor fd, int opt, Object optVal)
141             throws SocketException;
142
143     public void close(FileDescriptor fd) throws IOException;
144
145     // TODO: change the single caller so that recv/recvDirect
146     // can mutate the InetAddress as a side-effect.
147     public void setInetAddress(InetAddress sender, byte[] address);
148 }