Merge from mainline.
[official-gcc.git] / libjava / classpath / compat / java.net / PlainSocketImpl.java
blob4a80eab234a05eb1a89b73273fd037448f24cfaa
1 /* PlainSocketImpl.java -- Default socket implementation
2 Copyright (c) 1998 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 import java.net.*;
39 import java.io.InputStream;
40 import java.io.OutputStream;
41 import java.io.IOException;
43 /**
44 * Unless the application installs its own SocketImplFactory, this is the
45 * default socket implemetation that will be used. It simply uses a
46 * combination of Java and native routines to implement standard BSD
47 * style sockets of family AF_INET and types SOCK_STREAM and SOCK_DGRAM
49 * @version 0.1
51 * @author Aaron M. Renn (arenn@urbanophile.com)
53 class PlainSocketImpl extends SocketImpl
56 /*************************************************************************/
59 * Static Variables
63 // Static initializer to load native library
64 static
66 System.loadLibrary("javanet");
70 /*************************************************************************/
73 * Instance Variables
76 /**
77 * This is the native file descriptor for this socket
79 protected int native_fd = -1;
81 /*************************************************************************/
83 /**
84 * Default do nothing constructor
86 public
87 PlainSocketImpl()
92 /*************************************************************************/
94 /**
95 * Accepts a new connection on this socket and returns in in the
96 * passed in SocketImpl.
98 * @param impl The SocketImpl object to accept this connection.
100 protected native void
101 accept(SocketImpl impl) throws IOException;
103 /*************************************************************************/
106 * Returns the number of bytes that the caller can read from this socket
107 * without blocking. //*****Figure out if we can do something here
109 * @return The number of readable bytes before blocking
111 * @exception IOException If an error occurs
113 protected int
114 available() throws IOException
116 return(0);
119 /*************************************************************************/
122 * Binds to the specified port on the specified addr. Note that this addr
123 * must represent a local IP address. **** How bind to INADDR_ANY? ****
125 * @param addr The address to bind to
126 * @param port The port number to bind to
128 * @exception IOException If an error occurs
130 protected native void
131 bind(InetAddress addr, int port) throws IOException;
133 /*************************************************************************/
136 * Closes the socket. This will cause any InputStream or OutputStream
137 * objects for this Socket to be closed as well.
138 * <p>
139 * Note that if the SO_LINGER option is set on this socket, then the
140 * operation could block.
142 * @exception IOException If an error occurs
144 protected native void
145 close() throws IOException;
147 /*************************************************************************/
150 * Connects to the remote address and port specified as arguments.
152 * @param addr The remote address to connect to
153 * @param port The remote port to connect to
155 * @exception IOException If an error occurs
157 protected void
158 connect(InetAddress addr, int port) throws IOException
160 return;
163 /*************************************************************************/
166 * Connects to the remote hostname and port specified as arguments.
168 * @param hostname The remote hostname to connect to
169 * @param port The remote port to connect to
171 * @exception IOException If an error occurs
173 protected void
174 connect(String hostname, int port) throws IOException
176 InetAddress addr = InetAddress.getByName(hostname);
177 connect(addr, port);
180 /*************************************************************************/
183 * Creates a new socket that is not bound to any local address/port and
184 * is not connected to any remote address/port. This will be created as
185 * a stream socket if the stream parameter is true, or a datagram socket
186 * if the stream parameter is false.
188 * @param stream true for a stream socket, false for a datagram socket
190 protected native void
191 create(boolean stream) throws IOException;
193 /*************************************************************************/
196 * Starts listening for connections on a socket. The queuelen parameter
197 * is how many pending connections will queue up waiting to be serviced
198 * before being accept'ed. If the queue of pending requests exceeds this
199 * number, additional connections will be refused.
201 * @param queuelen The length of the pending connection queue
203 * @exception IOException If an error occurs
205 protected native void
206 listen(int queuelen) throws IOException;
208 /*************************************************************************/
211 * Sets the specified option on a socket to the passed in object. For
212 * options that take an integer argument, the passed in object is an
213 * Integer. The option_id parameter is one of the defined constants in
214 * this interface.
216 * @param option_id The identifier of the option
217 * @param val The value to set the option to
219 * @exception SocketException If an error occurs
221 public void
222 setOption(int option_id, Object val) throws SocketException
224 //*** Do non-native for now
225 System.err.println("Option Id=" + option_id);
226 System.err.println("Object is: " + val.getClass().getName());
227 System.err.println("Object value is: " + val);
230 /*************************************************************************/
233 * Returns the current setting of the specified option. The Object returned
234 * will be an Integer for options that have integer values. The option_id
235 * is one of the defined constants in this interface.
237 * @param option_id The option identifier
239 * @return The current value of the option
241 * @exception SocketException If an error occurs
243 public Object
244 getOption(int option_id) throws SocketException
246 //**** Do non-native for now
247 System.err.println("Option Id=" + option_id);
248 return(null);
251 /*************************************************************************/
254 * Returns an InputStream object for reading from this socket. This will
255 * be an instance of SocketInputStream.
257 * @return An InputStream
259 * @exception IOException If an error occurs
261 protected InputStream
262 getInputStream() throws IOException
264 return(null);
267 /*************************************************************************/
270 * Returns an OutputStream object for writing to this socket. This will
271 * be an instance of SocketOutputStream.
273 * @return An OutputStream
275 * @exception IOException If an error occurs
277 protected OutputStream
278 getOutputStream() throws IOException
280 return(null);
283 } // class PlainSocketImpl