OSDN Git Service

2002-04-16 David S. Miller <davem@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / java / net / DatagramSocketImpl.java
1 /* DatagramSocketImpl.java -- Abstract class for UDP socket implementations
2    Copyright (C) 1998, 1999 2000, 2001, 2002 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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.
10
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.
15
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
19 02111-1307 USA.
20
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.
25
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. */
37
38
39 package java.net;
40
41 import java.io.IOException;
42 import java.io.FileDescriptor;
43
44 /**
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.
48  *
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.
52  *
53  * @author Aaron M. Renn (arenn@urbanophile.com)
54  * @author Warren Levy <warrenl@cygnus.com>
55  */
56 public abstract class DatagramSocketImpl implements SocketOptions
57 {
58
59   /**
60    * The local port to which this socket is bound
61    */
62   protected int localPort;
63
64   /**
65    * The FileDescriptor object for this object.
66    */
67   protected FileDescriptor fd;
68
69   /**
70    * Default, no-argument constructor for subclasses to call.
71    */
72   public DatagramSocketImpl()
73   {
74   }
75
76   /**
77    * This method binds the socket to the specified local port and address.
78    *
79    * @param lport The port number to bind to
80    * @param laddr The address to bind to
81    *
82    * @exception SocketException If an error occurs
83    */
84   protected abstract void bind(int lport, InetAddress laddr)
85     throws SocketException;
86
87   /**
88    * This methods closes the socket
89    */
90   protected abstract void close();
91
92   /**
93    * Creates a new datagram socket.
94    *
95    * @exception SocketException If an error occurs
96    */
97   protected abstract void create() throws SocketException;
98
99   /**
100    * Takes a peek at the next packet received in order to retrieve the
101    * address of the sender
102    *
103    * @param i The InetAddress to fill in with the information about the
104    *          sender if the next packet
105    *
106    * @return The port number of the sender of the packet
107    *
108    * @exception IOException If an error occurs
109    */
110   protected abstract int peek(InetAddress i) throws IOException;
111
112   /**
113    * Transmits the specified packet of data to the network.  The destination
114    * host and port should be encoded in the packet.
115    *
116    * @param p The packet to send
117    *
118    * @exception IOException If an error occurs
119    */
120   protected abstract void send(DatagramPacket p) throws IOException;
121
122   /**
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.
126    *
127    * @param p A place to store the incoming packet.
128    *
129    * @exception IOException If an error occurs
130    */
131   protected abstract void receive(DatagramPacket p) throws IOException;
132
133   /**
134    * Sets the Time to Live (TTL) setting on this socket to the specified
135    * value. <b>Use <code>setTimeToLive(int)</code></b> instead.
136    *
137    * @param ttl The new Time to Live value
138    *
139    * @exception IOException If an error occurs
140    * @deprecated
141    */
142   protected abstract void setTTL(byte ttl) throws IOException;
143
144   /**
145    * This method returns the current Time to Live (TTL) setting on this
146    * socket.  <b>Use <code>getTimeToLive()</code></b> instead.
147    *
148    * @exception IOException If an error occurs
149    * @deprecated
150    */
151   protected abstract byte getTTL() throws IOException;
152
153   /**
154    * Sets the Time to Live (TTL) setting on this socket to the specified
155    * value.
156    *
157    * @param ttl The new Time to Live value
158    *
159    * @exception IOException If an error occurs
160    */
161   protected abstract void setTimeToLive(int ttl) throws IOException;
162
163   /**
164    * This method returns the current Time to Live (TTL) setting on this
165    * socket.
166    *
167    * @exception IOException If an error occurs
168    */
169   protected abstract int getTimeToLive() throws IOException;
170
171   /**
172    * Causes this socket to join the specified multicast group
173    *
174    * @param inetaddr The multicast address to join with
175    *
176    * @exception IOException If an error occurs
177    */
178   protected abstract void join(InetAddress inetaddr) throws IOException;
179
180   /**
181    * Causes the socket to leave the specified multicast group.
182    *
183    * @param inetaddr The multicast address to leave
184    *
185    * @exception IOException If an error occurs
186    */
187   protected abstract void leave(InetAddress inetaddr) throws IOException;
188
189   /**
190    * Returns the FileDescriptor for this socket
191    */
192   protected FileDescriptor getFileDescriptor()
193   {
194     return fd;
195   }
196
197   /**
198    * Returns the local port this socket is bound to
199    */
200   protected int getLocalPort()
201   {
202     return localPort;
203   }
204
205   /**
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.
211    *
212    * @param option_id The identifier of the option
213    * @param val The value to set the option to
214    *
215    * @exception SocketException If an error occurs
216    * @XXX This redeclaration from SocketOptions is a workaround to a gcj bug.
217    */
218   public abstract void setOption(int option_id, Object val)
219     throws SocketException;
220
221   /**
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.
227    *
228    * @param option_id The option identifier
229    *
230    * @return The current value of the option
231    *
232    * @exception SocketException If an error occurs
233    * @XXX This redeclaration from SocketOptions is a workaround to a gcj bug.
234    */
235   public abstract Object getOption(int option_id) throws SocketException;
236 }