1 // PlainDatagramSocketImpl.java - Implementation of DatagramSocketImpl.
3 /* Copyright (C) 1999 Red Hat, Inc.
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 import java.io.IOException;
15 * @author Warren Levy <warrenl@cygnus.com>
20 * Written using on-line Java Platform 1.2 API Specification, as well
21 * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
22 * Status: Believed complete and correct.
25 class PlainDatagramSocketImpl extends DatagramSocketImpl
27 // These fields are mirrored for use in native code to avoid cpp conflicts
28 // when the #defines in system header files are the same as the public fields.
29 static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
30 _Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
31 _Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
32 _Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
33 _Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
34 _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
35 _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
36 _Jv_SO_RCVBUF_ = SocketOptions.SO_RCVBUF;
40 // FIXME: Is this necessary? Could it help w/ DatagramSocket.getLocalAddress?
41 // InetAddress address;
44 InetAddress localAddress;
46 // 'timeout' is set/read by setOption/getOption.
49 // FIXME: Probably should have bind (and create?) calls from DatagramSocket
50 // constuctor. If so, then same change should be made to the corresponding
51 // Socket (non-datagram) classes. This allows the implementation more
52 // complete control over how the socket is set up and used (e.g. connect,
53 // setting options, etc.).
54 public PlainDatagramSocketImpl()
58 protected native void bind(int lport, InetAddress laddr)
59 throws SocketException;
60 protected native void create() throws SocketException;
61 protected native int peek(InetAddress i) throws IOException;
62 protected native void setTimeToLive(int ttl) throws IOException;
63 protected native int getTimeToLive() throws IOException;
64 protected native void send(DatagramPacket p) throws IOException;
65 protected native void receive(DatagramPacket p) throws IOException;
66 public native void setOption(int optID, Object value) throws SocketException;
67 public native Object getOption(int optID) throws SocketException;
68 private native void mcastGrp(InetAddress inetaddr, boolean join)
71 protected void close()
73 // FIXME: The close method in each of the DatagramSocket* classes does
74 // not throw an IOException. The issue is that FileDescriptor.close()
75 // in natFileDescriptorPosix.cc can throw one, so we have to catch
76 // it here. It seems that FileDescriptor.close is properly throwing
77 // the IOException on errors since many of the java.io classes depend
78 // on that. This probably requires a bit more research but for now,
79 // we'll catch the IOException here.
86 System.err.println("PlainDatagramSocketImpl.close: Error closing - " +
91 // Deprecated in JDK 1.2.
92 protected byte getTTL() throws IOException
94 return (byte) getTimeToLive();
97 // Deprecated in JDK 1.2.
98 protected void setTTL(byte ttl) throws IOException
100 setTimeToLive(((int) ttl) & 0xFF);
103 protected void join(InetAddress inetaddr) throws IOException
105 mcastGrp(inetaddr, true);
108 protected void leave(InetAddress inetaddr) throws IOException
110 mcastGrp(inetaddr, false);