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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 // address length was changed from long to int for performance reasons.
22 package org.apache.harmony.luni.platform;
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 import java.net.UnknownHostException;
31 import java.nio.channels.Channel;
34 * The interface for network methods.
36 public interface INetworkSystem {
39 * Socket connect Step start
41 public final int SOCKET_CONNECT_STEP_START = 0;
44 * Socket connect Step check
46 public final int SOCKET_CONNECT_STEP_CHECK = 1;
51 public void accept(FileDescriptor fdServer, SocketImpl newSocket,
52 FileDescriptor fdnewSocket, int timeout) throws IOException;
54 public void bind(FileDescriptor aFD, InetAddress inetAddress, int port)
55 throws SocketException;
57 public int read(FileDescriptor aFD, byte[] data, int offset, int count,
58 int timeout) throws IOException;
60 public int readDirect(FileDescriptor aFD, int address, int offset, int count,
61 int timeout) throws IOException;
63 public int write(FileDescriptor fd, byte[] data, int offset, int count)
66 public int writeDirect(FileDescriptor fd, int address, int offset, int count)
69 public void setNonBlocking(FileDescriptor aFD, boolean block)
72 public int connect(FileDescriptor aFD, int trafficClass,
73 InetAddress inetAddress, int port) throws IOException;
75 // BEGIN android-changed
76 public int connectWithTimeout(FileDescriptor aFD, int timeout,
77 int trafficClass, InetAddress hostname, int port, int step,
78 byte[] context) throws IOException;
79 // END android-changed
81 public int sendDatagram(FileDescriptor fd, byte[] data, int offset,
82 int length, int port, boolean bindToDevice, int trafficClass,
83 InetAddress inetAddress) throws IOException;
85 public int sendDatagramDirect(FileDescriptor fd, int address, int offset,
86 int length, int port, boolean bindToDevice, int trafficClass,
87 InetAddress inetAddress) throws IOException;
89 public int receiveDatagram(FileDescriptor aFD, DatagramPacket packet,
90 byte[] data, int offset, int length, int receiveTimeout,
91 boolean peek) throws IOException;
93 public int receiveDatagramDirect(FileDescriptor aFD, DatagramPacket packet,
94 int address, int offset, int length, int receiveTimeout,
95 boolean peek) throws IOException;
97 public int recvConnectedDatagram(FileDescriptor aFD, DatagramPacket packet,
98 byte[] data, int offset, int length, int receiveTimeout,
99 boolean peek) throws IOException;
101 public int recvConnectedDatagramDirect(FileDescriptor aFD,
102 DatagramPacket packet, int address, int offset, int length,
103 int receiveTimeout, boolean peek) throws IOException;
105 public int peekDatagram(FileDescriptor aFD, InetAddress sender,
106 int receiveTimeout) throws IOException;
108 public int sendConnectedDatagram(FileDescriptor fd, byte[] data,
109 int offset, int length, boolean bindToDevice) throws IOException;
111 public int sendConnectedDatagramDirect(FileDescriptor fd, int address,
112 int offset, int length, boolean bindToDevice) throws IOException;
114 public void disconnectDatagram(FileDescriptor aFD) throws SocketException;
116 public void createDatagramSocket(FileDescriptor aFD, boolean preferIPv4Stack)
117 throws SocketException;
119 public void connectDatagram(FileDescriptor aFD, int port, int trafficClass,
120 InetAddress inetAddress) throws SocketException;
123 * @deprecated Use {@link #read(FileDescriptor, byte[], int, int, int)}
126 public int receiveStream(FileDescriptor aFD, byte[] data, int offset,
127 int count, int timeout) throws IOException;
129 // BEGIN android-added
130 public int sendStream(FileDescriptor fd, byte[] data, int offset, int count)
134 public void shutdownInput(FileDescriptor descriptor) throws IOException;
136 public void shutdownOutput(FileDescriptor descriptor) throws IOException;
138 public boolean supportsUrgentData(FileDescriptor fd);
140 public void sendUrgentData(FileDescriptor fd, byte value);
142 public int availableStream(FileDescriptor aFD) throws SocketException;
144 // BEGIN android-removed
145 // public void acceptStreamSocket(FileDescriptor fdServer,
146 // SocketImpl newSocket, FileDescriptor fdnewSocket, int timeout)
147 // throws IOException;
148 // END android-removed
150 public void createServerStreamSocket(FileDescriptor aFD, boolean preferIPv4Stack)
151 throws SocketException;
153 public void createStreamSocket(FileDescriptor aFD, boolean preferIPv4Stack)
154 throws SocketException;
156 public void listenStreamSocket(FileDescriptor aFD, int backlog)
157 throws SocketException;
159 public void connectStreamWithTimeoutSocket(FileDescriptor aFD, int aport,
160 int timeout, int trafficClass, InetAddress inetAddress)
163 public int sendDatagram2(FileDescriptor fd, byte[] data, int offset,
164 int length, int port, InetAddress inetAddress) throws IOException;
166 public InetAddress getSocketLocalAddress(FileDescriptor aFD,
167 boolean preferIPv6Addresses);
169 public int[] select(FileDescriptor[] readFDs,
170 FileDescriptor[] writeFDs, long timeout)
171 throws SocketException;
174 * Query the IP stack for the local port to which this socket is bound.
176 * @param aFD the socket descriptor @param preferIPv6Addresses address
177 * preference for nodes that support both IPv4 and IPv6 @return int the
178 * local port to which the socket is bound
180 public int getSocketLocalPort(FileDescriptor aFD,
181 boolean preferIPv6Addresses);
184 * Query the IP stack for the nominated socket option.
186 * @param aFD the socket descriptor @param opt the socket option type
187 * @return the nominated socket option value
189 * @throws SocketException if the option is invalid
191 public Object getSocketOption(FileDescriptor aFD, int opt)
192 throws SocketException;
195 * Set the nominated socket option in the IP stack.
197 * @param aFD the socket descriptor @param opt the option selector @param
198 * optVal the nominated option value
200 * @throws SocketException if the option is invalid or cannot be set
202 public void setSocketOption(FileDescriptor aFD, int opt, Object optVal)
203 throws SocketException;
205 public int getSocketFlags();
208 * Close the socket in the IP stack.
210 * @param aFD the socket descriptor
212 public void socketClose(FileDescriptor aFD) throws IOException;
214 public InetAddress getHostByAddr(byte[] addr) throws UnknownHostException;
216 public InetAddress getHostByName(String addr, boolean preferIPv6Addresses)
217 throws UnknownHostException;
219 public void setInetAddress(InetAddress sender, byte[] address);
221 // BEGIN android-removed
222 // public boolean isReachableByICMP(InetAddress dest,InetAddress source,int ttl,int timeout);
223 // END android-removed
225 public Channel inheritedChannel();
227 public void oneTimeInitialization(boolean jcl_supports_ipv6);