2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / net / DatagramSocketImpl.java
blob891c8d183b5ec5e9c5da9c336fdd8eb8c9073aa6
1 /* DatagramSocketImpl.java -- Abstract class for UDP socket implementations
2 Copyright (C) 1998, 1999 2000, 2001,
3 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA.
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
25 combination.
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package java.net;
42 import java.io.IOException;
43 import java.io.FileDescriptor;
45 /**
46 * This abstract class models a datagram socket implementation. An
47 * actual implementation class would implement these methods, probably
48 * via redirecting them to native code.
49 * <p>
50 * Written using on-line Java Platform 1.2 API Specification, as well
51 * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
52 * <p>
53 * Status: Believed complete and correct.
55 * @author Aaron M. Renn (arenn@urbanophile.com)
56 * @author Warren Levy <warrenl@cygnus.com>
57 * @since 1.1
59 public abstract class DatagramSocketImpl implements SocketOptions
62 /**
63 * The local port to which this socket is bound
65 protected int localPort;
67 /**
68 * The FileDescriptor object for this object.
70 protected FileDescriptor fd;
72 /**
73 * Default, no-argument constructor for subclasses to call.
75 public DatagramSocketImpl()
79 /**
80 * This method binds the socket to the specified local port and address.
82 * @param lport The port number to bind to
83 * @param laddr The address to bind to
85 * @exception SocketException If an error occurs
87 protected abstract void bind(int lport, InetAddress laddr)
88 throws SocketException;
90 /**
91 * This methods closes the socket
93 protected abstract void close();
95 /**
96 * Creates a new datagram socket.
98 * @exception SocketException If an error occurs
100 protected abstract void create() throws SocketException;
103 * Takes a peek at the next packet received in order to retrieve the
104 * address of the sender
106 * @param i The <code>InetAddress</code> to fill in with the information
107 * about the sender if the next packet
109 * @return The port number of the sender of the packet
111 * @exception IOException If an error occurs
112 * @exception PortUnreachableException May be thrown if the socket is
113 * connected to a currently unreachable destination. Note, there is no
114 * guarantee that the exception will be thrown.
116 protected abstract int peek(InetAddress i) throws IOException;
119 * Takes a peek at the next packet received. This packet is not consumed.
120 * With the next peekData/receive operation this packet will be read again.
122 * @param p The <code>DatagramPacket</code> to fill in with the data sent.
124 * @return The port number of the sender of the packet.
126 * @exception IOException If an error occurs
127 * @exception PortUnreachableException May be thrown if the socket is
128 * connected to a currently unreachable destination. Note, there is no
129 * guarantee that the exception will be thrown.
131 * @since 1.4
133 protected abstract int peekData (DatagramPacket p) throws IOException;
136 * Transmits the specified packet of data to the network. The destination
137 * host and port should be encoded in the packet.
139 * @param p The packet to send
141 * @exception IOException If an error occurs
142 * @exception PortUnreachableException May be thrown if the socket is
143 * connected to a currently unreachable destination. Note, there is no
144 * guarantee that the exception will be thrown.
146 protected abstract void send(DatagramPacket p) throws IOException;
149 * Receives a packet of data from the network Will block until a packet
150 * arrives. The packet info in populated into the passed in
151 * <code>DatagramPacket</code> object.
153 * @param p A place to store the incoming packet.
155 * @exception IOException If an error occurs
156 * @exception PortUnreachableException May be thrown if the socket is
157 * connected to a currently unreachable destination. Note, there is no
158 * guarantee that the exception will be thrown.
160 protected abstract void receive(DatagramPacket p) throws IOException;
163 * Connects the socket to a host specified by address and port.
165 * @param address The <code>InetAddress</code> of the host to connect to
166 * @param port The port number of the host to connect to
168 * @exception SocketException If an error occurs
170 * @since 1.4
172 protected void connect (InetAddress address, int port) throws SocketException
174 // This method has to be overwritten by real implementations
178 * Disconnects the socket.
180 * @since 1.4
182 protected void disconnect ()
184 // This method has to be overwritten by real implementations
188 * Sets the Time to Live (TTL) setting on this socket to the specified
189 * value. <b>Use <code>setTimeToLive(int)</code></b> instead.
191 * @param ttl The new Time to Live value
193 * @exception IOException If an error occurs
194 * @deprecated
196 protected abstract void setTTL(byte ttl) throws IOException;
199 * This method returns the current Time to Live (TTL) setting on this
200 * socket. <b>Use <code>getTimeToLive()</code></b> instead.
202 * @exception IOException If an error occurs
203 * @deprecated
205 protected abstract byte getTTL() throws IOException;
208 * Sets the Time to Live (TTL) setting on this socket to the specified
209 * value.
211 * @param ttl The new Time to Live value
213 * @exception IOException If an error occurs
215 protected abstract void setTimeToLive(int ttl) throws IOException;
218 * This method returns the current Time to Live (TTL) setting on this
219 * socket.
221 * @exception IOException If an error occurs
223 protected abstract int getTimeToLive() throws IOException;
226 * Causes this socket to join the specified multicast group
228 * @param inetaddr The multicast address to join with
230 * @exception IOException If an error occurs
232 protected abstract void join(InetAddress inetaddr) throws IOException;
235 * Causes the socket to leave the specified multicast group.
237 * @param inetaddr The multicast address to leave
239 * @exception IOException If an error occurs
241 protected abstract void leave(InetAddress inetaddr) throws IOException;
244 * Causes this socket to join the specified multicast group on a specified
245 * device
247 * @param mcastaddr The address to leave
248 * @param netIf The specified network interface to join the group at
250 * @exception IOException If an error occurs
252 * @since 1.4
254 protected abstract void joinGroup (SocketAddress mcastaddr,
255 NetworkInterface netIf)
256 throws IOException;
259 * Leaves a multicast group
261 * @param mcastaddr The address to join
262 * @param netIf The specified network interface to leave the group at
264 * @exception IOException If an error occurs
266 * @since 1.4
268 protected abstract void leaveGroup (SocketAddress mcastaddr,
269 NetworkInterface netIf)
270 throws IOException;
273 * Returns the FileDescriptor for this socket
275 protected FileDescriptor getFileDescriptor()
277 return fd;
281 * Returns the local port this socket is bound to
283 protected int getLocalPort()
285 return localPort;