Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / net / DatagramSocketImpl.java
blobb48019f77c1bc96caa9511f28baa44e12d7e6b4d
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. */
39 package java.net;
41 import java.io.FileDescriptor;
42 import java.io.IOException;
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
61 /**
62 * The local port to which this socket is bound
64 protected int localPort;
66 /**
67 * The FileDescriptor object for this object.
69 protected FileDescriptor fd;
71 /**
72 * Default, no-argument constructor for subclasses to call.
74 public DatagramSocketImpl()
78 /**
79 * This method binds the socket to the specified local port and address.
81 * @param lport The port number to bind to
82 * @param laddr The address to bind to
84 * @exception SocketException If an error occurs
86 protected abstract void bind(int lport, InetAddress laddr)
87 throws SocketException;
89 /**
90 * This methods closes the socket
92 protected abstract void close();
94 /**
95 * Creates a new datagram socket.
97 * @exception SocketException If an error occurs
99 protected abstract void create() throws SocketException;
102 * Takes a peek at the next packet received in order to retrieve the
103 * address of the sender
105 * @param i The <code>InetAddress</code> to fill in with the information
106 * about the sender if the next packet
108 * @return The port number of the sender of the packet
110 * @exception IOException If an error occurs
111 * @exception PortUnreachableException May be thrown if the socket is
112 * connected to a currently unreachable destination. Note, there is no
113 * guarantee that the exception will be thrown.
115 protected abstract int peek(InetAddress i) throws IOException;
118 * Takes a peek at the next packet received. This packet is not consumed.
119 * With the next peekData/receive operation this packet will be read again.
121 * @param p The <code>DatagramPacket</code> to fill in with the data sent.
123 * @return The port number of the sender of the packet.
125 * @exception IOException If an error occurs
126 * @exception PortUnreachableException May be thrown if the socket is
127 * connected to a currently unreachable destination. Note, there is no
128 * guarantee that the exception will be thrown.
130 * @since 1.4
132 protected abstract int peekData(DatagramPacket p) throws IOException;
135 * Transmits the specified packet of data to the network. The destination
136 * host and port should be encoded in the packet.
138 * @param p The packet to send
140 * @exception IOException If an error occurs
141 * @exception PortUnreachableException May be thrown if the socket is
142 * connected to a currently unreachable destination. Note, there is no
143 * guarantee that the exception will be thrown.
145 protected abstract void send(DatagramPacket p) throws IOException;
148 * Receives a packet of data from the network Will block until a packet
149 * arrives. The packet info in populated into the passed in
150 * <code>DatagramPacket</code> object.
152 * @param p A place to store the incoming packet.
154 * @exception IOException If an error occurs
155 * @exception PortUnreachableException May be thrown if the socket is
156 * connected to a currently unreachable destination. Note, there is no
157 * guarantee that the exception will be thrown.
159 protected abstract void receive(DatagramPacket p) throws IOException;
162 * Connects the socket to a host specified by address and port.
164 * @param address The <code>InetAddress</code> of the host to connect to
165 * @param port The port number of the host to connect to
167 * @exception SocketException If an error occurs
169 * @since 1.4
171 protected void connect(InetAddress address, int port)
172 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 * @return the current time-to-live
204 * @exception IOException If an error occurs
206 * @deprecated // FIXME: when ?
208 protected abstract byte getTTL() throws IOException;
211 * Sets the Time to Live (TTL) setting on this socket to the specified
212 * value.
214 * @param ttl The new Time to Live value
216 * @exception IOException If an error occurs
218 protected abstract void setTimeToLive(int ttl) throws IOException;
221 * This method returns the current Time to Live (TTL) setting on this
222 * socket.
224 * @return the current time-to-live
226 * @exception IOException If an error occurs
228 protected abstract int getTimeToLive() throws IOException;
231 * Causes this socket to join the specified multicast group
233 * @param inetaddr The multicast address to join with
235 * @exception IOException If an error occurs
237 protected abstract void join(InetAddress inetaddr) throws IOException;
240 * Causes the socket to leave the specified multicast group.
242 * @param inetaddr The multicast address to leave
244 * @exception IOException If an error occurs
246 protected abstract void leave(InetAddress inetaddr) throws IOException;
249 * Causes this socket to join the specified multicast group on a specified
250 * device
252 * @param mcastaddr The address to leave
253 * @param netIf The specified network interface to join the group at
255 * @exception IOException If an error occurs
257 * @since 1.4
259 protected abstract void joinGroup(SocketAddress mcastaddr,
260 NetworkInterface netIf)
261 throws IOException;
264 * Leaves a multicast group
266 * @param mcastaddr The address to join
267 * @param netIf The specified network interface to leave the group at
269 * @exception IOException If an error occurs
271 * @since 1.4
273 protected abstract void leaveGroup(SocketAddress mcastaddr,
274 NetworkInterface netIf)
275 throws IOException;
278 * Returns the FileDescriptor for this socket
280 * @return the file descriptor associated with this socket
282 protected FileDescriptor getFileDescriptor()
284 return fd;
288 * Returns the local port this socket is bound to
290 * @return the local port
292 protected int getLocalPort()
294 return localPort;