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;
32 * The interface for network methods.
34 public interface INetworkSystem {
35 public void accept(FileDescriptor serverFd, SocketImpl newSocket, FileDescriptor clientFd)
38 public void bind(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException;
40 public int read(FileDescriptor fd, byte[] data, int offset, int count) throws IOException;
42 public int readDirect(FileDescriptor fd, int address, int count) throws IOException;
44 public int write(FileDescriptor fd, byte[] data, int offset, int count) throws IOException;
46 public int writeDirect(FileDescriptor fd, int address, int offset, int count) throws IOException;
48 public boolean connectNonBlocking(FileDescriptor fd, InetAddress inetAddress, int port)
50 public boolean isConnected(FileDescriptor fd, int timeout) throws IOException;
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;
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;
62 public void disconnectDatagram(FileDescriptor fd) throws SocketException;
64 public void socket(FileDescriptor fd, boolean stream) throws SocketException;
66 public void shutdownInput(FileDescriptor descriptor) throws IOException;
68 public void shutdownOutput(FileDescriptor descriptor) throws IOException;
70 public void sendUrgentData(FileDescriptor fd, byte value);
72 public void listen(FileDescriptor fd, int backlog) throws SocketException;
74 public void connect(FileDescriptor fd, InetAddress inetAddress, int port, int timeout)
75 throws SocketException;
77 public InetAddress getSocketLocalAddress(FileDescriptor fd);
80 * Select the given file descriptors for read and write operations.
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.
90 * all sockets interested in read and accept
92 * all sockets interested in write and connect
94 * the size of the subset of readFDs to read or accept.
96 * the size of the subset of writeFDs to write or connect
98 * timeout in milliseconds
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}
106 * unless selection timed out or was interrupted
107 * @throws SocketException
109 public boolean select(FileDescriptor[] readFDs, FileDescriptor[] writeFDs,
110 int numReadable, int numWritable, long timeout, int[] flags)
111 throws SocketException;
114 * Query the IP stack for the local port to which this socket is bound.
116 * @param fd the socket descriptor
117 * @return int the local port to which the socket is bound
119 public int getSocketLocalPort(FileDescriptor fd);
122 * Query the IP stack for the nominated socket option.
124 * @param fd the socket descriptor @param opt the socket option type
125 * @return the nominated socket option value
127 * @throws SocketException if the option is invalid
129 public Object getSocketOption(FileDescriptor fd, int opt)
130 throws SocketException;
133 * Set the nominated socket option in the IP stack.
135 * @param fd the socket descriptor @param opt the option selector @param
136 * optVal the nominated option value
138 * @throws SocketException if the option is invalid or cannot be set
140 public void setSocketOption(FileDescriptor fd, int opt, Object optVal)
141 throws SocketException;
143 public void close(FileDescriptor fd) throws IOException;
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);