Commit 40b86e5f by Tom Tromey Committed by Tom Tromey

Collections.java (UnmodifiableMap.toArray): Imported changes from Classpath.

libjava/classpath
	* java/util/Collections.java (UnmodifiableMap.toArray): Imported
	changes from Classpath.
libjava
	* sources.am, Makefile.in: Rebuilt.
	* java/lang/Socket.java: Removed override.
	* java/lang/DatagramSocket.java: Removed override.
	* gnu/java/net/PlainSocketImpl.java (localSocketAddress): New
	field.
	(getLocalAddress): New method.
	* gnu/java/net/PlainDatagramSocketImpl.java
	(PlainDatagramSocketImpl): Throws IOException.
	* gnu/java/net/natPlainSocketImplPosix.cc (write): Remove
	'sizeof'.
	(read): Likewise.

From-SVN: r121866
parent e8c30b5f
2007-02-12 Tom Tromey <tromey@redhat.com>
* sources.am, Makefile.in: Rebuilt.
* java/lang/Socket.java: Removed override.
* java/lang/DatagramSocket.java: Removed override.
* gnu/java/net/PlainSocketImpl.java (localSocketAddress): New
field.
(getLocalAddress): New method.
* gnu/java/net/PlainDatagramSocketImpl.java
(PlainDatagramSocketImpl): Throws IOException.
* gnu/java/net/natPlainSocketImplPosix.cc (write): Remove
'sizeof'.
(read): Likewise.
2007-02-09 Jakub Jelinek <jakub@redhat.com> 2007-02-09 Jakub Jelinek <jakub@redhat.com>
* java/util/VMTimeZone.java: Rewrite to handle both the old * java/util/VMTimeZone.java: Rewrite to handle both the old
......
...@@ -1209,6 +1209,7 @@ classpath/gnu/classpath/jdwp/exception/InvalidClassLoaderException.java \ ...@@ -1209,6 +1209,7 @@ classpath/gnu/classpath/jdwp/exception/InvalidClassLoaderException.java \
classpath/gnu/classpath/jdwp/exception/InvalidCountException.java \ classpath/gnu/classpath/jdwp/exception/InvalidCountException.java \
classpath/gnu/classpath/jdwp/exception/InvalidEventTypeException.java \ classpath/gnu/classpath/jdwp/exception/InvalidEventTypeException.java \
classpath/gnu/classpath/jdwp/exception/InvalidFieldException.java \ classpath/gnu/classpath/jdwp/exception/InvalidFieldException.java \
classpath/gnu/classpath/jdwp/exception/InvalidFrameException.java \
classpath/gnu/classpath/jdwp/exception/InvalidLocationException.java \ classpath/gnu/classpath/jdwp/exception/InvalidLocationException.java \
classpath/gnu/classpath/jdwp/exception/InvalidMethodException.java \ classpath/gnu/classpath/jdwp/exception/InvalidMethodException.java \
classpath/gnu/classpath/jdwp/exception/InvalidObjectException.java \ classpath/gnu/classpath/jdwp/exception/InvalidObjectException.java \
...@@ -4392,7 +4393,7 @@ classpath/java/net/ConnectException.java \ ...@@ -4392,7 +4393,7 @@ classpath/java/net/ConnectException.java \
classpath/java/net/ContentHandler.java \ classpath/java/net/ContentHandler.java \
classpath/java/net/ContentHandlerFactory.java \ classpath/java/net/ContentHandlerFactory.java \
classpath/java/net/DatagramPacket.java \ classpath/java/net/DatagramPacket.java \
java/net/DatagramSocket.java \ classpath/java/net/DatagramSocket.java \
classpath/java/net/DatagramSocketImpl.java \ classpath/java/net/DatagramSocketImpl.java \
classpath/java/net/DatagramSocketImplFactory.java \ classpath/java/net/DatagramSocketImplFactory.java \
classpath/java/net/FileNameMap.java \ classpath/java/net/FileNameMap.java \
...@@ -4415,7 +4416,7 @@ classpath/java/net/Proxy.java \ ...@@ -4415,7 +4416,7 @@ classpath/java/net/Proxy.java \
classpath/java/net/ProxySelector.java \ classpath/java/net/ProxySelector.java \
classpath/java/net/ResolverCache.java \ classpath/java/net/ResolverCache.java \
classpath/java/net/ServerSocket.java \ classpath/java/net/ServerSocket.java \
java/net/Socket.java \ classpath/java/net/Socket.java \
classpath/java/net/SocketAddress.java \ classpath/java/net/SocketAddress.java \
classpath/java/net/SocketException.java \ classpath/java/net/SocketException.java \
classpath/java/net/SocketImpl.java \ classpath/java/net/SocketImpl.java \
...@@ -9973,7 +9974,7 @@ java/lang/Class.lo: classpath/lib/java/lang/Class.class ...@@ -9973,7 +9974,7 @@ java/lang/Class.lo: classpath/lib/java/lang/Class.class
gnu-CORBA.lo: $(gnu_CORBA_source_files) gnu-CORBA.lo: $(gnu_CORBA_source_files)
@find $(srcdir)/classpath/lib/gnu/CORBA -name '*.class' > gnu-CORBA.list @find $(srcdir)/classpath/lib/gnu/CORBA -name '*.class' > gnu-CORBA.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-CORBA.lo @gnu-CORBA.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-CORBA.lo @gnu-CORBA.list
@rm -f gnu-CORBA.list @rm -f gnu-CORBA.list
gnu/awt.list: $(gnu_awt_source_files) gnu/awt.list: $(gnu_awt_source_files)
...@@ -10122,7 +10123,7 @@ gnu/java/awt/dnd.list: $(gnu_java_awt_dnd_source_files) ...@@ -10122,7 +10123,7 @@ gnu/java/awt/dnd.list: $(gnu_java_awt_dnd_source_files)
gnu-java-awt-dnd-peer-gtk.lo: $(gnu_java_awt_dnd_peer_gtk_source_files) gnu-java-awt-dnd-peer-gtk.lo: $(gnu_java_awt_dnd_peer_gtk_source_files)
@find $(srcdir)/classpath/lib/gnu/java/awt/dnd/peer/gtk -name '*.class' > gnu-java-awt-dnd-peer-gtk.list @find $(srcdir)/classpath/lib/gnu/java/awt/dnd/peer/gtk -name '*.class' > gnu-java-awt-dnd-peer-gtk.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-dnd-peer-gtk.lo @gnu-java-awt-dnd-peer-gtk.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-dnd-peer-gtk.lo @gnu-java-awt-dnd-peer-gtk.list
@rm -f gnu-java-awt-dnd-peer-gtk.list @rm -f gnu-java-awt-dnd-peer-gtk.list
gnu/java/awt/font.list: $(gnu_java_awt_font_source_files) gnu/java/awt/font.list: $(gnu_java_awt_font_source_files)
...@@ -10169,7 +10170,7 @@ gnu/java/awt/peer.list: $(gnu_java_awt_peer_source_files) ...@@ -10169,7 +10170,7 @@ gnu/java/awt/peer.list: $(gnu_java_awt_peer_source_files)
gnu-java-awt-peer-gtk.lo: $(gnu_java_awt_peer_gtk_source_files) gnu-java-awt-peer-gtk.lo: $(gnu_java_awt_peer_gtk_source_files)
@find $(srcdir)/classpath/lib/gnu/java/awt/peer/gtk -name '*.class' > gnu-java-awt-peer-gtk.list @find $(srcdir)/classpath/lib/gnu/java/awt/peer/gtk -name '*.class' > gnu-java-awt-peer-gtk.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-peer-gtk.lo @gnu-java-awt-peer-gtk.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-peer-gtk.lo @gnu-java-awt-peer-gtk.list
@rm -f gnu-java-awt-peer-gtk.list @rm -f gnu-java-awt-peer-gtk.list
gnu/java/awt/peer/headless.list: $(gnu_java_awt_peer_headless_source_files) gnu/java/awt/peer/headless.list: $(gnu_java_awt_peer_headless_source_files)
...@@ -10180,17 +10181,17 @@ gnu/java/awt/peer/headless.list: $(gnu_java_awt_peer_headless_source_files) ...@@ -10180,17 +10181,17 @@ gnu/java/awt/peer/headless.list: $(gnu_java_awt_peer_headless_source_files)
gnu-java-awt-peer-qt.lo: $(gnu_java_awt_peer_qt_source_files) gnu-java-awt-peer-qt.lo: $(gnu_java_awt_peer_qt_source_files)
@find $(srcdir)/classpath/lib/gnu/java/awt/peer/qt -name '*.class' > gnu-java-awt-peer-qt.list @find $(srcdir)/classpath/lib/gnu/java/awt/peer/qt -name '*.class' > gnu-java-awt-peer-qt.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-peer-qt.lo @gnu-java-awt-peer-qt.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-peer-qt.lo @gnu-java-awt-peer-qt.list
@rm -f gnu-java-awt-peer-qt.list @rm -f gnu-java-awt-peer-qt.list
gnu-java-awt-peer-swing.lo: $(gnu_java_awt_peer_swing_source_files) gnu-java-awt-peer-swing.lo: $(gnu_java_awt_peer_swing_source_files)
@find $(srcdir)/classpath/lib/gnu/java/awt/peer/swing -name '*.class' > gnu-java-awt-peer-swing.list @find $(srcdir)/classpath/lib/gnu/java/awt/peer/swing -name '*.class' > gnu-java-awt-peer-swing.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-peer-swing.lo @gnu-java-awt-peer-swing.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-peer-swing.lo @gnu-java-awt-peer-swing.list
@rm -f gnu-java-awt-peer-swing.list @rm -f gnu-java-awt-peer-swing.list
gnu-java-awt-peer-x.lo: $(gnu_java_awt_peer_x_source_files) gnu-java-awt-peer-x.lo: $(gnu_java_awt_peer_x_source_files)
@find $(srcdir)/classpath/lib/gnu/java/awt/peer/x -name '*.class' > gnu-java-awt-peer-x.list @find $(srcdir)/classpath/lib/gnu/java/awt/peer/x -name '*.class' > gnu-java-awt-peer-x.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-peer-x.lo @gnu-java-awt-peer-x.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-awt-peer-x.lo @gnu-java-awt-peer-x.list
@rm -f gnu-java-awt-peer-x.list @rm -f gnu-java-awt-peer-x.list
gnu/java/awt/print.list: $(gnu_java_awt_print_source_files) gnu/java/awt/print.list: $(gnu_java_awt_print_source_files)
...@@ -10201,7 +10202,7 @@ gnu/java/awt/print.list: $(gnu_java_awt_print_source_files) ...@@ -10201,7 +10202,7 @@ gnu/java/awt/print.list: $(gnu_java_awt_print_source_files)
gnu-java-beans.lo: $(gnu_java_beans_source_files) gnu-java-beans.lo: $(gnu_java_beans_source_files)
@find $(srcdir)/classpath/lib/gnu/java/beans -name '*.class' > gnu-java-beans.list @find $(srcdir)/classpath/lib/gnu/java/beans -name '*.class' > gnu-java-beans.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-beans.lo @gnu-java-beans.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-beans.lo @gnu-java-beans.list
@rm -f gnu-java-beans.list @rm -f gnu-java-beans.list
gnu/java/io.list: $(gnu_java_io_source_files) gnu/java/io.list: $(gnu_java_io_source_files)
...@@ -10494,7 +10495,7 @@ gnu/java/util/prefs.list: $(gnu_java_util_prefs_source_files) ...@@ -10494,7 +10495,7 @@ gnu/java/util/prefs.list: $(gnu_java_util_prefs_source_files)
gnu-java-util-prefs-gconf.lo: $(gnu_java_util_prefs_gconf_source_files) gnu-java-util-prefs-gconf.lo: $(gnu_java_util_prefs_gconf_source_files)
@find $(srcdir)/classpath/lib/gnu/java/util/prefs/gconf -name '*.class' > gnu-java-util-prefs-gconf.list @find $(srcdir)/classpath/lib/gnu/java/util/prefs/gconf -name '*.class' > gnu-java-util-prefs-gconf.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-util-prefs-gconf.lo @gnu-java-util-prefs-gconf.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-java-util-prefs-gconf.lo @gnu-java-util-prefs-gconf.list
@rm -f gnu-java-util-prefs-gconf.list @rm -f gnu-java-util-prefs-gconf.list
gnu/java/util/regex.list: $(gnu_java_util_regex_source_files) gnu/java/util/regex.list: $(gnu_java_util_regex_source_files)
...@@ -10775,7 +10776,7 @@ gnu/javax/print/ipp/attribute/supported.list: $(gnu_javax_print_ipp_attribute_su ...@@ -10775,7 +10776,7 @@ gnu/javax/print/ipp/attribute/supported.list: $(gnu_javax_print_ipp_attribute_su
gnu-javax-rmi.lo: $(gnu_javax_rmi_source_files) gnu-javax-rmi.lo: $(gnu_javax_rmi_source_files)
@find $(srcdir)/classpath/lib/gnu/javax/rmi -name '*.class' > gnu-javax-rmi.list @find $(srcdir)/classpath/lib/gnu/javax/rmi -name '*.class' > gnu-javax-rmi.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-javax-rmi.lo @gnu-javax-rmi.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-javax-rmi.lo @gnu-javax-rmi.list
@rm -f gnu-javax-rmi.list @rm -f gnu-javax-rmi.list
gnu/javax/security/auth.list: $(gnu_javax_security_auth_source_files) gnu/javax/security/auth.list: $(gnu_javax_security_auth_source_files)
...@@ -10798,7 +10799,7 @@ gnu/javax/security/auth/login.list: $(gnu_javax_security_auth_login_source_files ...@@ -10798,7 +10799,7 @@ gnu/javax/security/auth/login.list: $(gnu_javax_security_auth_login_source_files
gnu-javax-sound-midi.lo: $(gnu_javax_sound_midi_source_files) gnu-javax-sound-midi.lo: $(gnu_javax_sound_midi_source_files)
@find $(srcdir)/classpath/lib/gnu/javax/sound/midi -name '*.class' > gnu-javax-sound-midi.list @find $(srcdir)/classpath/lib/gnu/javax/sound/midi -name '*.class' > gnu-javax-sound-midi.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-javax-sound-midi.lo @gnu-javax-sound-midi.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-javax-sound-midi.lo @gnu-javax-sound-midi.list
@rm -f gnu-javax-sound-midi.list @rm -f gnu-javax-sound-midi.list
gnu/javax/sound/sampled/AU.list: $(gnu_javax_sound_sampled_AU_source_files) gnu/javax/sound/sampled/AU.list: $(gnu_javax_sound_sampled_AU_source_files)
...@@ -10899,47 +10900,47 @@ gnu/javax/swing/tree.list: $(gnu_javax_swing_tree_source_files) ...@@ -10899,47 +10900,47 @@ gnu/javax/swing/tree.list: $(gnu_javax_swing_tree_source_files)
gnu-xml-aelfred2.lo: $(gnu_xml_aelfred2_source_files) gnu-xml-aelfred2.lo: $(gnu_xml_aelfred2_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/aelfred2 -name '*.class' > gnu-xml-aelfred2.list @find $(srcdir)/classpath/lib/gnu/xml/aelfred2 -name '*.class' > gnu-xml-aelfred2.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-aelfred2.lo @gnu-xml-aelfred2.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-aelfred2.lo @gnu-xml-aelfred2.list
@rm -f gnu-xml-aelfred2.list @rm -f gnu-xml-aelfred2.list
gnu-xml-dom.lo: $(gnu_xml_dom_source_files) gnu-xml-dom.lo: $(gnu_xml_dom_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/dom -name '*.class' > gnu-xml-dom.list @find $(srcdir)/classpath/lib/gnu/xml/dom -name '*.class' > gnu-xml-dom.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-dom.lo @gnu-xml-dom.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-dom.lo @gnu-xml-dom.list
@rm -f gnu-xml-dom.list @rm -f gnu-xml-dom.list
gnu-xml-libxmlj.lo: $(gnu_xml_libxmlj_source_files) gnu-xml-libxmlj.lo: $(gnu_xml_libxmlj_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/libxmlj -name '*.class' > gnu-xml-libxmlj.list @find $(srcdir)/classpath/lib/gnu/xml/libxmlj -name '*.class' > gnu-xml-libxmlj.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-libxmlj.lo @gnu-xml-libxmlj.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-libxmlj.lo @gnu-xml-libxmlj.list
@rm -f gnu-xml-libxmlj.list @rm -f gnu-xml-libxmlj.list
gnu-xml-pipeline.lo: $(gnu_xml_pipeline_source_files) gnu-xml-pipeline.lo: $(gnu_xml_pipeline_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/pipeline -name '*.class' > gnu-xml-pipeline.list @find $(srcdir)/classpath/lib/gnu/xml/pipeline -name '*.class' > gnu-xml-pipeline.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-pipeline.lo @gnu-xml-pipeline.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-pipeline.lo @gnu-xml-pipeline.list
@rm -f gnu-xml-pipeline.list @rm -f gnu-xml-pipeline.list
gnu-xml-stream.lo: $(gnu_xml_stream_source_files) gnu-xml-stream.lo: $(gnu_xml_stream_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/stream -name '*.class' > gnu-xml-stream.list @find $(srcdir)/classpath/lib/gnu/xml/stream -name '*.class' > gnu-xml-stream.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-stream.lo @gnu-xml-stream.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-stream.lo @gnu-xml-stream.list
@rm -f gnu-xml-stream.list @rm -f gnu-xml-stream.list
gnu-xml-transform.lo: $(gnu_xml_transform_source_files) gnu-xml-transform.lo: $(gnu_xml_transform_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/transform -name '*.class' > gnu-xml-transform.list @find $(srcdir)/classpath/lib/gnu/xml/transform -name '*.class' > gnu-xml-transform.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-transform.lo @gnu-xml-transform.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-transform.lo @gnu-xml-transform.list
@rm -f gnu-xml-transform.list @rm -f gnu-xml-transform.list
gnu-xml-util.lo: $(gnu_xml_util_source_files) gnu-xml-util.lo: $(gnu_xml_util_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/util -name '*.class' > gnu-xml-util.list @find $(srcdir)/classpath/lib/gnu/xml/util -name '*.class' > gnu-xml-util.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-util.lo @gnu-xml-util.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-util.lo @gnu-xml-util.list
@rm -f gnu-xml-util.list @rm -f gnu-xml-util.list
gnu-xml-validation.lo: $(gnu_xml_validation_source_files) gnu-xml-validation.lo: $(gnu_xml_validation_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/validation -name '*.class' > gnu-xml-validation.list @find $(srcdir)/classpath/lib/gnu/xml/validation -name '*.class' > gnu-xml-validation.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-validation.lo @gnu-xml-validation.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-validation.lo @gnu-xml-validation.list
@rm -f gnu-xml-validation.list @rm -f gnu-xml-validation.list
gnu-xml-xpath.lo: $(gnu_xml_xpath_source_files) gnu-xml-xpath.lo: $(gnu_xml_xpath_source_files)
@find $(srcdir)/classpath/lib/gnu/xml/xpath -name '*.class' > gnu-xml-xpath.list @find $(srcdir)/classpath/lib/gnu/xml/xpath -name '*.class' > gnu-xml-xpath.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-xpath.lo @gnu-xml-xpath.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o gnu-xml-xpath.lo @gnu-xml-xpath.list
@rm -f gnu-xml-xpath.list @rm -f gnu-xml-xpath.list
java/applet.list: $(java_applet_source_files) java/applet.list: $(java_applet_source_files)
...@@ -11280,7 +11281,7 @@ javax/crypto/spec.list: $(javax_crypto_spec_source_files) ...@@ -11280,7 +11281,7 @@ javax/crypto/spec.list: $(javax_crypto_spec_source_files)
javax-imageio.lo: $(javax_imageio_source_files) javax-imageio.lo: $(javax_imageio_source_files)
@find $(srcdir)/classpath/lib/javax/imageio -name '*.class' > javax-imageio.list @find $(srcdir)/classpath/lib/javax/imageio -name '*.class' > javax-imageio.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o javax-imageio.lo @javax-imageio.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o javax-imageio.lo @javax-imageio.list
@rm -f javax-imageio.list @rm -f javax-imageio.list
javax/management.list: $(javax_management_source_files) javax/management.list: $(javax_management_source_files)
...@@ -11369,7 +11370,7 @@ javax/print/event.list: $(javax_print_event_source_files) ...@@ -11369,7 +11370,7 @@ javax/print/event.list: $(javax_print_event_source_files)
javax-rmi.lo: $(javax_rmi_source_files) javax-rmi.lo: $(javax_rmi_source_files)
@find $(srcdir)/classpath/lib/javax/rmi -name '*.class' > javax-rmi.list @find $(srcdir)/classpath/lib/javax/rmi -name '*.class' > javax-rmi.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o javax-rmi.lo @javax-rmi.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o javax-rmi.lo @javax-rmi.list
@rm -f javax-rmi.list @rm -f javax-rmi.list
javax/security/auth.list: $(javax_security_auth_source_files) javax/security/auth.list: $(javax_security_auth_source_files)
...@@ -11566,7 +11567,7 @@ javax/transaction/xa.list: $(javax_transaction_xa_source_files) ...@@ -11566,7 +11567,7 @@ javax/transaction/xa.list: $(javax_transaction_xa_source_files)
javax-xml.lo: $(javax_xml_source_files) javax-xml.lo: $(javax_xml_source_files)
@find $(srcdir)/classpath/lib/javax/xml -name '*.class' > javax-xml.list @find $(srcdir)/classpath/lib/javax/xml -name '*.class' > javax-xml.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o javax-xml.lo @javax-xml.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o javax-xml.lo @javax-xml.list
@rm -f javax-xml.list @rm -f javax-xml.list
org/ietf/jgss.list: $(org_ietf_jgss_source_files) org/ietf/jgss.list: $(org_ietf_jgss_source_files)
...@@ -11577,22 +11578,22 @@ org/ietf/jgss.list: $(org_ietf_jgss_source_files) ...@@ -11577,22 +11578,22 @@ org/ietf/jgss.list: $(org_ietf_jgss_source_files)
org-omg.lo: $(org_omg_source_files) org-omg.lo: $(org_omg_source_files)
@find $(srcdir)/classpath/lib/org/omg -name '*.class' > org-omg.list @find $(srcdir)/classpath/lib/org/omg -name '*.class' > org-omg.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o org-omg.lo @org-omg.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o org-omg.lo @org-omg.list
@rm -f org-omg.list @rm -f org-omg.list
org-relaxng.lo: $(org_relaxng_source_files) org-relaxng.lo: $(org_relaxng_source_files)
@find $(srcdir)/classpath/lib/org/relaxng -name '*.class' > org-relaxng.list @find $(srcdir)/classpath/lib/org/relaxng -name '*.class' > org-relaxng.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o org-relaxng.lo @org-relaxng.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o org-relaxng.lo @org-relaxng.list
@rm -f org-relaxng.list @rm -f org-relaxng.list
org-w3c.lo: $(org_w3c_source_files) org-w3c.lo: $(org_w3c_source_files)
@find $(srcdir)/classpath/lib/org/w3c -name '*.class' > org-w3c.list @find $(srcdir)/classpath/lib/org/w3c -name '*.class' > org-w3c.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o org-w3c.lo @org-w3c.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o org-w3c.lo @org-w3c.list
@rm -f org-w3c.list @rm -f org-w3c.list
org-xml.lo: $(org_xml_source_files) org-xml.lo: $(org_xml_source_files)
@find $(srcdir)/classpath/lib/org/xml -name '*.class' > org-xml.list @find $(srcdir)/classpath/lib/org/xml -name '*.class' > org-xml.list
$(LTGCJCOMPILE) -fjni -findirect-dispatch -fno-indirect-classes -c -o org-xml.lo @org-xml.list $(LTGCJCOMPILE) -fsource-filename=$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o org-xml.lo @org-xml.list
@rm -f org-xml.list @rm -f org-xml.list
sun/misc.list: $(sun_misc_source_files) sun/misc.list: $(sun_misc_source_files)
......
2007-02-12 Tom Tromey <tromey@redhat.com>
* java/util/Collections.java (UnmodifiableMap.toArray): Imported
changes from Classpath.
2007-02-09 Gary Benson <gbenson@redhat.com> 2007-02-09 Gary Benson <gbenson@redhat.com>
* javax/management/ObjectName.java * javax/management/ObjectName.java
......
...@@ -5115,7 +5115,7 @@ public class Collections ...@@ -5115,7 +5115,7 @@ public class Collections
// Map.Entry // Map.Entry
public Map.Entry<K,V>[] toArray() public Map.Entry<K,V>[] toArray()
{ {
Map.Entry<K,V>[] mapEntryResult = (Map.Entry<K,V>[]) super.toArray(); Object[] mapEntryResult = super.toArray();
UnmodifiableMapEntry<K,V> result[] = null; UnmodifiableMapEntry<K,V> result[] = null;
if (mapEntryResult != null) if (mapEntryResult != null)
...@@ -5123,21 +5123,21 @@ public class Collections ...@@ -5123,21 +5123,21 @@ public class Collections
result = (UnmodifiableMapEntry<K,V>[]) result = (UnmodifiableMapEntry<K,V>[])
new UnmodifiableMapEntry[mapEntryResult.length]; new UnmodifiableMapEntry[mapEntryResult.length];
for (int i = 0; i < mapEntryResult.length; ++i) for (int i = 0; i < mapEntryResult.length; ++i)
result[i] = new UnmodifiableMapEntry(mapEntryResult[i]); result[i] = new UnmodifiableMapEntry<K,V>((Map.Entry<K,V>)mapEntryResult[i]);
} }
return result; return result;
} }
// The array returned is an array of UnmodifiableMapEntry instead of // The array returned is an array of UnmodifiableMapEntry instead of
// Map.Entry // Map.Entry
public Map.Entry<K,V>[] toArray(Map.Entry<K,V>[] array) public <S> S[] toArray(S[] array)
{ {
super.toArray(array); S[] result = super.toArray(array);
if (array != null) if (result != null)
for (int i = 0; i < array.length; i++) for (int i = 0; i < result.length; i++)
array[i] = array[i] =
new UnmodifiableMapEntry<K,V>(array[i]); (S) new UnmodifiableMapEntry<K,V>((Map.Entry<K,V>) result[i]);
return array; return array;
} }
......
/* PlainDatagramSocketImpl.java -- Default DatagramSocket implementation /* PlainDatagramSocketImpl.java -- Default DatagramSocket implementation
Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -119,7 +119,7 @@ public final class PlainDatagramSocketImpl extends DatagramSocketImpl ...@@ -119,7 +119,7 @@ public final class PlainDatagramSocketImpl extends DatagramSocketImpl
/** /**
* Default do nothing constructor * Default do nothing constructor
*/ */
public PlainDatagramSocketImpl() public PlainDatagramSocketImpl() throws IOException
{ {
} }
......
/* PlainSocketImpl.java -- Default socket implementation /* PlainSocketImpl.java -- Default socket implementation
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -110,6 +110,9 @@ public final class PlainSocketImpl extends SocketImpl ...@@ -110,6 +110,9 @@ public final class PlainSocketImpl extends SocketImpl
// localAddress cache // localAddress cache
InetAddress localAddress; InetAddress localAddress;
// Local address as an InetSocketAddress.
InetSocketAddress localSocketAddress;
/** /**
* A cached copy of the in stream for reading from the socket. * A cached copy of the in stream for reading from the socket.
*/ */
...@@ -325,6 +328,24 @@ public final class PlainSocketImpl extends SocketImpl ...@@ -325,6 +328,24 @@ public final class PlainSocketImpl extends SocketImpl
protected native void sendUrgentData(int data) throws IOException; protected native void sendUrgentData(int data) throws IOException;
public synchronized InetSocketAddress getLocalAddress()
{
if (localSocketAddress == null)
{
try
{
localSocketAddress
= new InetSocketAddress ((InetAddress) getOption(SocketOptions.SO_BINDADDR),
localport);
}
catch (SocketException _)
{
return null;
}
}
return localSocketAddress;
}
/** /**
* Returns an InputStream object for reading from this socket. This will * Returns an InputStream object for reading from this socket. This will
* be an instance of SocketInputStream. * be an instance of SocketInputStream.
......
/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation /* Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -364,7 +364,7 @@ gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jbyteArray b, jint off ...@@ -364,7 +364,7 @@ gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jbyteArray b, jint off
if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b)) if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
throw new ::java::lang::ArrayIndexOutOfBoundsException; throw new ::java::lang::ArrayIndexOutOfBoundsException;
write_helper (this$0->native_fd, elements (b) + offset * sizeof (jbyte), len); write_helper (this$0->native_fd, elements (b) + offset, len);
} }
static void static void
...@@ -435,8 +435,7 @@ gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer, ...@@ -435,8 +435,7 @@ gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer,
if (offset < 0 || count < 0 || offset + count > bsize) if (offset < 0 || count < 0 || offset + count > bsize)
throw new ::java::lang::ArrayIndexOutOfBoundsException; throw new ::java::lang::ArrayIndexOutOfBoundsException;
return read_helper (this$0, return read_helper (this$0, elements (buffer) + offset, count);
elements (buffer) + offset * sizeof (jbyte), count);
} }
static jint static jint
......
/* DatagramSocket.java -- A class to model UDP sockets
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.net;
import gnu.classpath.SystemProperties;
import gnu.java.net.PlainDatagramSocketImpl;
import gnu.java.nio.DatagramChannelImpl;
import java.io.IOException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.IllegalBlockingModeException;
/**
* Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Believed complete and correct.
*/
/**
* This class models a connectionless datagram socket that sends
* individual packets of data across the network. In the TCP/IP world,
* this means UDP. Datagram packets do not have guaranteed delivery,
* or any guarantee about the order the data will be received on the
* remote host.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Warren Levy (warrenl@cygnus.com)
* @date May 3, 1999.
*/
public class DatagramSocket
{
/**
* This is the user DatagramSocketImplFactory for this class. If this
* variable is null, a default factory is used.
*/
private static DatagramSocketImplFactory factory;
/**
* This is the implementation object used by this socket.
*/
private DatagramSocketImpl impl;
/**
* True if socket implementation was created.
*/
private boolean implCreated;
/**
* This is the address we are "connected" to
*/
private InetAddress remoteAddress;
/**
* This is the port we are "connected" to
*/
private int remotePort = -1;
/**
* True if socket is bound.
*/
private boolean bound;
/**
* Creates a <code>DatagramSocket</code> from a specified
* <code>DatagramSocketImpl</code> instance
*
* @param impl The <code>DatagramSocketImpl</code> the socket will be
* created from
*
* @since 1.4
*/
protected DatagramSocket(DatagramSocketImpl impl)
{
if (impl == null)
throw new NullPointerException("impl may not be null");
this.impl = impl;
this.remoteAddress = null;
this.remotePort = -1;
}
/**
* Initializes a new instance of <code>DatagramSocket</code> that binds to
* a random port and every address on the local machine.
*
* @exception SocketException If an error occurs.
* @exception SecurityException If a security manager exists and
* its <code>checkListen</code> method doesn't allow the operation.
*/
public DatagramSocket() throws SocketException
{
this(new InetSocketAddress(0));
}
/**
* Initializes a new instance of <code>DatagramSocket</code> that binds to
* the specified port and every address on the local machine.
*
* @param port The local port number to bind to.
*
* @exception SecurityException If a security manager exists and its
* <code>checkListen</code> method doesn't allow the operation.
* @exception SocketException If an error occurs.
*/
public DatagramSocket(int port) throws SocketException
{
this(new InetSocketAddress(port));
}
/**
* Initializes a new instance of <code>DatagramSocket</code> that binds to
* the specified local port and address.
*
* @param port The local port number to bind to.
* @param addr The local address to bind to.
*
* @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation.
* @exception SocketException If an error occurs.
*/
public DatagramSocket(int port, InetAddress addr) throws SocketException
{
this(new InetSocketAddress(addr, port));
}
/**
* Initializes a new instance of <code>DatagramSocket</code> that binds to
* the specified local port and address.
*
* @param address The local address and port number to bind to.
*
* @exception SecurityException If a security manager exists and its
* <code>checkListen</code> method doesn't allow the operation.
* @exception SocketException If an error occurs.
*
* @since 1.4
*/
public DatagramSocket(SocketAddress address) throws SocketException
{
String propVal = SystemProperties.getProperty("impl.prefix");
if (propVal == null || propVal.equals(""))
{
if (factory != null)
impl = factory.createDatagramSocketImpl();
else
impl = new PlainDatagramSocketImpl();
}
else
try
{
impl =
(DatagramSocketImpl) Class.forName("java.net." + propVal
+ "DatagramSocketImpl")
.newInstance();
}
catch (Exception e)
{
System.err.println("Could not instantiate class: java.net."
+ propVal + "DatagramSocketImpl");
impl = new PlainDatagramSocketImpl();
}
if (address != null)
bind(address);
}
// This needs to be accessible from java.net.MulticastSocket
DatagramSocketImpl getImpl() throws SocketException
{
try
{
if (! implCreated)
{
impl.create();
implCreated = true;
}
return impl;
}
catch (IOException e)
{
SocketException se = new SocketException();
se.initCause(e);
throw se;
}
}
/**
* Closes this datagram socket.
*/
public void close()
{
if (isClosed())
return;
try
{
getImpl().close();
}
catch (SocketException e)
{
// Ignore this case, just close the socket in finally clause.
}
finally
{
remoteAddress = null;
remotePort = -1;
impl = null;
}
try
{
if (getChannel() != null)
getChannel().close();
}
catch (IOException e)
{
// Do nothing.
}
}
/**
* This method returns the remote address to which this socket is
* connected. If this socket is not connected, then this method will
* return <code>null</code>.
*
* @return The remote address.
*
* @since 1.2
*/
public InetAddress getInetAddress()
{
return remoteAddress;
}
/**
* This method returns the remote port to which this socket is
* connected. If this socket is not connected, then this method will
* return -1.
*
* @return The remote port.
*
* @since 1.2
*/
public int getPort()
{
return remotePort;
}
/**
* Returns the local address this datagram socket is bound to.
*
* @return The local address is the socket is bound or null
*
* @since 1.1
*/
public InetAddress getLocalAddress()
{
if (! isBound())
return null;
InetAddress localAddr;
try
{
localAddr =
(InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR);
SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkConnect(localAddr.getHostName(), -1);
}
catch (SecurityException e)
{
localAddr = InetAddress.ANY_IF;
}
catch (SocketException e)
{
// This cannot happen as we are bound.
return null;
}
return localAddr;
}
/**
* Returns the local port this socket is bound to.
*
* @return The local port number.
*/
public int getLocalPort()
{
if (isClosed())
return -1;
try
{
return getImpl().getLocalPort();
}
catch (SocketException e)
{
// This cannot happen as we are bound.
return 0;
}
}
/**
* Returns the value of the socket's SO_TIMEOUT setting. If this method
* returns 0 then SO_TIMEOUT is disabled.
*
* @return The current timeout in milliseconds.
*
* @exception SocketException If an error occurs.
*
* @since 1.1
*/
public synchronized int getSoTimeout() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_TIMEOUT);
if (buf instanceof Integer)
return ((Integer) buf).intValue();
throw new SocketException("unexpected type");
}
/**
* Sets the value of the socket's SO_TIMEOUT value. A value of 0 will
* disable SO_TIMEOUT. Any other value is the number of milliseconds
* a socket read/write will block before timing out.
*
* @param timeout The new SO_TIMEOUT value in milliseconds.
*
* @exception SocketException If an error occurs.
*
* @since 1.1
*/
public synchronized void setSoTimeout(int timeout) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (timeout < 0)
throw new IllegalArgumentException("Invalid timeout: " + timeout);
getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
}
/**
* This method returns the value of the system level socket option
* SO_SNDBUF, which is used by the operating system to tune buffer
* sizes for data transfers.
*
* @return The send buffer size.
*
* @exception SocketException If an error occurs.
*
* @since 1.2
*/
public int getSendBufferSize() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF);
if (buf instanceof Integer)
return ((Integer) buf).intValue();
throw new SocketException("unexpected type");
}
/**
* This method sets the value for the system level socket option
* SO_SNDBUF to the specified value. Note that valid values for this
* option are specific to a given operating system.
*
* @param size The new send buffer size.
*
* @exception SocketException If an error occurs.
* @exception IllegalArgumentException If size is 0 or negative.
*
* @since 1.2
*/
public void setSendBufferSize(int size) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (size < 0)
throw new IllegalArgumentException("Buffer size is less than 0");
getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size));
}
/**
* This method returns the value of the system level socket option
* SO_RCVBUF, which is used by the operating system to tune buffer
* sizes for data transfers.
*
* @return The receive buffer size.
*
* @exception SocketException If an error occurs.
*
* @since 1.2
*/
public int getReceiveBufferSize() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF);
if (buf instanceof Integer)
return ((Integer) buf).intValue();
throw new SocketException("unexpected type");
}
/**
* This method sets the value for the system level socket option
* SO_RCVBUF to the specified value. Note that valid values for this
* option are specific to a given operating system.
*
* @param size The new receive buffer size.
*
* @exception SocketException If an error occurs.
* @exception IllegalArgumentException If size is 0 or negative.
*
* @since 1.2
*/
public void setReceiveBufferSize(int size) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (size < 0)
throw new IllegalArgumentException("Buffer size is less than 0");
getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
}
/**
* This method connects this socket to the specified address and port.
* When a datagram socket is connected, it will only send or receive
* packets to and from the host to which it is connected. A multicast
* socket that is connected may only send and not receive packets.
*
* @param address The address to connect this socket to.
* @param port The port to connect this socket to.
*
* @exception IllegalArgumentException If address or port are invalid.
* @exception SecurityException If the caller is not allowed to send
* datagrams to or receive from this address and port.
*
* @since 1.2
*/
public void connect(InetAddress address, int port)
{
if (address == null)
throw new IllegalArgumentException("Connect address may not be null");
if ((port < 1) || (port > 65535))
throw new IllegalArgumentException("Port number is illegal: " + port);
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkConnect(address.getHostName(), port);
try
{
getImpl().connect(address, port);
remoteAddress = address;
remotePort = port;
}
catch (SocketException e)
{
// This means simply not connected or connect not implemented.
}
}
/**
* This method disconnects this socket from the address/port it was
* connected to. If the socket was not connected in the first place,
* this method does nothing.
*
* @since 1.2
*/
public void disconnect()
{
if (! isConnected())
return;
try
{
getImpl().disconnect();
}
catch (SocketException e)
{
// This cannot happen as we are connected.
}
finally
{
remoteAddress = null;
remotePort = -1;
}
}
/**
* Reads a datagram packet from the socket. Note that this method
* will block until a packet is received from the network. On return,
* the passed in <code>DatagramPacket</code> is populated with the data
* received and all the other information about the packet.
*
* @param p A <code>DatagramPacket</code> for storing the data
*
* @exception IOException If an error occurs.
* @exception SocketTimeoutException If setSoTimeout was previously called
* and the timeout has expired.
* @exception PortUnreachableException If the socket is connected to a
* currently unreachable destination. Note, there is no guarantee that the
* exception will be thrown.
* @exception IllegalBlockingModeException If this socket has an associated
* channel, and the channel is in non-blocking mode.
* @exception SecurityException If a security manager exists and its
* checkAccept method doesn't allow the receive.
*/
public synchronized void receive(DatagramPacket p) throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
if (remoteAddress != null && remoteAddress.isMulticastAddress())
throw new IOException
("Socket connected to a multicast address my not receive");
if (getChannel() != null && ! getChannel().isBlocking()
&& ! ((DatagramChannelImpl) getChannel()).isInChannelOperation())
throw new IllegalBlockingModeException();
getImpl().receive(p);
SecurityManager s = System.getSecurityManager();
if (s != null && isConnected())
s.checkAccept(p.getAddress().getHostName(), p.getPort());
}
/**
* Sends the specified packet. The host and port to which the packet
* are to be sent should be set inside the packet.
*
* @param p The datagram packet to send.
*
* @exception IOException If an error occurs.
* @exception SecurityException If a security manager exists and its
* checkMulticast or checkConnect method doesn't allow the send.
* @exception PortUnreachableException If the socket is connected to a
* currently unreachable destination. Note, there is no guarantee that the
* exception will be thrown.
* @exception IllegalBlockingModeException If this socket has an associated
* channel, and the channel is in non-blocking mode.
*/
public void send(DatagramPacket p) throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
// JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api.
SecurityManager s = System.getSecurityManager();
if (s != null && ! isConnected())
{
InetAddress addr = p.getAddress();
if (addr.isMulticastAddress())
s.checkMulticast(addr);
else
s.checkConnect(addr.getHostAddress(), p.getPort());
}
if (isConnected())
{
if (p.getAddress() != null
&& (remoteAddress != p.getAddress() || remotePort != p.getPort()))
throw new IllegalArgumentException
("DatagramPacket address does not match remote address");
}
// FIXME: if this is a subclass of MulticastSocket,
// use getTimeToLive for TTL val.
if (getChannel() != null && ! getChannel().isBlocking()
&& ! ((DatagramChannelImpl) getChannel()).isInChannelOperation())
throw new IllegalBlockingModeException();
getImpl().send(p);
}
/**
* Binds the socket to the given socket address.
*
* @param address The socket address to bind to.
*
* @exception SocketException If an error occurs.
* @exception SecurityException If a security manager exists and
* its checkListen method doesn't allow the operation.
* @exception IllegalArgumentException If address type is not supported.
*
* @since 1.4
*/
public void bind(SocketAddress address) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (! (address instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type");
InetAddress addr = ((InetSocketAddress) address).getAddress();
int port = ((InetSocketAddress) address).getPort();
if (port < 0 || port > 65535)
throw new IllegalArgumentException("Invalid port: " + port);
SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkListen(port);
if (addr == null)
addr = InetAddress.ANY_IF;
try
{
getImpl().bind(port, addr);
bound = true;
}
catch (SocketException exception)
{
getImpl().close();
throw exception;
}
catch (RuntimeException exception)
{
getImpl().close();
throw exception;
}
catch (Error error)
{
getImpl().close();
throw error;
}
}
/**
* Checks if the datagram socket is closed.
*
* @return True if socket is closed, false otherwise.
*
* @since 1.4
*/
public boolean isClosed()
{
return impl == null;
}
/**
* Returns the datagram channel assoziated with this datagram socket.
*
* @return The associated <code>DatagramChannel</code> object or null
*
* @since 1.4
*/
public DatagramChannel getChannel()
{
return null;
}
/**
* Connects the datagram socket to a specified socket address.
*
* @param address The socket address to connect to.
*
* @exception SocketException If an error occurs.
* @exception IllegalArgumentException If address type is not supported.
*
* @since 1.4
*/
public void connect(SocketAddress address) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (! (address instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type");
InetSocketAddress tmp = (InetSocketAddress) address;
connect(tmp.getAddress(), tmp.getPort());
}
/**
* Returns the binding state of the socket.
*
* @return True if socket bound, false otherwise.
*
* @since 1.4
*/
public boolean isBound()
{
return bound;
}
/**
* Returns the connection state of the socket.
*
* @return True if socket is connected, false otherwise.
*
* @since 1.4
*/
public boolean isConnected()
{
return remoteAddress != null;
}
/**
* Returns the SocketAddress of the host this socket is conneted to
* or null if this socket is not connected.
*
* @return The socket address of the remote host if connected or null
*
* @since 1.4
*/
public SocketAddress getRemoteSocketAddress()
{
if (! isConnected())
return null;
return new InetSocketAddress(remoteAddress, remotePort);
}
/**
* Returns the local SocketAddress this socket is bound to.
*
* @return The local SocketAddress or null if the socket is not bound.
*
* @since 1.4
*/
public SocketAddress getLocalSocketAddress()
{
if (! isBound())
return null;
return new InetSocketAddress(getLocalAddress(), getLocalPort());
}
/**
* Enables/Disables SO_REUSEADDR.
*
* @param on Whether or not to have SO_REUSEADDR turned on.
*
* @exception SocketException If an error occurs.
*
* @since 1.4
*/
public void setReuseAddress(boolean on) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
}
/**
* Checks if SO_REUSEADDR is enabled.
*
* @return True if SO_REUSEADDR is set on the socket, false otherwise.
*
* @exception SocketException If an error occurs.
*
* @since 1.4
*/
public boolean getReuseAddress() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_REUSEADDR);
if (buf instanceof Boolean)
return ((Boolean) buf).booleanValue();
throw new SocketException("unexpected type");
}
/**
* Enables/Disables SO_BROADCAST
*
* @param enable True if SO_BROADCAST should be enabled, false otherwise.
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public void setBroadcast(boolean enable) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.SO_BROADCAST, Boolean.valueOf(enable));
}
/**
* Checks if SO_BROADCAST is enabled
*
* @return Whether SO_BROADCAST is set
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public boolean getBroadcast() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_BROADCAST);
if (buf instanceof Boolean)
return ((Boolean) buf).booleanValue();
throw new SocketException("unexpected type");
}
/**
* Sets the traffic class value
*
* @param tc The traffic class
*
* @exception SocketException If an error occurs
* @exception IllegalArgumentException If tc value is illegal
*
* @see DatagramSocket#getTrafficClass()
*
* @since 1.4
*/
public void setTrafficClass(int tc) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (tc < 0 || tc > 255)
throw new IllegalArgumentException();
getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc));
}
/**
* Returns the current traffic class
*
* @return The current traffic class.
*
* @see DatagramSocket#setTrafficClass(int tc)
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public int getTrafficClass() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.IP_TOS);
if (buf instanceof Integer)
return ((Integer) buf).intValue();
throw new SocketException("unexpected type");
}
/**
* Sets the datagram socket implementation factory for the application
*
* @param fac The factory to set
*
* @exception IOException If an error occurs
* @exception SocketException If the factory is already defined
* @exception SecurityException If a security manager exists and its
* checkSetFactory method doesn't allow the operation
*/
public static void setDatagramSocketImplFactory(DatagramSocketImplFactory fac)
throws IOException
{
if (factory != null)
throw new SocketException("DatagramSocketImplFactory already defined");
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkSetFactory();
factory = fac;
}
}
/* Socket.java -- Client socket implementation
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.net;
import gnu.java.net.PlainSocketImpl;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.SocketChannel;
/* Written using on-line Java Platform 1.2 API Specification.
* Status: I believe all methods are implemented.
*/
/**
* This class models a client site socket. A socket is a TCP/IP endpoint
* for network communications conceptually similar to a file handle.
* <p>
* This class does not actually do any work. Instead, it redirects all of
* its calls to a socket implementation object which implements the
* <code>SocketImpl</code> interface. The implementation class is
* instantiated by factory class that implements the
* <code>SocketImplFactory interface</code>. A default
* factory is provided, however the factory may be set by a call to
* the <code>setSocketImplFactory</code> method. Note that this may only be
* done once per virtual machine. If a subsequent attempt is made to set the
* factory, a <code>SocketException</code> will be thrown.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Per Bothner (bothner@cygnus.com)
*/
public class Socket
{
/**
* This is the user SocketImplFactory for this class. If this variable is
* null, a default factory is used.
*/
static SocketImplFactory factory;
/**
* The implementation object to which calls are redirected
*/
// package-private because ServerSocket.implAccept() needs to access it.
SocketImpl impl;
/**
* True if socket implementation was created by calling their
* create() method.
*/
// package-private because ServerSocket.implAccept() needs to access it.
boolean implCreated;
/**
* True if the socket is bound.
* Package private so it can be set from ServerSocket when accept is called.
*/
boolean bound;
/**
* True if input is shutdown.
*/
private boolean inputShutdown;
/**
* True if output is shutdown.
*/
private boolean outputShutdown;
/**
* Initializes a new instance of <code>Socket</code> object without
* connecting to a remote host. This useful for subclasses of socket that
* might want this behavior.
*
* @specnote This constructor is public since JDK 1.4
* @since 1.1
*/
public Socket()
{
if (factory != null)
impl = factory.createSocketImpl();
else
impl = new PlainSocketImpl();
}
/**
* Initializes a new instance of <code>Socket</code> object without
* connecting to a remote host. This is useful for subclasses of socket
* that might want this behavior.
* <p>
* Additionally, this socket will be created using the supplied
* implementation class instead the default class or one returned by a
* factory. If this value is <code>null</code>, the default Socket
* implementation is used.
*
* @param impl The <code>SocketImpl</code> to use for this
* <code>Socket</code>
*
* @exception SocketException If an error occurs
*
* @since 1.1
*/
protected Socket(SocketImpl impl) throws SocketException
{
if (impl == null)
this.impl = new PlainSocketImpl();
else
this.impl = impl;
}
/**
* Initializes a new instance of <code>Socket</code> and connects to the
* hostname and port specified as arguments.
*
* @param host The name of the host to connect to
* @param port The port number to connect to
*
* @exception UnknownHostException If the hostname cannot be resolved to a
* network address.
* @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
*/
public Socket(String host, int port)
throws UnknownHostException, IOException
{
this(InetAddress.getByName(host), port, null, 0, true);
}
/**
* Initializes a new instance of <code>Socket</code> and connects to the
* address and port number specified as arguments.
*
* @param address The address to connect to
* @param port The port number to connect to
*
* @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
*/
public Socket(InetAddress address, int port) throws IOException
{
this(address, port, null, 0, true);
}
/**
* Initializes a new instance of <code>Socket</code> that connects to the
* named host on the specified port and binds to the specified local address
* and port.
*
* @param host The name of the remote host to connect to.
* @param port The remote port to connect to.
* @param localAddr The local address to bind to.
* @param localPort The local port to bind to.
*
* @exception SecurityException If the <code>SecurityManager</code>
* exists and does not allow a connection to the specified host/port or
* binding to the specified local host/port.
* @exception IOException If a connection error occurs.
*
* @since 1.1
*/
public Socket(String host, int port, InetAddress localAddr, int localPort)
throws IOException
{
this(InetAddress.getByName(host), port, localAddr, localPort, true);
}
/**
* Initializes a new instance of <code>Socket</code> and connects to the
* address and port number specified as arguments, plus binds to the
* specified local address and port.
*
* @param address The remote address to connect to
* @param port The remote port to connect to
* @param localAddr The local address to connect to
* @param localPort The local port to connect to
*
* @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
*
* @since 1.1
*/
public Socket(InetAddress address, int port, InetAddress localAddr,
int localPort) throws IOException
{
this(address, port, localAddr, localPort, true);
}
/**
* Initializes a new instance of <code>Socket</code> and connects to the
* hostname and port specified as arguments. If the stream argument is set
* to <code>true</code>, then a stream socket is created. If it is
* <code>false</code>, a datagram socket is created.
*
* @param host The name of the host to connect to
* @param port The port to connect to
* @param stream <code>true</code> for a stream socket, <code>false</code>
* for a datagram socket
*
* @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
*
* @deprecated Use the <code>DatagramSocket</code> class to create
* datagram oriented sockets.
*/
public Socket(String host, int port, boolean stream)
throws IOException
{
this(InetAddress.getByName(host), port, null, 0, stream);
}
/**
* Initializes a new instance of <code>Socket</code> and connects to the
* address and port number specified as arguments. If the stream param is
* <code>true</code>, a stream socket will be created, otherwise a datagram
* socket is created.
*
* @param host The address to connect to
* @param port The port number to connect to
* @param stream <code>true</code> to create a stream socket,
* <code>false</code> to create a datagram socket.
*
* @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
*
* @deprecated Use the <code>DatagramSocket</code> class to create
* datagram oriented sockets.
*/
public Socket(InetAddress host, int port, boolean stream)
throws IOException
{
this(host, port, null, 0, stream);
}
/**
* This constructor is where the real work takes place. Connect to the
* specified address and port. Use default local values if not specified,
* otherwise use the local host and port passed in. Create as stream or
* datagram based on "stream" argument.
* <p>
*
* @param raddr The remote address to connect to
* @param rport The remote port to connect to
* @param laddr The local address to connect to
* @param lport The local port to connect to
* @param stream true for a stream socket, false for a datagram socket
*
* @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
*/
private Socket(InetAddress raddr, int rport, InetAddress laddr, int lport,
boolean stream) throws IOException
{
this();
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkConnect(raddr.getHostName(), rport);
// bind socket
SocketAddress bindaddr =
laddr == null ? null : new InetSocketAddress(laddr, lport);
bind(bindaddr);
// connect socket
connect(new InetSocketAddress(raddr, rport));
// FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
// i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
// that default. JDK 1.2 doc infers not to do a bind.
}
private SocketImpl getImpl() throws SocketException
{
try
{
if (! implCreated)
{
impl.create(true);
implCreated = true;
}
}
catch (IOException e)
{
SocketException se = new SocketException(e.toString());
se.initCause(e);
throw se;
}
return impl;
}
/**
* Binds the socket to the givent local address/port
*
* @param bindpoint The address/port to bind to
*
* @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
* @exception IllegalArgumentException If the address type is not supported
*
* @since 1.4
*/
public void bind(SocketAddress bindpoint) throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
// XXX: JDK 1.4.1 API documentation says that if bindpoint is null the
// socket will be bound to an ephemeral port and a valid local address.
if (bindpoint == null)
bindpoint = new InetSocketAddress(InetAddress.ANY_IF, 0);
if (! (bindpoint instanceof InetSocketAddress))
throw new IllegalArgumentException();
InetSocketAddress tmp = (InetSocketAddress) bindpoint;
// bind to address/port
try
{
getImpl().bind(tmp.getAddress(), tmp.getPort());
bound = true;
}
catch (IOException exception)
{
close();
throw exception;
}
catch (RuntimeException exception)
{
close();
throw exception;
}
catch (Error error)
{
close();
throw error;
}
}
/**
* Connects the socket with a remote address.
*
* @param endpoint The address to connect to
*
* @exception IOException If an error occurs
* @exception IllegalArgumentException If the addess type is not supported
* @exception IllegalBlockingModeException If this socket has an associated
* channel, and the channel is in non-blocking mode
*
* @since 1.4
*/
public void connect(SocketAddress endpoint) throws IOException
{
connect(endpoint, 0);
}
/**
* Connects the socket with a remote address. A timeout of zero is
* interpreted as an infinite timeout. The connection will then block
* until established or an error occurs.
*
* @param endpoint The address to connect to
* @param timeout The length of the timeout in milliseconds, or
* 0 to indicate no timeout.
*
* @exception IOException If an error occurs
* @exception IllegalArgumentException If the address type is not supported
* @exception IllegalBlockingModeException If this socket has an associated
* channel, and the channel is in non-blocking mode
* @exception SocketTimeoutException If the timeout is reached
*
* @since 1.4
*/
public void connect(SocketAddress endpoint, int timeout)
throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type");
// The Sun spec says that if we have an associated channel and
// it is in non-blocking mode, we throw an IllegalBlockingModeException.
// However, in our implementation if the channel itself initiated this
// operation, then we must honor it regardless of its blocking mode.
if (getChannel() != null && ! getChannel().isBlocking()
&& ! ((PlainSocketImpl) getImpl()).isInChannelOperation())
throw new IllegalBlockingModeException();
if (! isBound())
bind(null);
getImpl().connect(endpoint, timeout);
}
/**
* Returns the address of the remote end of the socket. If this socket
* is not connected, then <code>null</code> is returned.
*
* @return The remote address this socket is connected to
*/
public InetAddress getInetAddress()
{
if (! isConnected())
return null;
try
{
return getImpl().getInetAddress();
}
catch (SocketException e)
{
// This cannot happen as we are connected.
}
return null;
}
/**
* Returns the local address to which this socket is bound. If this socket
* is not connected, then a wildcard address, for which
* @see InetAddress#isAnyLocalAddress() is <code>true</code>, is returned.
*
* @return The local address
*
* @since 1.1
*/
public InetAddress getLocalAddress()
{
if (! isBound())
return InetAddress.ANY_IF;
InetAddress addr = null;
try
{
addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
// (hopefully) shouldn't happen
// throw new java.lang.InternalError
// ("Error in PlainSocketImpl.getOption");
return null;
}
// FIXME: According to libgcj, checkConnect() is supposed to be called
// before performing this operation. Problems: 1) We don't have the
// addr until after we do it, so we do a post check. 2). The docs I
// see don't require this in the Socket case, only DatagramSocket, but
// we'll assume they mean both.
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkConnect(addr.getHostName(), getLocalPort());
return addr;
}
/**
* Returns the port number of the remote end of the socket connection. If
* this socket is not connected, then 0 is returned.
*
* @return The remote port this socket is connected to
*/
public int getPort()
{
if (! isConnected())
return 0;
try
{
return getImpl().getPort();
}
catch (SocketException e)
{
// This cannot happen as we are connected.
}
return 0;
}
/**
* Returns the local port number to which this socket is bound. If this
* socket is not connected, then -1 is returned.
*
* @return The local port
*/
public int getLocalPort()
{
if (! isBound())
return -1;
try
{
if (getImpl() != null)
return getImpl().getLocalPort();
}
catch (SocketException e)
{
// This cannot happen as we are bound.
}
return -1;
}
/**
* Returns local socket address.
*
* @return the local socket address, null if not bound
*
* @since 1.4
*/
public SocketAddress getLocalSocketAddress()
{
if (! isBound())
return null;
InetAddress addr = getLocalAddress();
try
{
return new InetSocketAddress(addr, getImpl().getLocalPort());
}
catch (SocketException e)
{
// This cannot happen as we are bound.
return null;
}
}
/**
* Returns the remote socket address.
*
* @return the remote socket address, null of not connected
*
* @since 1.4
*/
public SocketAddress getRemoteSocketAddress()
{
if (! isConnected())
return null;
try
{
return new InetSocketAddress(getImpl().getInetAddress(),
getImpl().getPort());
}
catch (SocketException e)
{
// This cannot happen as we are connected.
return null;
}
}
/**
* Returns an InputStream for reading from this socket.
*
* @return The InputStream object
*
* @exception IOException If an error occurs or Socket is not connected
*/
public InputStream getInputStream() throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
if (! isConnected())
throw new IOException("not connected");
return getImpl().getInputStream();
}
/**
* Returns an OutputStream for writing to this socket.
*
* @return The OutputStream object
*
* @exception IOException If an error occurs or Socket is not connected
*/
public OutputStream getOutputStream() throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
if (! isConnected())
throw new IOException("not connected");
return getImpl().getOutputStream();
}
/**
* Sets the TCP_NODELAY option on the socket.
*
* @param on true to enable, false to disable
*
* @exception SocketException If an error occurs or Socket is not connected
*
* @since 1.1
*/
public void setTcpNoDelay(boolean on) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.TCP_NODELAY, Boolean.valueOf(on));
}
/**
* Tests whether or not the TCP_NODELAY option is set on the socket.
* Returns true if enabled, false if disabled. When on it disables the
* Nagle algorithm which means that packets are always send immediatly and
* never merged together to reduce network trafic.
*
* @return Whether or not TCP_NODELAY is set
*
* @exception SocketException If an error occurs or Socket not connected
*
* @since 1.1
*/
public boolean getTcpNoDelay() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object on = getImpl().getOption(SocketOptions.TCP_NODELAY);
if (on instanceof Boolean)
return (((Boolean) on).booleanValue());
else
throw new SocketException("Internal Error");
}
/**
* Sets the value of the SO_LINGER option on the socket. If the
* SO_LINGER option is set on a socket and there is still data waiting to
* be sent when the socket is closed, then the close operation will block
* until either that data is delivered or until the timeout period
* expires. The linger interval is specified in hundreths of a second
* (platform specific?)
*
* @param on true to enable SO_LINGER, false to disable
* @param linger The SO_LINGER timeout in hundreths of a second or -1 if
* SO_LINGER not set.
*
* @exception SocketException If an error occurs or Socket not connected
* @exception IllegalArgumentException If linger is negative
*
* @since 1.1
*/
public void setSoLinger(boolean on, int linger) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (on)
{
if (linger < 0)
throw new IllegalArgumentException("SO_LINGER must be >= 0");
if (linger > 65535)
linger = 65535;
getImpl().setOption(SocketOptions.SO_LINGER, new Integer(linger));
}
else
getImpl().setOption(SocketOptions.SO_LINGER, Boolean.valueOf(false));
}
/**
* Returns the value of the SO_LINGER option on the socket. If the
* SO_LINGER option is set on a socket and there is still data waiting to
* be sent when the socket is closed, then the close operation will block
* until either that data is delivered or until the timeout period
* expires. This method either returns the timeouts (in hundredths of
* of a second (platform specific?)) if SO_LINGER is set, or -1 if
* SO_LINGER is not set.
*
* @return The SO_LINGER timeout in hundreths of a second or -1
* if SO_LINGER not set
*
* @exception SocketException If an error occurs or Socket is not connected
*
* @since 1.1
*/
public int getSoLinger() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object linger = getImpl().getOption(SocketOptions.SO_LINGER);
if (linger instanceof Integer)
return (((Integer) linger).intValue());
else
return -1;
}
/**
* Sends urgent data through the socket
*
* @param data The data to send.
* Only the lowest eight bits of data are sent
*
* @exception IOException If an error occurs
*
* @since 1.4
*/
public void sendUrgentData(int data) throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().sendUrgentData(data);
}
/**
* Enables/disables the SO_OOBINLINE option
*
* @param on True if SO_OOBLINE should be enabled
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public void setOOBInline(boolean on) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.SO_OOBINLINE, Boolean.valueOf(on));
}
/**
* Returns the current setting of the SO_OOBINLINE option for this socket
*
* @return True if SO_OOBINLINE is set, false otherwise.
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public boolean getOOBInline() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_OOBINLINE);
if (buf instanceof Boolean)
return (((Boolean) buf).booleanValue());
else
throw new SocketException("Internal Error: Unexpected type");
}
/**
* Sets the value of the SO_TIMEOUT option on the socket. If this value
* is set, and an read/write is performed that does not complete within
* the timeout period, a short count is returned (or an EWOULDBLOCK signal
* would be sent in Unix if no data had been read). A value of 0 for
* this option implies that there is no timeout (ie, operations will
* block forever). On systems that have separate read and write timeout
* values, this method returns the read timeout. This
* value is in milliseconds.
*
* @param timeout The length of the timeout in milliseconds, or
* 0 to indicate no timeout.
*
* @exception SocketException If an error occurs or Socket not connected
*
* @since 1.1
*/
public synchronized void setSoTimeout(int timeout) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (timeout < 0)
throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");
getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
}
/**
* Returns the value of the SO_TIMEOUT option on the socket. If this value
* is set, and an read/write is performed that does not complete within
* the timeout period, a short count is returned (or an EWOULDBLOCK signal
* would be sent in Unix if no data had been read). A value of 0 for
* this option implies that there is no timeout (ie, operations will
* block forever). On systems that have separate read and write timeout
* values, this method returns the read timeout. This
* value is in thousandths of a second (implementation specific?).
*
* @return The length of the timeout in thousandth's of a second or 0
* if not set
*
* @exception SocketException If an error occurs or Socket not connected
*
* @since 1.1
*/
public synchronized int getSoTimeout() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object timeout = getImpl().getOption(SocketOptions.SO_TIMEOUT);
if (timeout instanceof Integer)
return (((Integer) timeout).intValue());
else
return 0;
}
/**
* This method sets the value for the system level socket option
* SO_SNDBUF to the specified value. Note that valid values for this
* option are specific to a given operating system.
*
* @param size The new send buffer size.
*
* @exception SocketException If an error occurs or Socket not connected
* @exception IllegalArgumentException If size is 0 or negative
*
* @since 1.2
*/
public void setSendBufferSize(int size) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (size <= 0)
throw new IllegalArgumentException("SO_SNDBUF value must be > 0");
getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size));
}
/**
* This method returns the value of the system level socket option
* SO_SNDBUF, which is used by the operating system to tune buffer
* sizes for data transfers.
*
* @return The send buffer size.
*
* @exception SocketException If an error occurs or socket not connected
*
* @since 1.2
*/
public int getSendBufferSize() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF);
if (buf instanceof Integer)
return (((Integer) buf).intValue());
else
throw new SocketException("Internal Error: Unexpected type");
}
/**
* This method sets the value for the system level socket option
* SO_RCVBUF to the specified value. Note that valid values for this
* option are specific to a given operating system.
*
* @param size The new receive buffer size.
*
* @exception SocketException If an error occurs or Socket is not connected
* @exception IllegalArgumentException If size is 0 or negative
*
* @since 1.2
*/
public void setReceiveBufferSize(int size) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (size <= 0)
throw new IllegalArgumentException("SO_RCVBUF value must be > 0");
getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
}
/**
* This method returns the value of the system level socket option
* SO_RCVBUF, which is used by the operating system to tune buffer
* sizes for data transfers.
*
* @return The receive buffer size.
*
* @exception SocketException If an error occurs or Socket is not connected
*
* @since 1.2
*/
public int getReceiveBufferSize() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF);
if (buf instanceof Integer)
return (((Integer) buf).intValue());
else
throw new SocketException("Internal Error: Unexpected type");
}
/**
* This method sets the value for the socket level socket option
* SO_KEEPALIVE.
*
* @param on True if SO_KEEPALIVE should be enabled
*
* @exception SocketException If an error occurs or Socket is not connected
*
* @since 1.3
*/
public void setKeepAlive(boolean on) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.SO_KEEPALIVE, Boolean.valueOf(on));
}
/**
* This method returns the value of the socket level socket option
* SO_KEEPALIVE.
*
* @return The setting
*
* @exception SocketException If an error occurs or Socket is not connected
*
* @since 1.3
*/
public boolean getKeepAlive() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_KEEPALIVE);
if (buf instanceof Boolean)
return (((Boolean) buf).booleanValue());
else
throw new SocketException("Internal Error: Unexpected type");
}
/**
* Closes the socket.
*
* @exception IOException If an error occurs
*/
public synchronized void close() throws IOException
{
if (isClosed())
return;
getImpl().close();
impl = null;
bound = false;
if (getChannel() != null)
getChannel().close();
}
/**
* Converts this <code>Socket</code> to a <code>String</code>.
*
* @return The <code>String</code> representation of this <code>Socket</code>
*/
public String toString()
{
try
{
if (isConnected())
return ("Socket[addr=" + getImpl().getInetAddress() + ",port="
+ getImpl().getPort() + ",localport="
+ getImpl().getLocalPort() + "]");
}
catch (SocketException e)
{
// This cannot happen as we are connected.
}
return "Socket[unconnected]";
}
/**
* Sets the <code>SocketImplFactory</code>. This may be done only once per
* virtual machine. Subsequent attempts will generate a
* <code>SocketException</code>. Note that a <code>SecurityManager</code>
* check is made prior to setting the factory. If
* insufficient privileges exist to set the factory, then an
* <code>IOException</code> will be thrown.
*
* @param fac the factory to set
*
* @exception SecurityException If the <code>SecurityManager</code> does
* not allow this operation.
* @exception SocketException If the SocketImplFactory is already defined
* @exception IOException If any other error occurs
*/
public static synchronized void setSocketImplFactory(SocketImplFactory fac)
throws IOException
{
// See if already set
if (factory != null)
throw new SocketException("SocketImplFactory already defined");
// Check permissions
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkSetFactory();
if (fac == null)
throw new SocketException("SocketImplFactory cannot be null");
factory = fac;
}
/**
* Closes the input side of the socket stream.
*
* @exception IOException If an error occurs.
*
* @since 1.3
*/
public void shutdownInput() throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().shutdownInput();
inputShutdown = true;
}
/**
* Closes the output side of the socket stream.
*
* @exception IOException If an error occurs.
*
* @since 1.3
*/
public void shutdownOutput() throws IOException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().shutdownOutput();
outputShutdown = true;
}
/**
* Returns the socket channel associated with this socket.
*
* @return the associated socket channel,
* null if no associated channel exists
*
* @since 1.4
*/
public SocketChannel getChannel()
{
return null;
}
/**
* Checks if the SO_REUSEADDR option is enabled
*
* @return True if SO_REUSEADDR is set, false otherwise.
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public boolean getReuseAddress() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object reuseaddr = getImpl().getOption(SocketOptions.SO_REUSEADDR);
if (! (reuseaddr instanceof Boolean))
throw new SocketException("Internal Error");
return ((Boolean) reuseaddr).booleanValue();
}
/**
* Enables/Disables the SO_REUSEADDR option
*
* @param reuseAddress true if SO_REUSEADDR should be enabled,
* false otherwise
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public void setReuseAddress(boolean reuseAddress) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.SO_REUSEADDR,
Boolean.valueOf(reuseAddress));
}
/**
* Returns the current traffic class
*
* @return The current traffic class.
*
* @exception SocketException If an error occurs
*
* @see Socket#setTrafficClass(int tc)
*
* @since 1.4
*/
public int getTrafficClass() throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
Object obj = getImpl().getOption(SocketOptions.IP_TOS);
if (obj instanceof Integer)
return ((Integer) obj).intValue();
else
throw new SocketException("Unexpected type");
}
/**
* Sets the traffic class value
*
* @param tc The traffic class
*
* @exception SocketException If an error occurs
* @exception IllegalArgumentException If tc value is illegal
*
* @see Socket#getTrafficClass()
*
* @since 1.4
*/
public void setTrafficClass(int tc) throws SocketException
{
if (isClosed())
throw new SocketException("socket is closed");
if (tc < 0 || tc > 255)
throw new IllegalArgumentException();
getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc));
}
/**
* Checks if the socket is connected
*
* @return True if socket is connected, false otherwise.
*
* @since 1.4
*/
public boolean isConnected()
{
try
{
if (getImpl() == null)
return false;
return getImpl().getInetAddress() != null;
}
catch (SocketException e)
{
return false;
}
}
/**
* Checks if the socket is already bound.
*
* @return True if socket is bound, false otherwise.
*
* @since 1.4
*/
public boolean isBound()
{
return bound;
}
/**
* Checks if the socket is closed.
*
* @return True if socket is closed, false otherwise.
*
* @since 1.4
*/
public boolean isClosed()
{
return impl == null;
}
/**
* Checks if the socket's input stream is shutdown
*
* @return True if input is shut down.
*
* @since 1.4
*/
public boolean isInputShutdown()
{
return inputShutdown;
}
/**
* Checks if the socket's output stream is shutdown
*
* @return True if output is shut down.
*
* @since 1.4
*/
public boolean isOutputShutdown()
{
return outputShutdown;
}
}
...@@ -4905,7 +4905,7 @@ classpath/java/net/ConnectException.java \ ...@@ -4905,7 +4905,7 @@ classpath/java/net/ConnectException.java \
classpath/java/net/ContentHandler.java \ classpath/java/net/ContentHandler.java \
classpath/java/net/ContentHandlerFactory.java \ classpath/java/net/ContentHandlerFactory.java \
classpath/java/net/DatagramPacket.java \ classpath/java/net/DatagramPacket.java \
java/net/DatagramSocket.java \ classpath/java/net/DatagramSocket.java \
classpath/java/net/DatagramSocketImpl.java \ classpath/java/net/DatagramSocketImpl.java \
classpath/java/net/DatagramSocketImplFactory.java \ classpath/java/net/DatagramSocketImplFactory.java \
classpath/java/net/FileNameMap.java \ classpath/java/net/FileNameMap.java \
...@@ -4928,7 +4928,7 @@ classpath/java/net/Proxy.java \ ...@@ -4928,7 +4928,7 @@ classpath/java/net/Proxy.java \
classpath/java/net/ProxySelector.java \ classpath/java/net/ProxySelector.java \
classpath/java/net/ResolverCache.java \ classpath/java/net/ResolverCache.java \
classpath/java/net/ServerSocket.java \ classpath/java/net/ServerSocket.java \
java/net/Socket.java \ classpath/java/net/Socket.java \
classpath/java/net/SocketAddress.java \ classpath/java/net/SocketAddress.java \
classpath/java/net/SocketException.java \ classpath/java/net/SocketException.java \
classpath/java/net/SocketImpl.java \ classpath/java/net/SocketImpl.java \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment