1 /* DatagramSocketImpl.java -- Abstract class for UDP socket implementations
2 Copyright (C) 1998, 1999 2000, 2001, 2002 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)
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., 59 Temple Place, Suite 330, Boston, MA
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
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. */
41 import java.io.IOException;
42 import java.io.FileDescriptor;
45 * Written using on-line Java Platform 1.2 API Specification, as well
46 * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
47 * Status: Believed complete and correct.
49 * <p>This abstract class models a datagram socket implementation. An
50 * actual implementation class would implement these methods, probably
51 * via redirecting them to native code.
53 * @author Aaron M. Renn (arenn@urbanophile.com)
54 * @author Warren Levy <warrenl@cygnus.com>
56 public abstract class DatagramSocketImpl implements SocketOptions
60 * The local port to which this socket is bound
62 protected int localPort;
65 * The FileDescriptor object for this object.
67 protected FileDescriptor fd;
70 * Default, no-argument constructor for subclasses to call.
72 public DatagramSocketImpl()
77 * This method binds the socket to the specified local port and address.
79 * @param lport The port number to bind to
80 * @param laddr The address to bind to
82 * @exception SocketException If an error occurs
84 protected abstract void bind(int lport, InetAddress laddr)
85 throws SocketException;
88 * This methods closes the socket
90 protected abstract void close();
93 * Creates a new datagram socket.
95 * @exception SocketException If an error occurs
97 protected abstract void create() throws SocketException;
100 * Takes a peek at the next packet received in order to retrieve the
101 * address of the sender
103 * @param i The InetAddress to fill in with the information about the
104 * sender if the next packet
106 * @return The port number of the sender of the packet
108 * @exception IOException If an error occurs
110 protected abstract int peek(InetAddress i) throws IOException;
113 * Transmits the specified packet of data to the network. The destination
114 * host and port should be encoded in the packet.
116 * @param p The packet to send
118 * @exception IOException If an error occurs
120 protected abstract void send(DatagramPacket p) throws IOException;
123 * Receives a packet of data from the network Will block until a packet
124 * arrives. The packet info in populated into the passed in
125 * DatagramPacket object.
127 * @param p A place to store the incoming packet.
129 * @exception IOException If an error occurs
131 protected abstract void receive(DatagramPacket p) throws IOException;
134 * Sets the Time to Live (TTL) setting on this socket to the specified
135 * value. <b>Use <code>setTimeToLive(int)</code></b> instead.
137 * @param ttl The new Time to Live value
139 * @exception IOException If an error occurs
142 protected abstract void setTTL(byte ttl) throws IOException;
145 * This method returns the current Time to Live (TTL) setting on this
146 * socket. <b>Use <code>getTimeToLive()</code></b> instead.
148 * @exception IOException If an error occurs
151 protected abstract byte getTTL() throws IOException;
154 * Sets the Time to Live (TTL) setting on this socket to the specified
157 * @param ttl The new Time to Live value
159 * @exception IOException If an error occurs
161 protected abstract void setTimeToLive(int ttl) throws IOException;
164 * This method returns the current Time to Live (TTL) setting on this
167 * @exception IOException If an error occurs
169 protected abstract int getTimeToLive() throws IOException;
172 * Causes this socket to join the specified multicast group
174 * @param inetaddr The multicast address to join with
176 * @exception IOException If an error occurs
178 protected abstract void join(InetAddress inetaddr) throws IOException;
181 * Causes the socket to leave the specified multicast group.
183 * @param inetaddr The multicast address to leave
185 * @exception IOException If an error occurs
187 protected abstract void leave(InetAddress inetaddr) throws IOException;
190 * Returns the FileDescriptor for this socket
192 protected FileDescriptor getFileDescriptor()
198 * Returns the local port this socket is bound to
200 protected int getLocalPort()
206 * Sets the specified option on a socket to the passed in object. For
207 * options that take an integer argument, the passed in object is an
208 * <code>Integer</code>. For options that are set to on or off, the
209 * value passed will be a <code>Boolean</code>. The <code>option_id</code>
210 * parameter is one of the defined constants in the superinterface.
212 * @param option_id The identifier of the option
213 * @param val The value to set the option to
215 * @exception SocketException If an error occurs
216 * @XXX This redeclaration from SocketOptions is a workaround to a gcj bug.
218 public abstract void setOption(int option_id, Object val)
219 throws SocketException;
222 * Returns the current setting of the specified option. The
223 * <code>Object</code> returned will be an <code>Integer</code> for options
224 * that have integer values. For options that are set to on or off, a
225 * <code>Boolean</code> will be returned. The <code>option_id</code>
226 * is one of the defined constants in the superinterface.
228 * @param option_id The option identifier
230 * @return The current value of the option
232 * @exception SocketException If an error occurs
233 * @XXX This redeclaration from SocketOptions is a workaround to a gcj bug.
235 public abstract Object getOption(int option_id) throws SocketException;