+2003-09-10 Michael Koch <konqueror@gmx.de>
+
+ * java/net/DatagramSocket.java,
+ java/net/MulticastSocket.java,
+ java/net/ServerSocket.java,
+ java/net/Socket.java:
+ Use gnu.java.net.Plain*SocketImpl instead of
+ java.net.PlainSocketImpl.
+ * java/net/PlainDatagramSocketImpl.java,
+ java/net/PlainSocketImpl.java,
+ java/net/SocketInputStream.java,
+ java/net/SocketOutputStream.java,
+ java/net/natPlainDatagramSocketImplNoNet.cc,
+ java/net/natPlainDatagramSocketImplPosix.cc,
+ java/net/natPlainDatagramSocketImplWin32.cc,
+ java/net/natPlainSocketImplNoNet.cc,
+ java/net/natPlainSocketImplPosix.cc,
+ java/net/natPlainSocketImplWin32.cc:
+ Removed.
+ * gnu/java/net/PlainDatagramSocketImpl.java,
+ gnu/java/net/PlainSocketImpl.java,
+ gnu/java/net/SocketInputStream.java,
+ gnu/java/net/SocketOutputStream.java,
+ gnu/java/net/natPlainDatagramSocketImplNoNet.cc,
+ gnu/java/net/natPlainDatagramSocketImplPosix.cc,
+ gnu/java/net/natPlainDatagramSocketImplWin32.cc,
+ gnu/java/net/natPlainSocketImplNoNet.cc,
+ gnu/java/net/natPlainSocketImplPosix.cc,
+ gnu/java/net/natPlainSocketImplWin32.cc:
+ New files (moved from java/net).
+ * configure.in: Create links for gnu/java/net/natPlain*SocketImpl.cc
+ instead of java/net/natPlain*SocketImpl.cc.
+ * configure: Regenerated.
+ * Makefile.am: Moved files from java/net to gnu/java/net.
+ * Makefile.in: Regenerated.
+
2003-09-09 Alan Modra <amodra@bigpond.net.au>
* configure: Regenerate.
gnu/java/locale/LocaleInformation_zh_SG.java \
gnu/java/locale/LocaleInformation_zh_TW.java \
gnu/java/math/MPN.java \
+gnu/java/net/PlainDatagramSocketImpl.java \
+gnu/java/net/PlainSocketImpl.java \
gnu/java/nio/DatagramChannelImpl.java \
gnu/java/nio/FileLockImpl.java \
gnu/java/nio/PipeImpl.java \
java/net/NetworkInterface.java \
java/net/NoRouteToHostException.java \
java/net/PasswordAuthentication.java \
-java/net/PlainDatagramSocketImpl.java \
-java/net/PlainSocketImpl.java \
java/net/PortUnreachableException.java \
java/net/ProtocolException.java \
java/net/ServerSocket.java \
gnu/gcj/runtime/natStringBuffer.cc \
gnu/gcj/runtime/natVMClassLoader.cc \
gnu/java/awt/natEmbeddedWindow.cc \
+gnu/java/net/natPlainDatagramSocketImpl.cc \
+gnu/java/net/natPlainSocketImpl.cc \
gnu/java/nio/natFileLockImpl.cc \
gnu/java/nio/natSelectorImpl.cc \
java/io/natFile.cc \
java/lang/reflect/natProxy.cc \
java/net/natNetworkInterface.cc \
java/net/natInetAddress.cc \
-java/net/natPlainDatagramSocketImpl.cc \
-java/net/natPlainSocketImpl.cc \
java/nio/natDirectByteBufferImpl.cc \
java/nio/channels/natFileChannelImpl.cc \
java/text/natCollator.cc \
gnu/java/locale/LocaleInformation_zh_SG.java \
gnu/java/locale/LocaleInformation_zh_TW.java \
gnu/java/math/MPN.java \
+gnu/java/net/PlainDatagramSocketImpl.java \
+gnu/java/net/PlainSocketImpl.java \
gnu/java/nio/DatagramChannelImpl.java \
gnu/java/nio/FileLockImpl.java \
gnu/java/nio/PipeImpl.java \
java/net/NetworkInterface.java \
java/net/NoRouteToHostException.java \
java/net/PasswordAuthentication.java \
-java/net/PlainDatagramSocketImpl.java \
-java/net/PlainSocketImpl.java \
java/net/PortUnreachableException.java \
java/net/ProtocolException.java \
java/net/ServerSocket.java \
gnu/gcj/runtime/natStringBuffer.cc \
gnu/gcj/runtime/natVMClassLoader.cc \
gnu/java/awt/natEmbeddedWindow.cc \
+gnu/java/net/natPlainDatagramSocketImpl.cc \
+gnu/java/net/natPlainSocketImpl.cc \
gnu/java/nio/natFileLockImpl.cc \
gnu/java/nio/natSelectorImpl.cc \
java/io/natFile.cc \
java/lang/reflect/natProxy.cc \
java/net/natNetworkInterface.cc \
java/net/natInetAddress.cc \
-java/net/natPlainDatagramSocketImpl.cc \
-java/net/natPlainSocketImpl.cc \
java/nio/natDirectByteBufferImpl.cc \
java/nio/channels/natFileChannelImpl.cc \
java/text/natCollator.cc \
gnu/gcj/runtime/natNameFinder.lo gnu/gcj/runtime/natSharedLibLoader.lo \
gnu/gcj/runtime/natStackTrace.lo gnu/gcj/runtime/natStringBuffer.lo \
gnu/gcj/runtime/natVMClassLoader.lo gnu/java/awt/natEmbeddedWindow.lo \
-gnu/java/nio/natFileLockImpl.lo gnu/java/nio/natSelectorImpl.lo \
-java/io/natFile.lo java/io/natFileDescriptor.lo \
-java/io/natObjectInputStream.lo java/io/natVMObjectStreamClass.lo \
-java/lang/natCharacter.lo java/lang/natClass.lo \
-java/lang/natClassLoader.lo java/lang/natConcreteProcess.lo \
-java/lang/natDouble.lo java/lang/natFloat.lo java/lang/natMath.lo \
-java/lang/natObject.lo java/lang/natRuntime.lo java/lang/natString.lo \
+gnu/java/net/natPlainDatagramSocketImpl.lo \
+gnu/java/net/natPlainSocketImpl.lo gnu/java/nio/natFileLockImpl.lo \
+gnu/java/nio/natSelectorImpl.lo java/io/natFile.lo \
+java/io/natFileDescriptor.lo java/io/natObjectInputStream.lo \
+java/io/natVMObjectStreamClass.lo java/lang/natCharacter.lo \
+java/lang/natClass.lo java/lang/natClassLoader.lo \
+java/lang/natConcreteProcess.lo java/lang/natDouble.lo \
+java/lang/natFloat.lo java/lang/natMath.lo java/lang/natObject.lo \
+java/lang/natRuntime.lo java/lang/natString.lo \
java/lang/natStringBuffer.lo java/lang/natSystem.lo \
java/lang/natThread.lo java/lang/natVMSecurityManager.lo \
java/lang/ref/natReference.lo java/lang/reflect/natArray.lo \
java/lang/reflect/natConstructor.lo java/lang/reflect/natField.lo \
java/lang/reflect/natMethod.lo java/lang/reflect/natProxy.lo \
java/net/natNetworkInterface.lo java/net/natInetAddress.lo \
-java/net/natPlainDatagramSocketImpl.lo java/net/natPlainSocketImpl.lo \
java/nio/natDirectByteBufferImpl.lo \
java/nio/channels/natFileChannelImpl.lo java/text/natCollator.lo \
java/util/natResourceBundle.lo java/util/natTimeZone.lo \
.deps/gnu/java/locale/LocaleInformation_zh_HK.P \
.deps/gnu/java/locale/LocaleInformation_zh_SG.P \
.deps/gnu/java/locale/LocaleInformation_zh_TW.P \
-.deps/gnu/java/math/MPN.P .deps/gnu/java/nio/DatagramChannelImpl.P \
+.deps/gnu/java/math/MPN.P .deps/gnu/java/net/PlainDatagramSocketImpl.P \
+.deps/gnu/java/net/PlainSocketImpl.P \
+.deps/gnu/java/net/natPlainDatagramSocketImpl.P \
+.deps/gnu/java/net/natPlainSocketImpl.P \
+.deps/gnu/java/nio/DatagramChannelImpl.P \
.deps/gnu/java/nio/FileLockImpl.P .deps/gnu/java/nio/PipeImpl.P \
.deps/gnu/java/nio/SelectionKeyImpl.P .deps/gnu/java/nio/SelectorImpl.P \
.deps/gnu/java/nio/SelectorProviderImpl.P \
.deps/java/net/NetPermission.P .deps/java/net/NetworkInterface.P \
.deps/java/net/NoRouteToHostException.P \
.deps/java/net/PasswordAuthentication.P \
-.deps/java/net/PlainDatagramSocketImpl.P \
-.deps/java/net/PlainSocketImpl.P \
.deps/java/net/PortUnreachableException.P \
.deps/java/net/ProtocolException.P .deps/java/net/ServerSocket.P \
.deps/java/net/Socket.P .deps/java/net/SocketAddress.P \
.deps/java/net/UnknownHostException.P \
.deps/java/net/UnknownServiceException.P \
.deps/java/net/natInetAddress.P .deps/java/net/natNetworkInterface.P \
-.deps/java/net/natPlainDatagramSocketImpl.P \
-.deps/java/net/natPlainSocketImpl.P .deps/java/nio/Buffer.P \
-.deps/java/nio/BufferOverflowException.P \
+.deps/java/nio/Buffer.P .deps/java/nio/BufferOverflowException.P \
.deps/java/nio/BufferUnderflowException.P .deps/java/nio/ByteBuffer.P \
.deps/java/nio/ByteBufferImpl.P .deps/java/nio/ByteOrder.P \
.deps/java/nio/CharBuffer.P .deps/java/nio/CharBufferImpl.P \
if { (eval echo configure:1632: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
for file in conftest.*; do
case $file in
- *.c | *.o | *.obj) ;;
+ *.$ac_ext | *.c | *.o | *.obj) ;;
*) ac_cv_exeext=`echo $file | sed -e s/conftest//` ;;
esac
done
+test -d gnu/java || mkdir gnu/java
+test -d gnu/java/net || mkdir gnu/java/net
+
case "${host}" in
# Uses ac_ vars as temps to allow command line to override cache and checks.
# --without-x overrides everything else, but does not touch the cache.
echo $ac_n "checking for X""... $ac_c" 1>&6
-echo "configure:3217: checking for X" >&5
+echo "configure:3220: checking for X" >&5
# Check whether --with-x or --without-x was given.
if test "${with_x+set}" = set; then
# First, try using that file with no special directory specified.
cat > conftest.$ac_ext <<EOF
-#line 3279 "configure"
+#line 3282 "configure"
#include "confdefs.h"
#include <$x_direct_test_include>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:3284: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:3287: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
ac_save_LIBS="$LIBS"
LIBS="-l$x_direct_test_library $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3353 "configure"
+#line 3356 "configure"
#include "confdefs.h"
int main() {
${x_direct_test_function}()
; return 0; }
EOF
-if { (eval echo configure:3360: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3363: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
LIBS="$ac_save_LIBS"
# We can link X programs with no special library path.
case "`(uname -sr) 2>/dev/null`" in
"SunOS 5"*)
echo $ac_n "checking whether -R must be followed by a space""... $ac_c" 1>&6
-echo "configure:3466: checking whether -R must be followed by a space" >&5
+echo "configure:3469: checking whether -R must be followed by a space" >&5
ac_xsave_LIBS="$LIBS"; LIBS="$LIBS -R$x_libraries"
cat > conftest.$ac_ext <<EOF
-#line 3469 "configure"
+#line 3472 "configure"
#include "confdefs.h"
int main() {
; return 0; }
EOF
-if { (eval echo configure:3476: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3479: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
ac_R_nospace=yes
else
else
LIBS="$ac_xsave_LIBS -R $x_libraries"
cat > conftest.$ac_ext <<EOF
-#line 3492 "configure"
+#line 3495 "configure"
#include "confdefs.h"
int main() {
; return 0; }
EOF
-if { (eval echo configure:3499: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3502: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
ac_R_space=yes
else
# libraries were built with DECnet support. And karl@cs.umb.edu says
# the Alpha needs dnet_stub (dnet does not exist).
echo $ac_n "checking for dnet_ntoa in -ldnet""... $ac_c" 1>&6
-echo "configure:3531: checking for dnet_ntoa in -ldnet" >&5
+echo "configure:3534: checking for dnet_ntoa in -ldnet" >&5
ac_lib_var=`echo dnet'_'dnet_ntoa | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-ldnet $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3539 "configure"
+#line 3542 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
dnet_ntoa()
; return 0; }
EOF
-if { (eval echo configure:3550: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3553: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
if test $ac_cv_lib_dnet_dnet_ntoa = no; then
echo $ac_n "checking for dnet_ntoa in -ldnet_stub""... $ac_c" 1>&6
-echo "configure:3572: checking for dnet_ntoa in -ldnet_stub" >&5
+echo "configure:3575: checking for dnet_ntoa in -ldnet_stub" >&5
ac_lib_var=`echo dnet_stub'_'dnet_ntoa | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-ldnet_stub $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3580 "configure"
+#line 3583 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
dnet_ntoa()
; return 0; }
EOF
-if { (eval echo configure:3591: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3594: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# The nsl library prevents programs from opening the X display
# on Irix 5.2, according to dickey@clark.net.
echo $ac_n "checking for gethostbyname""... $ac_c" 1>&6
-echo "configure:3620: checking for gethostbyname" >&5
+echo "configure:3623: checking for gethostbyname" >&5
if eval "test \"`echo '$''{'ac_cv_func_gethostbyname'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3625 "configure"
+#line 3628 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char gethostbyname(); below. */
; return 0; }
EOF
-if { (eval echo configure:3648: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3651: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_gethostbyname=yes"
else
if test $ac_cv_func_gethostbyname = no; then
echo $ac_n "checking for gethostbyname in -lnsl""... $ac_c" 1>&6
-echo "configure:3669: checking for gethostbyname in -lnsl" >&5
+echo "configure:3672: checking for gethostbyname in -lnsl" >&5
ac_lib_var=`echo nsl'_'gethostbyname | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lnsl $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3677 "configure"
+#line 3680 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
gethostbyname()
; return 0; }
EOF
-if { (eval echo configure:3688: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3691: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# -lsocket must be given before -lnsl if both are needed.
# We assume that if connect needs -lnsl, so does gethostbyname.
echo $ac_n "checking for connect""... $ac_c" 1>&6
-echo "configure:3718: checking for connect" >&5
+echo "configure:3721: checking for connect" >&5
if eval "test \"`echo '$''{'ac_cv_func_connect'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3723 "configure"
+#line 3726 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char connect(); below. */
; return 0; }
EOF
-if { (eval echo configure:3746: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3749: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_connect=yes"
else
if test $ac_cv_func_connect = no; then
echo $ac_n "checking for connect in -lsocket""... $ac_c" 1>&6
-echo "configure:3767: checking for connect in -lsocket" >&5
+echo "configure:3770: checking for connect in -lsocket" >&5
ac_lib_var=`echo socket'_'connect | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lsocket $X_EXTRA_LIBS $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3775 "configure"
+#line 3778 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
connect()
; return 0; }
EOF
-if { (eval echo configure:3786: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3789: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# gomez@mi.uni-erlangen.de says -lposix is necessary on A/UX.
echo $ac_n "checking for remove""... $ac_c" 1>&6
-echo "configure:3810: checking for remove" >&5
+echo "configure:3813: checking for remove" >&5
if eval "test \"`echo '$''{'ac_cv_func_remove'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3815 "configure"
+#line 3818 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char remove(); below. */
; return 0; }
EOF
-if { (eval echo configure:3838: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3841: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_remove=yes"
else
if test $ac_cv_func_remove = no; then
echo $ac_n "checking for remove in -lposix""... $ac_c" 1>&6
-echo "configure:3859: checking for remove in -lposix" >&5
+echo "configure:3862: checking for remove in -lposix" >&5
ac_lib_var=`echo posix'_'remove | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lposix $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3867 "configure"
+#line 3870 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
remove()
; return 0; }
EOF
-if { (eval echo configure:3878: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3881: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay.
echo $ac_n "checking for shmat""... $ac_c" 1>&6
-echo "configure:3902: checking for shmat" >&5
+echo "configure:3905: checking for shmat" >&5
if eval "test \"`echo '$''{'ac_cv_func_shmat'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3907 "configure"
+#line 3910 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char shmat(); below. */
; return 0; }
EOF
-if { (eval echo configure:3930: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3933: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_shmat=yes"
else
if test $ac_cv_func_shmat = no; then
echo $ac_n "checking for shmat in -lipc""... $ac_c" 1>&6
-echo "configure:3951: checking for shmat in -lipc" >&5
+echo "configure:3954: checking for shmat in -lipc" >&5
ac_lib_var=`echo ipc'_'shmat | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lipc $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3959 "configure"
+#line 3962 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
shmat()
; return 0; }
EOF
-if { (eval echo configure:3970: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3973: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# libraries we check for below, so use a different variable.
# --interran@uluru.Stanford.EDU, kb@cs.umb.edu.
echo $ac_n "checking for IceConnectionNumber in -lICE""... $ac_c" 1>&6
-echo "configure:4003: checking for IceConnectionNumber in -lICE" >&5
+echo "configure:4006: checking for IceConnectionNumber in -lICE" >&5
ac_lib_var=`echo ICE'_'IceConnectionNumber | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lICE $X_EXTRA_LIBS $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 4011 "configure"
+#line 4014 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
IceConnectionNumber()
; return 0; }
EOF
-if { (eval echo configure:4022: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4025: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
libsubdir=.libs
echo $ac_n "checking for garbage collector to use""... $ac_c" 1>&6
-echo "configure:4120: checking for garbage collector to use" >&5
+echo "configure:4123: checking for garbage collector to use" >&5
# Check whether --enable-java-gc or --disable-java-gc was given.
if test "${enable_java_gc+set}" = set; then
enableval="$enable_java_gc"
echo $ac_n "checking for thread model used by GCC""... $ac_c" 1>&6
-echo "configure:4172: checking for thread model used by GCC" >&5
+echo "configure:4175: checking for thread model used by GCC" >&5
THREADS=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
echo "$ac_t""$THREADS" 1>&6
for ac_func in strerror ioctl select fstat open fsync sleep opendir
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4379: checking for $ac_func" >&5
+echo "configure:4382: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4384 "configure"
+#line 4387 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:4407: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4410: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in gmtime_r localtime_r readdir_r getpwuid_r getcwd
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4434: checking for $ac_func" >&5
+echo "configure:4437: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4439 "configure"
+#line 4442 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:4462: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4465: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in access stat mkdir rename rmdir unlink realpath utime chmod
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4489: checking for $ac_func" >&5
+echo "configure:4492: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4494 "configure"
+#line 4497 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:4517: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4520: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in nl_langinfo setlocale
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4544: checking for $ac_func" >&5
+echo "configure:4547: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4549 "configure"
+#line 4552 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:4572: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4575: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in inet_aton inet_addr
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4599: checking for $ac_func" >&5
+echo "configure:4602: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4604 "configure"
+#line 4607 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:4627: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4630: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in inet_pton uname inet_ntoa
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4654: checking for $ac_func" >&5
+echo "configure:4657: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4659 "configure"
+#line 4662 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:4682: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4685: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in fork execvp pipe sigaction ftruncate
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4709: checking for $ac_func" >&5
+echo "configure:4712: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4714 "configure"
+#line 4717 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:4737: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4740: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:4765: checking for $ac_hdr" >&5
+echo "configure:4768: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4770 "configure"
+#line 4773 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4775: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4778: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
done
echo $ac_n "checking for backtrace""... $ac_c" 1>&6
-echo "configure:4802: checking for backtrace" >&5
+echo "configure:4805: checking for backtrace" >&5
if eval "test \"`echo '$''{'ac_cv_func_backtrace'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4807 "configure"
+#line 4810 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char backtrace(); below. */
; return 0; }
EOF
-if { (eval echo configure:4830: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4833: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_backtrace=yes"
else
echo $ac_n "checking for dladdr in -ldl""... $ac_c" 1>&6
-echo "configure:4874: checking for dladdr in -ldl" >&5
+echo "configure:4877: checking for dladdr in -ldl" >&5
ac_lib_var=`echo dl'_'dladdr | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-ldl $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 4882 "configure"
+#line 4885 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
dladdr()
; return 0; }
EOF
-if { (eval echo configure:4893: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4896: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
ac_safe=`echo "$ac_file" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_file""... $ac_c" 1>&6
-echo "configure:4923: checking for $ac_file" >&5
+echo "configure:4926: checking for $ac_file" >&5
if eval "test \"`echo '$''{'ac_cv_file_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
echo $ac_n "checking for iconv""... $ac_c" 1>&6
-echo "configure:4981: checking for iconv" >&5
+echo "configure:4984: checking for iconv" >&5
if eval "test \"`echo '$''{'am_cv_func_iconv'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
am_cv_func_iconv="no, consider installing GNU libiconv"
am_cv_lib_iconv=no
cat > conftest.$ac_ext <<EOF
-#line 4989 "configure"
+#line 4992 "configure"
#include "confdefs.h"
#include <stdlib.h>
#include <iconv.h>
iconv_close(cd);
; return 0; }
EOF
-if { (eval echo configure:4999: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5002: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
am_cv_func_iconv=yes
else
am_save_LIBS="$LIBS"
LIBS="$LIBS $am_cv_libiconv_ldpath -liconv"
cat > conftest.$ac_ext <<EOF
-#line 5011 "configure"
+#line 5014 "configure"
#include "confdefs.h"
#include <stdlib.h>
#include <iconv.h>
iconv_close(cd);
; return 0; }
EOF
-if { (eval echo configure:5021: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5024: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
am_cv_lib_iconv=yes
am_cv_func_iconv=yes
EOF
echo $ac_n "checking for iconv declaration""... $ac_c" 1>&6
-echo "configure:5042: checking for iconv declaration" >&5
+echo "configure:5045: checking for iconv declaration" >&5
if eval "test \"`echo '$''{'am_cv_proto_iconv'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5048 "configure"
+#line 5051 "configure"
#include "confdefs.h"
#include <stdlib.h>
; return 0; }
EOF
-if { (eval echo configure:5067: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5070: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
am_cv_proto_iconv_arg1=""
else
if test $ac_cv_header_locale_h = yes; then
echo $ac_n "checking for LC_MESSAGES""... $ac_c" 1>&6
-echo "configure:5096: checking for LC_MESSAGES" >&5
+echo "configure:5099: checking for LC_MESSAGES" >&5
if eval "test \"`echo '$''{'am_cv_val_LC_MESSAGES'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5101 "configure"
+#line 5104 "configure"
#include "confdefs.h"
#include <locale.h>
int main() {
return LC_MESSAGES
; return 0; }
EOF
-if { (eval echo configure:5108: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5111: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
am_cv_val_LC_MESSAGES=yes
else
fi
fi
echo $ac_n "checking whether struct tm is in sys/time.h or time.h""... $ac_c" 1>&6
-echo "configure:5129: checking whether struct tm is in sys/time.h or time.h" >&5
+echo "configure:5132: checking whether struct tm is in sys/time.h or time.h" >&5
if eval "test \"`echo '$''{'ac_cv_struct_tm'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5134 "configure"
+#line 5137 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <time.h>
struct tm *tp; tp->tm_sec;
; return 0; }
EOF
-if { (eval echo configure:5142: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5145: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_struct_tm=time.h
else
fi
echo $ac_n "checking for tm_zone in struct tm""... $ac_c" 1>&6
-echo "configure:5163: checking for tm_zone in struct tm" >&5
+echo "configure:5166: checking for tm_zone in struct tm" >&5
if eval "test \"`echo '$''{'ac_cv_struct_tm_zone'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5168 "configure"
+#line 5171 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <$ac_cv_struct_tm>
struct tm tm; tm.tm_zone;
; return 0; }
EOF
-if { (eval echo configure:5176: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5179: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_struct_tm_zone=yes
else
else
echo $ac_n "checking for tzname""... $ac_c" 1>&6
-echo "configure:5196: checking for tzname" >&5
+echo "configure:5199: checking for tzname" >&5
if eval "test \"`echo '$''{'ac_cv_var_tzname'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5201 "configure"
+#line 5204 "configure"
#include "confdefs.h"
#include <time.h>
#ifndef tzname /* For SGI. */
atoi(*tzname);
; return 0; }
EOF
-if { (eval echo configure:5211: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5214: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
ac_cv_var_tzname=yes
else
for ac_func in gethostbyname_r
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5236: checking for $ac_func" >&5
+echo "configure:5239: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5241 "configure"
+#line 5244 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:5264: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5267: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
# We look for the one that returns `int'.
# Hopefully this check is robust enough.
cat > conftest.$ac_ext <<EOF
-#line 5291 "configure"
+#line 5294 "configure"
#include "confdefs.h"
#include <netdb.h>
EOF
*" -D_REENTRANT "*) ;;
*)
echo $ac_n "checking whether gethostbyname_r declaration requires -D_REENTRANT""... $ac_c" 1>&6
-echo "configure:5311: checking whether gethostbyname_r declaration requires -D_REENTRANT" >&5
+echo "configure:5314: checking whether gethostbyname_r declaration requires -D_REENTRANT" >&5
if eval "test \"`echo '$''{'libjava_cv_gethostbyname_r_needs_reentrant'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cross_compiling=$ac_cv_prog_cxx_cross
cat > conftest.$ac_ext <<EOF
-#line 5324 "configure"
+#line 5327 "configure"
#include "confdefs.h"
#include <netdb.h>
int main() {
gethostbyname_r("", 0, 0);
; return 0; }
EOF
-if { (eval echo configure:5331: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5334: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
libjava_cv_gethostbyname_r_needs_reentrant=no
else
CPPFLAGS_SAVE="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -D_REENTRANT"
cat > conftest.$ac_ext <<EOF
-#line 5341 "configure"
+#line 5344 "configure"
#include "confdefs.h"
#include <netdb.h>
int main() {
gethostbyname_r("", 0, 0);
; return 0; }
EOF
-if { (eval echo configure:5348: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5351: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
libjava_cv_gethostbyname_r_needs_reentrant=yes
else
esac
echo $ac_n "checking for struct hostent_data""... $ac_c" 1>&6
-echo "configure:5383: checking for struct hostent_data" >&5
+echo "configure:5386: checking for struct hostent_data" >&5
if eval "test \"`echo '$''{'libjava_cv_struct_hostent_data'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5388 "configure"
+#line 5391 "configure"
#include "confdefs.h"
#if GETHOSTBYNAME_R_NEEDS_REENTRANT && !defined(_REENTRANT)
struct hostent_data data;
; return 0; }
EOF
-if { (eval echo configure:5399: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5402: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
libjava_cv_struct_hostent_data=yes
else
# to exist where expected. (The root issue: AC_CHECK_FUNCS assumes C
# linkage check is enough, yet C++ code requires proper prototypes.)
cat > conftest.$ac_ext <<EOF
-#line 5431 "configure"
+#line 5434 "configure"
#include "confdefs.h"
#include <netdb.h>
EOF
for ac_func in gethostbyaddr_r
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5442: checking for $ac_func" >&5
+echo "configure:5445: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5447 "configure"
+#line 5450 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:5470: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5473: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
# We look for the one that returns `int'.
# Hopefully this check is robust enough.
cat > conftest.$ac_ext <<EOF
-#line 5497 "configure"
+#line 5500 "configure"
#include "confdefs.h"
#include <netdb.h>
EOF
for ac_func in gethostname
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5524: checking for $ac_func" >&5
+echo "configure:5527: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5529 "configure"
+#line 5532 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:5552: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5555: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
EOF
cat > conftest.$ac_ext <<EOF
-#line 5576 "configure"
+#line 5579 "configure"
#include "confdefs.h"
#include <unistd.h>
EOF
for ac_func in usleep
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5600: checking for $ac_func" >&5
+echo "configure:5603: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5605 "configure"
+#line 5608 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:5628: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5631: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
EOF
cat > conftest.$ac_ext <<EOF
-#line 5648 "configure"
+#line 5651 "configure"
#include "confdefs.h"
#include <unistd.h>
EOF
for ac_func in pthread_mutexattr_settype pthread_mutexattr_setkind_np
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5679: checking for $ac_func" >&5
+echo "configure:5682: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5684 "configure"
+#line 5687 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:5707: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5710: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in sched_yield
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5737: checking for $ac_func" >&5
+echo "configure:5740: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5742 "configure"
+#line 5745 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:5765: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5768: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
else
echo "$ac_t""no" 1>&6
echo $ac_n "checking for sched_yield in -lrt""... $ac_c" 1>&6
-echo "configure:5787: checking for sched_yield in -lrt" >&5
+echo "configure:5790: checking for sched_yield in -lrt" >&5
ac_lib_var=`echo rt'_'sched_yield | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lrt $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 5795 "configure"
+#line 5798 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
sched_yield()
; return 0; }
EOF
-if { (eval echo configure:5806: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5809: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
echo "$ac_t""no" 1>&6
echo $ac_n "checking for sched_yield in -lposix4""... $ac_c" 1>&6
-echo "configure:5832: checking for sched_yield in -lposix4" >&5
+echo "configure:5835: checking for sched_yield in -lposix4" >&5
ac_lib_var=`echo posix4'_'sched_yield | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lposix4 $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 5840 "configure"
+#line 5843 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
sched_yield()
; return 0; }
EOF
-if { (eval echo configure:5851: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5854: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# We can save a little space at runtime if the mutex has m_count
# or __m_count. This is a nice hack for Linux.
cat > conftest.$ac_ext <<EOF
-#line 5887 "configure"
+#line 5890 "configure"
#include "confdefs.h"
#include <pthread.h>
int main() {
; return 0; }
EOF
-if { (eval echo configure:5896: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5899: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define PTHREAD_MUTEX_HAVE_M_COUNT 1
rm -rf conftest*
cat > conftest.$ac_ext <<EOF
-#line 5908 "configure"
+#line 5911 "configure"
#include "confdefs.h"
#include <pthread.h>
int main() {
; return 0; }
EOF
-if { (eval echo configure:5917: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5920: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define PTHREAD_MUTEX_HAVE___M_COUNT 1
for ac_func in gettimeofday time ftime
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5937: checking for $ac_func" >&5
+echo "configure:5940: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5942 "configure"
+#line 5945 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:5965: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5968: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in memmove
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5996: checking for $ac_func" >&5
+echo "configure:5999: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6001 "configure"
+#line 6004 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:6024: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6027: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in memcpy
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:6054: checking for $ac_func" >&5
+echo "configure:6057: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6059 "configure"
+#line 6062 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:6082: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6085: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
fi
echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:6111: checking for dlopen in -ldl" >&5
+echo "configure:6114: checking for dlopen in -ldl" >&5
ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-ldl $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 6119 "configure"
+#line 6122 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
dlopen()
; return 0; }
EOF
-if { (eval echo configure:6130: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6133: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
#--------------------------------------------------------------------
echo $ac_n "checking for socket libraries""... $ac_c" 1>&6
-echo "configure:6175: checking for socket libraries" >&5
+echo "configure:6178: checking for socket libraries" >&5
if eval "test \"`echo '$''{'gcj_cv_lib_sockets'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
gcj_checkBoth=0
unset ac_cv_func_connect
echo $ac_n "checking for connect""... $ac_c" 1>&6
-echo "configure:6183: checking for connect" >&5
+echo "configure:6186: checking for connect" >&5
if eval "test \"`echo '$''{'ac_cv_func_connect'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6188 "configure"
+#line 6191 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char connect(); below. */
; return 0; }
EOF
-if { (eval echo configure:6211: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6214: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_connect=yes"
else
if test "$gcj_checkSocket" = 1; then
unset ac_cv_func_connect
echo $ac_n "checking for main in -lsocket""... $ac_c" 1>&6
-echo "configure:6234: checking for main in -lsocket" >&5
+echo "configure:6237: checking for main in -lsocket" >&5
ac_lib_var=`echo socket'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lsocket $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 6242 "configure"
+#line 6245 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:6249: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6252: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
LIBS="$LIBS -lsocket -lnsl"
unset ac_cv_func_accept
echo $ac_n "checking for accept""... $ac_c" 1>&6
-echo "configure:6276: checking for accept" >&5
+echo "configure:6279: checking for accept" >&5
if eval "test \"`echo '$''{'ac_cv_func_accept'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6281 "configure"
+#line 6284 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char accept(); below. */
; return 0; }
EOF
-if { (eval echo configure:6304: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6307: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_accept=yes"
else
gcj_oldLibs=$LIBS
LIBS="$LIBS $gcj_cv_lib_sockets"
echo $ac_n "checking for gethostbyname""... $ac_c" 1>&6
-echo "configure:6331: checking for gethostbyname" >&5
+echo "configure:6334: checking for gethostbyname" >&5
if eval "test \"`echo '$''{'ac_cv_func_gethostbyname'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6336 "configure"
+#line 6339 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char gethostbyname(); below. */
; return 0; }
EOF
-if { (eval echo configure:6359: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6362: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_gethostbyname=yes"
else
else
echo "$ac_t""no" 1>&6
echo $ac_n "checking for main in -lnsl""... $ac_c" 1>&6
-echo "configure:6377: checking for main in -lnsl" >&5
+echo "configure:6380: checking for main in -lnsl" >&5
ac_lib_var=`echo nsl'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lnsl $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 6385 "configure"
+#line 6388 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:6392: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6395: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
if test "$with_system_zlib" = yes; then
echo $ac_n "checking for deflate in -lz""... $ac_c" 1>&6
-echo "configure:6424: checking for deflate in -lz" >&5
+echo "configure:6427: checking for deflate in -lz" >&5
ac_lib_var=`echo z'_'deflate | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lz $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 6432 "configure"
+#line 6435 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
deflate()
; return 0; }
EOF
-if { (eval echo configure:6443: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6446: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# Extract the first word of "pkg-config", so it can be a program name with args.
set dummy pkg-config; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:6492: checking for $ac_word" >&5
+echo "configure:6495: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_PKG_CONFIG'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
min_gtk_version=2.0.0
echo $ac_n "checking for GTK+ - version >= $min_gtk_version""... $ac_c" 1>&6
-echo "configure:6540: checking for GTK+ - version >= $min_gtk_version" >&5
+echo "configure:6543: checking for GTK+ - version >= $min_gtk_version" >&5
if test x$PKG_CONFIG != xno ; then
## don't try to run the test against uninstalled libtool libs
echo $ac_n "cross compiling; assumed OK... $ac_c"
else
cat > conftest.$ac_ext <<EOF
-#line 6575 "configure"
+#line 6578 "configure"
#include "confdefs.h"
#include <gtk/gtk.h>
}
EOF
-if { (eval echo configure:6650: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:6653: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
:
else
CFLAGS="$CFLAGS $GTK_CFLAGS"
LIBS="$LIBS $GTK_LIBS"
cat > conftest.$ac_ext <<EOF
-#line 6684 "configure"
+#line 6687 "configure"
#include "confdefs.h"
#include <gtk/gtk.h>
return ((gtk_major_version) || (gtk_minor_version) || (gtk_micro_version));
; return 0; }
EOF
-if { (eval echo configure:6694: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6697: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding GTK+ or finding the wrong"
# Extract the first word of "pkg-config", so it can be a program name with args.
set dummy pkg-config; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:6753: checking for $ac_word" >&5
+echo "configure:6756: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_PKG_CONFIG'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
min_glib_version=2.0.0
echo $ac_n "checking for GLIB - version >= $min_glib_version""... $ac_c" 1>&6
-echo "configure:6803: checking for GLIB - version >= $min_glib_version" >&5
+echo "configure:6806: checking for GLIB - version >= $min_glib_version" >&5
if test x$PKG_CONFIG != xno ; then
## don't try to run the test against uninstalled libtool libs
echo $ac_n "cross compiling; assumed OK... $ac_c"
else
cat > conftest.$ac_ext <<EOF
-#line 6842 "configure"
+#line 6845 "configure"
#include "confdefs.h"
#include <glib.h>
}
EOF
-if { (eval echo configure:6917: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:6920: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
:
else
CFLAGS="$CFLAGS $GLIB_CFLAGS"
LIBS="$LIBS $GLIB_LIBS"
cat > conftest.$ac_ext <<EOF
-#line 6951 "configure"
+#line 6954 "configure"
#include "confdefs.h"
#include <glib.h>
return ((glib_major_version) || (glib_minor_version) || (glib_micro_version));
; return 0; }
EOF
-if { (eval echo configure:6961: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6964: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding GLIB or finding the wrong"
# Extract the first word of "libart2-config", so it can be a program name with args.
set dummy libart2-config; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:7040: checking for $ac_word" >&5
+echo "configure:7043: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_LIBART_CONFIG'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "libart-config", so it can be a program name with args.
set dummy libart-config; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:7077: checking for $ac_word" >&5
+echo "configure:7080: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_LIBART_CONFIG'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
fi
min_libart_version=2.1.0
echo $ac_n "checking for LIBART - version >= $min_libart_version""... $ac_c" 1>&6
-echo "configure:7113: checking for LIBART - version >= $min_libart_version" >&5
+echo "configure:7116: checking for LIBART - version >= $min_libart_version" >&5
no_libart=""
if test "$LIBART_CONFIG" = "no" ; then
no_libart=yes
echo $ac_n "cross compiling; assumed OK... $ac_c"
else
cat > conftest.$ac_ext <<EOF
-#line 7137 "configure"
+#line 7140 "configure"
#include "confdefs.h"
#include <stdio.h>
EOF
-if { (eval echo configure:7195: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:7198: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
:
else
CFLAGS="$CFLAGS $LIBART_CFLAGS"
LIBS="$LIBS $LIBART_LIBS"
cat > conftest.$ac_ext <<EOF
-#line 7229 "configure"
+#line 7232 "configure"
#include "confdefs.h"
#include <stdio.h>
return 0;
; return 0; }
EOF
-if { (eval echo configure:7239: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:7242: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding LIBART or finding the wrong"
# requires -ldl.
if test "$GC" = boehm; then
echo $ac_n "checking for main in -ldl""... $ac_c" 1>&6
-echo "configure:7278: checking for main in -ldl" >&5
+echo "configure:7281: checking for main in -ldl" >&5
ac_lib_var=`echo dl'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-ldl $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 7286 "configure"
+#line 7289 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:7293: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:7296: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# Extract the first word of "${ac_tool_prefix}gcj", so it can be a program name with args.
set dummy ${ac_tool_prefix}gcj; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:7414: checking for $ac_word" >&5
+echo "configure:7417: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_GCJ'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "gcj", so it can be a program name with args.
set dummy gcj; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:7446: checking for $ac_word" >&5
+echo "configure:7449: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_GCJ'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
CPPFLAGS=$GCJ_SAVE_CPPFLAGS
echo $ac_n "checking size of void *""... $ac_c" 1>&6
-echo "configure:7508: checking size of void *" >&5
+echo "configure:7511: checking size of void *" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_void_p'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
for ac_size in 4 8 1 2 16 12 ; do # List sizes in rough order of prevalence.
cat > conftest.$ac_ext <<EOF
-#line 7514 "configure"
+#line 7517 "configure"
#include "confdefs.h"
#include "confdefs.h"
#include <sys/types.h>
switch (0) case 0: case (sizeof (void *) == $ac_size):;
; return 0; }
EOF
-if { (eval echo configure:7524: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:7527: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_sizeof_void_p=$ac_size
else
echo $ac_n "checking for g++ -ffloat-store bug""... $ac_c" 1>&6
-echo "configure:7634: checking for g++ -ffloat-store bug" >&5
+echo "configure:7637: checking for g++ -ffloat-store bug" >&5
save_CFLAGS="$CFLAGS"
CFLAGS="-x c++ -O2 -ffloat-store"
cat > conftest.$ac_ext <<EOF
-#line 7638 "configure"
+#line 7641 "configure"
#include "confdefs.h"
#include <math.h>
int main() {
; return 0; }
EOF
-if { (eval echo configure:7645: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:7648: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
echo "$ac_t""no" 1>&6
else
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:7665: checking for $ac_hdr" >&5
+echo "configure:7668: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 7670 "configure"
+#line 7673 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:7675: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:7678: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:7705: checking for $ac_hdr" >&5
+echo "configure:7708: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 7710 "configure"
+#line 7713 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:7715: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:7718: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:7745: checking for $ac_hdr" >&5
+echo "configure:7748: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 7750 "configure"
+#line 7753 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:7755: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:7758: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
done
echo $ac_n "checking for sys/wait.h that is POSIX.1 compatible""... $ac_c" 1>&6
-echo "configure:7791: checking for sys/wait.h that is POSIX.1 compatible" >&5
+echo "configure:7794: checking for sys/wait.h that is POSIX.1 compatible" >&5
if eval "test \"`echo '$''{'ac_cv_header_sys_wait_h'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 7796 "configure"
+#line 7799 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <sys/wait.h>
s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;
; return 0; }
EOF
-if { (eval echo configure:7812: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:7815: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_header_sys_wait_h=yes
else
echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:7834: checking for ANSI C header files" >&5
+echo "configure:7837: checking for ANSI C header files" >&5
if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 7839 "configure"
+#line 7842 "configure"
#include "confdefs.h"
#include <stdlib.h>
#include <stdarg.h>
#include <float.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:7847: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:7850: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
if test $ac_cv_header_stdc = yes; then
# SunOS 4.x string.h does not declare mem*, contrary to ANSI.
cat > conftest.$ac_ext <<EOF
-#line 7864 "configure"
+#line 7867 "configure"
#include "confdefs.h"
#include <string.h>
EOF
if test $ac_cv_header_stdc = yes; then
# ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
cat > conftest.$ac_ext <<EOF
-#line 7882 "configure"
+#line 7885 "configure"
#include "confdefs.h"
#include <stdlib.h>
EOF
:
else
cat > conftest.$ac_ext <<EOF
-#line 7903 "configure"
+#line 7906 "configure"
#include "confdefs.h"
#include <ctype.h>
#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
exit (0); }
EOF
-if { (eval echo configure:7914: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:7917: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
:
else
fi
echo $ac_n "checking for ssize_t""... $ac_c" 1>&6
-echo "configure:7938: checking for ssize_t" >&5
+echo "configure:7941: checking for ssize_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_ssize_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 7943 "configure"
+#line 7946 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
echo $ac_n "checking for in_addr_t""... $ac_c" 1>&6
-echo "configure:7972: checking for in_addr_t" >&5
+echo "configure:7975: checking for in_addr_t" >&5
cat > conftest.$ac_ext <<EOF
-#line 7974 "configure"
+#line 7977 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
in_addr_t foo;
; return 0; }
EOF
-if { (eval echo configure:7988: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:7991: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define HAVE_IN_ADDR_T 1
rm -f conftest*
echo $ac_n "checking whether struct ip_mreq is in netinet/in.h""... $ac_c" 1>&6
-echo "configure:8004: checking whether struct ip_mreq is in netinet/in.h" >&5
+echo "configure:8007: checking whether struct ip_mreq is in netinet/in.h" >&5
cat > conftest.$ac_ext <<EOF
-#line 8006 "configure"
+#line 8009 "configure"
#include "confdefs.h"
#include <netinet/in.h>
int main() {
struct ip_mreq mreq;
; return 0; }
EOF
-if { (eval echo configure:8013: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:8016: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define HAVE_STRUCT_IP_MREQ 1
rm -f conftest*
echo $ac_n "checking whether struct ipv6_mreq is in netinet/in.h""... $ac_c" 1>&6
-echo "configure:8029: checking whether struct ipv6_mreq is in netinet/in.h" >&5
+echo "configure:8032: checking whether struct ipv6_mreq is in netinet/in.h" >&5
cat > conftest.$ac_ext <<EOF
-#line 8031 "configure"
+#line 8034 "configure"
#include "confdefs.h"
#include <netinet/in.h>
int main() {
struct ipv6_mreq mreq6;
; return 0; }
EOF
-if { (eval echo configure:8038: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:8041: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define HAVE_STRUCT_IPV6_MREQ 1
rm -f conftest*
echo $ac_n "checking whether struct sockaddr_in6 is in netinet/in.h""... $ac_c" 1>&6
-echo "configure:8054: checking whether struct sockaddr_in6 is in netinet/in.h" >&5
+echo "configure:8057: checking whether struct sockaddr_in6 is in netinet/in.h" >&5
cat > conftest.$ac_ext <<EOF
-#line 8056 "configure"
+#line 8059 "configure"
#include "confdefs.h"
#include <netinet/in.h>
int main() {
struct sockaddr_in6 addr6;
; return 0; }
EOF
-if { (eval echo configure:8063: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:8066: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define HAVE_INET6 1
rm -f conftest*
echo $ac_n "checking for socklen_t in sys/socket.h""... $ac_c" 1>&6
-echo "configure:8079: checking for socklen_t in sys/socket.h" >&5
+echo "configure:8082: checking for socklen_t in sys/socket.h" >&5
cat > conftest.$ac_ext <<EOF
-#line 8081 "configure"
+#line 8084 "configure"
#include "confdefs.h"
#define _POSIX_PII_SOCKET
#include <sys/types.h>
socklen_t x = 5;
; return 0; }
EOF
-if { (eval echo configure:8090: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:8093: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define HAVE_SOCKLEN_T 1
rm -f conftest*
echo $ac_n "checking for tm_gmtoff in struct tm""... $ac_c" 1>&6
-echo "configure:8106: checking for tm_gmtoff in struct tm" >&5
+echo "configure:8109: checking for tm_gmtoff in struct tm" >&5
cat > conftest.$ac_ext <<EOF
-#line 8108 "configure"
+#line 8111 "configure"
#include "confdefs.h"
#include <time.h>
int main() {
struct tm tim; tim.tm_gmtoff = 0;
; return 0; }
EOF
-if { (eval echo configure:8115: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:8118: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define STRUCT_TM_HAS_GMTOFF 1
rm -rf conftest*
echo "$ac_t""no" 1>&6
echo $ac_n "checking for global timezone variable""... $ac_c" 1>&6
-echo "configure:8128: checking for global timezone variable" >&5
+echo "configure:8131: checking for global timezone variable" >&5
cat > conftest.$ac_ext <<EOF
-#line 8130 "configure"
+#line 8133 "configure"
#include "confdefs.h"
#include <time.h>
int main() {
void i(){long z2 = 2*timezone;}
; return 0; }
EOF
-if { (eval echo configure:8137: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:8140: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define HAVE_TIMEZONE 1
rm -rf conftest*
echo "$ac_t""no" 1>&6
echo $ac_n "checking for global _timezone variable""... $ac_c" 1>&6
-echo "configure:8150: checking for global _timezone variable" >&5
+echo "configure:8153: checking for global _timezone variable" >&5
cat > conftest.$ac_ext <<EOF
-#line 8152 "configure"
+#line 8155 "configure"
#include "confdefs.h"
#include <time.h>
int main() {
long z2 = _timezone;
; return 0; }
EOF
-if { (eval echo configure:8159: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:8162: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
cat >> confdefs.h <<\EOF
#define HAVE_UNDERSCORE_TIMEZONE 1
# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
# for constant arguments. Useless!
echo $ac_n "checking for working alloca.h""... $ac_c" 1>&6
-echo "configure:8181: checking for working alloca.h" >&5
+echo "configure:8184: checking for working alloca.h" >&5
if eval "test \"`echo '$''{'ac_cv_header_alloca_h'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 8186 "configure"
+#line 8189 "configure"
#include "confdefs.h"
#include <alloca.h>
int main() {
char *p = alloca(2 * sizeof(int));
; return 0; }
EOF
-if { (eval echo configure:8193: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:8196: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
ac_cv_header_alloca_h=yes
else
fi
echo $ac_n "checking for alloca""... $ac_c" 1>&6
-echo "configure:8214: checking for alloca" >&5
+echo "configure:8217: checking for alloca" >&5
if eval "test \"`echo '$''{'ac_cv_func_alloca_works'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 8219 "configure"
+#line 8222 "configure"
#include "confdefs.h"
#ifdef __GNUC__
char *p = (char *) alloca(1);
; return 0; }
EOF
-if { (eval echo configure:8247: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:8250: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
ac_cv_func_alloca_works=yes
else
echo $ac_n "checking whether alloca needs Cray hooks""... $ac_c" 1>&6
-echo "configure:8279: checking whether alloca needs Cray hooks" >&5
+echo "configure:8282: checking whether alloca needs Cray hooks" >&5
if eval "test \"`echo '$''{'ac_cv_os_cray'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 8284 "configure"
+#line 8287 "configure"
#include "confdefs.h"
#if defined(CRAY) && ! defined(CRAY2)
webecray
if test $ac_cv_os_cray = yes; then
for ac_func in _getb67 GETB67 getb67; do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:8309: checking for $ac_func" >&5
+echo "configure:8312: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 8314 "configure"
+#line 8317 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:8337: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:8340: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
fi
echo $ac_n "checking stack direction for C alloca""... $ac_c" 1>&6
-echo "configure:8364: checking stack direction for C alloca" >&5
+echo "configure:8367: checking stack direction for C alloca" >&5
if eval "test \"`echo '$''{'ac_cv_c_stack_direction'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_cv_c_stack_direction=0
else
cat > conftest.$ac_ext <<EOF
-#line 8372 "configure"
+#line 8375 "configure"
#include "confdefs.h"
find_stack_direction ()
{
exit (find_stack_direction() < 0);
}
EOF
-if { (eval echo configure:8391: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:8394: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_c_stack_direction=1
else
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:8416: checking for $ac_hdr" >&5
+echo "configure:8419: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 8421 "configure"
+#line 8424 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:8426: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:8429: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
for ac_func in getpagesize
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:8455: checking for $ac_func" >&5
+echo "configure:8458: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 8460 "configure"
+#line 8463 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:8483: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:8486: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
done
echo $ac_n "checking for working mmap""... $ac_c" 1>&6
-echo "configure:8508: checking for working mmap" >&5
+echo "configure:8511: checking for working mmap" >&5
if eval "test \"`echo '$''{'ac_cv_func_mmap_fixed_mapped'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_cv_func_mmap_fixed_mapped=no
else
cat > conftest.$ac_ext <<EOF
-#line 8516 "configure"
+#line 8519 "configure"
#include "confdefs.h"
/* Thanks to Mike Haertel and Jim Avera for this test.
}
EOF
-if { (eval echo configure:8656: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:8659: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_func_mmap_fixed_mapped=yes
else
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:8684: checking for $ac_word" >&5
+echo "configure:8687: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_PERL'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
EOF
cat >> $CONFIG_STATUS <<EOF
-ac_sources="include/$PLATFORMH java/io/natFile${FILE-${PLATFORM}}.cc java/io/natFileDescriptor${FILE-${PLATFORM}}.cc java/lang/${PLATFORM}Process.java java/lang/nat${PLATFORM}Process.cc java/net/natInetAddress${PLATFORMNET}.cc java/net/natNetworkInterface${PLATFORMNET}.cc java/net/natPlainSocketImpl${PLATFORMNET}.cc java/net/natPlainDatagramSocketImpl${PLATFORMNET}.cc include/$GCHDR include/$THREADH sysdep/$sysdeps_dir/locks.h $SIGNAL_HANDLER"
-ac_dests="include/platform.h java/io/natFile.cc java/io/natFileDescriptor.cc java/lang/ConcreteProcess.java java/lang/natConcreteProcess.cc java/net/natInetAddress.cc java/net/natNetworkInterface.cc java/net/natPlainSocketImpl.cc java/net/natPlainDatagramSocketImpl.cc include/java-gc.h include/java-threads.h sysdep/locks.h include/java-signal.h"
+ac_sources="include/$PLATFORMH java/io/natFile${FILE-${PLATFORM}}.cc java/io/natFileDescriptor${FILE-${PLATFORM}}.cc java/lang/${PLATFORM}Process.java java/lang/nat${PLATFORM}Process.cc java/net/natInetAddress${PLATFORMNET}.cc java/net/natNetworkInterface${PLATFORMNET}.cc gnu/java/net/natPlainSocketImpl${PLATFORMNET}.cc gnu/java/net/natPlainDatagramSocketImpl${PLATFORMNET}.cc include/$GCHDR include/$THREADH sysdep/$sysdeps_dir/locks.h $SIGNAL_HANDLER"
+ac_dests="include/platform.h java/io/natFile.cc java/io/natFileDescriptor.cc java/lang/ConcreteProcess.java java/lang/natConcreteProcess.cc java/net/natInetAddress.cc java/net/natNetworkInterface.cc gnu/java/net/natPlainSocketImpl.cc gnu/java/net/natPlainDatagramSocketImpl.cc include/java-gc.h include/java-threads.h sysdep/locks.h include/java-signal.h"
EOF
cat >> $CONFIG_STATUS <<\EOF
fi
fi
- cd $ac_popdir
+ cd "$ac_popdir"
done
fi
AC_LINK_FILES(java/lang/${PLATFORM}Process.java, java/lang/ConcreteProcess.java)
AC_LINK_FILES(java/lang/nat${PLATFORM}Process.cc, java/lang/natConcreteProcess.cc)
-dnl Likewise for natInetAddress.cc, natNetworkInterface.cc, natPlainSocketImpl.cc
-dnl and natPlainDatagramSocketImpl.cc
+dnl Likewise for natInetAddress.cc and natNetworkInterface.cc.
test -d java/net || mkdir java/net
AC_LINK_FILES(java/net/natInetAddress${PLATFORMNET}.cc, java/net/natInetAddress.cc)
AC_LINK_FILES(java/net/natNetworkInterface${PLATFORMNET}.cc, java/net/natNetworkInterface.cc)
-AC_LINK_FILES(java/net/natPlainSocketImpl${PLATFORMNET}.cc, java/net/natPlainSocketImpl.cc)
-AC_LINK_FILES(java/net/natPlainDatagramSocketImpl${PLATFORMNET}.cc, java/net/natPlainDatagramSocketImpl.cc)
+
+dnl Likewise for natPlainSocketImpl.cc and natPlainDatagramSocketImpl.ca.c
+test -d gnu/java || mkdir gnu/java
+test -d gnu/java/net || mkdir gnu/java/net
+AC_LINK_FILES(gnu/java/net/natPlainSocketImpl${PLATFORMNET}.cc, gnu/java/net/natPlainSocketImpl.cc)
+AC_LINK_FILES(gnu/java/net/natPlainDatagramSocketImpl${PLATFORMNET}.cc, gnu/java/net/natPlainDatagramSocketImpl.cc)
case "${host}" in
*mingw*)
--- /dev/null
+/* PlainDatagramSocketImpl.java -- Default DatagramSocket implementation
+ Copyright (C) 1998, 1999, 2001, 2003 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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 gnu.java.net;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocketImpl;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.NetworkInterface;
+import java.net.SocketAddress;
+import java.net.SocketOptions;
+import java.net.SocketException;
+import gnu.classpath.Configuration;
+
+/**
+ * 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 is the default socket implementation for datagram sockets.
+ * It makes native calls to C routines that implement BSD style
+ * SOCK_DGRAM sockets in the AF_INET family.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @author Warren Levy <warrenl@cygnus.com>
+ */
+public final class PlainDatagramSocketImpl extends DatagramSocketImpl
+{
+ // Static initializer to load native library
+ static
+ {
+ if (Configuration.INIT_LOAD_LIBRARY)
+ {
+ System.loadLibrary("javanet");
+ }
+ }
+
+ // These fields are mirrored for use in native code to avoid cpp conflicts
+ // when the #defines in system header files are the same as the public fields.
+ static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
+ _Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
+ _Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
+ _Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
+ _Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
+ _Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
+ _Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
+ _Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
+ _Jv_IP_TOS_ = SocketOptions.IP_TOS,
+ _Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
+ _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
+ _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
+ _Jv_SO_RCVBUF_ = SocketOptions.SO_RCVBUF,
+ _Jv_SO_KEEPALIVE_ = SocketOptions.SO_KEEPALIVE;
+
+ /**
+ * This is the actual underlying file descriptor
+ */
+ int fnum = -1;
+
+ // FIXME: Is this necessary? Could it help w/ DatagramSocket.getLocalAddress?
+ // InetAddress address;
+
+ // localAddress cache
+ InetAddress localAddress;
+
+ // 'timeout' is set/read by setOption/getOption.
+ int timeout = 0;
+
+ /**
+ * Default do nothing constructor
+ */
+ public PlainDatagramSocketImpl()
+ {
+ }
+
+ /**
+ * Binds this socket to a particular port and interface
+ *
+ * @param port The port to bind to
+ * @param addr The address to bind to
+ *
+ * @exception SocketException If an error occurs
+ */
+ protected native void bind(int lport, InetAddress laddr)
+ throws SocketException;
+
+ protected native void connect (InetAddress i, int port)
+ throws SocketException;
+
+ protected native void disconnect ();
+
+ /**
+ * Creates a new datagram socket
+ *
+ * @exception SocketException If an error occurs
+ */
+ protected native void create() throws SocketException;
+
+ protected native int peek(InetAddress i) throws IOException;
+
+ protected native int peekData (DatagramPacket dp) throws IOException;
+
+ /**
+ * Sets the Time to Live value for the socket
+ *
+ * @param ttl The new TTL value
+ *
+ * @exception IOException If an error occurs
+ */
+ protected native void setTimeToLive(int ttl) throws IOException;
+
+ /**
+ * Gets the Time to Live value for the socket
+ *
+ * @return The TTL value
+ *
+ * @exception IOException If an error occurs
+ */
+ protected native int getTimeToLive() throws IOException;
+
+ /**
+ * Sends a packet of data to a remote host
+ *
+ * @param packet The packet to send
+ *
+ * @exception IOException If an error occurs
+ */
+ protected native void send(DatagramPacket p) throws IOException;
+
+ /**
+ * Receives a UDP packet from the network
+ *
+ * @param packet The packet to fill in with the data received
+ *
+ * @exception IOException IOException If an error occurs
+ */
+ protected native void receive(DatagramPacket p) throws IOException;
+
+ /**
+ * Sets the value of an option on the socket
+ *
+ * @param option_id The identifier of the option to set
+ * @param val The value of the option to set
+ *
+ * @exception SocketException If an error occurs
+ */
+ public native void setOption(int optID, Object value) throws SocketException;
+
+ /**
+ * Retrieves the value of an option on the socket
+ *
+ * @param option_id The identifier of the option to retrieve
+ *
+ * @return The value of the option
+ *
+ * @exception SocketException If an error occurs
+ */
+ public native Object getOption(int optID) throws SocketException;
+
+ private native void mcastGrp(InetAddress inetaddr, NetworkInterface netIf,
+ boolean join) throws IOException;
+
+ /**
+ * Closes the socket
+ */
+ protected native void close();
+
+ /**
+ * Gets the Time to Live value for the socket
+ *
+ * @return The TTL value
+ *
+ * @exception IOException If an error occurs
+ *
+ * @deprecated 1.2
+ */
+ protected byte getTTL() throws IOException
+ {
+ return (byte) getTimeToLive();
+ }
+
+ /**
+ * Sets the Time to Live value for the socket
+ *
+ * @param ttl The new TTL value
+ *
+ * @exception IOException If an error occurs
+ *
+ * @deprecated 1.2
+ */
+ protected void setTTL(byte ttl) throws IOException
+ {
+ setTimeToLive(((int) ttl) & 0xFF);
+ }
+
+ /**
+ * Joins a multicast group
+ *
+ * @param addr The group to join
+ *
+ * @exception IOException If an error occurs
+ */
+ protected void join(InetAddress inetaddr) throws IOException
+ {
+ mcastGrp(inetaddr, null, true);
+ }
+
+ /**
+ * Leaves a multicast group
+ *
+ * @param addr The group to leave
+ *
+ * @exception IOException If an error occurs
+ */
+ protected void leave(InetAddress inetaddr) throws IOException
+ {
+ mcastGrp(inetaddr, null, false);
+ }
+
+ protected void joinGroup (SocketAddress mcastaddr, NetworkInterface netIf)
+ throws IOException
+ {
+ mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, true);
+ }
+
+ protected void leaveGroup (SocketAddress mcastaddr, NetworkInterface netIf)
+ throws IOException
+ {
+ mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, false);
+ }
+
+ protected void finalize() throws Throwable
+ {
+ synchronized (this)
+ {
+ if (fnum != -1)
+ close();
+ }
+ super.finalize();
+ }
+}
--- /dev/null
+/* PlainSocketImpl.java -- Default socket implementation
+ Copyright (C) 1998, 1999, 2003 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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 gnu.java.net;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketImpl;
+import java.net.SocketOptions;
+import gnu.classpath.Configuration;
+
+/**
+ * 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.
+ */
+
+/**
+ * Unless the application installs its own SocketImplFactory, this is the
+ * default socket implemetation that will be used. It simply uses a
+ * combination of Java and native routines to implement standard BSD
+ * style sockets of family AF_INET and types SOCK_STREAM and SOCK_DGRAM
+ *
+ * @author Per Bothner <bothner@cygnus.com>
+ * @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ */
+public final class PlainSocketImpl extends SocketImpl
+{
+ // Static initializer to load native library.
+ static
+ {
+ if (Configuration.INIT_LOAD_LIBRARY)
+ {
+ System.loadLibrary("javanet");
+ }
+ }
+
+ // These fields are mirrored for use in native code to avoid cpp conflicts
+ // when the #defines in system header files are the same as the public fields.
+ static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
+ _Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
+ _Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
+ _Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
+ _Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
+ _Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
+ _Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
+ _Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
+ _Jv_IP_TOS_ = SocketOptions.IP_TOS,
+ _Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
+ _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
+ _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
+ _Jv_SO_RCVBUF_ = SocketOptions.SO_RCVBUF,
+ _Jv_SO_KEEPALIVE_ = SocketOptions.SO_KEEPALIVE;
+
+ /**
+ * The OS file handle representing the socket.
+ * This is used for reads and writes to/from the socket and
+ * to close it.
+ *
+ * When the socket is closed this is reset to -1.
+ */
+ int fnum = -1;
+
+ // This value is set/read by setOption/getOption.
+ int timeout = 0;
+
+ // localAddress cache
+ InetAddress localAddress;
+
+ /**
+ * A cached copy of the in stream for reading from the socket.
+ */
+ private InputStream in;
+
+ /**
+ * A cached copy of the out stream for writing to the socket.
+ */
+ private OutputStream out;
+
+ /**
+ * Default do nothing constructor
+ */
+ public PlainSocketImpl()
+ {
+ }
+
+ protected void finalize() throws Throwable
+ {
+ synchronized (this)
+ {
+ if (fnum != -1)
+ try
+ {
+ close();
+ }
+ catch (IOException ex)
+ {
+ // ignore
+ }
+ }
+ super.finalize();
+ }
+
+ /**
+ * Sets the specified option on a socket to the passed in object. For
+ * options that take an integer argument, the passed in object is an
+ * Integer. The option_id parameter is one of the defined constants in
+ * this interface.
+ *
+ * @param option_id The identifier of the option
+ * @param val The value to set the option to
+ *
+ * @exception SocketException If an error occurs
+ */
+ public native void setOption(int optID, Object value) throws SocketException;
+
+ /**
+ * Returns the current setting of the specified option. The Object returned
+ * will be an Integer for options that have integer values. The option_id
+ * is one of the defined constants in this interface.
+ *
+ * @param option_id The option identifier
+ *
+ * @return The current value of the option
+ *
+ * @exception SocketException If an error occurs
+ */
+ public native Object getOption(int optID) throws SocketException;
+
+ public native void shutdownInput () throws IOException;
+
+ public native void shutdownOutput () throws IOException;
+
+ /**
+ * Creates a new socket that is not bound to any local address/port and
+ * is not connected to any remote address/port. This will be created as
+ * a stream socket if the stream parameter is true, or a datagram socket
+ * if the stream parameter is false.
+ *
+ * @param stream true for a stream socket, false for a datagram socket
+ */
+ protected native void create (boolean stream) throws IOException;
+
+ /**
+ * Connects to the remote hostname and port specified as arguments.
+ *
+ * @param hostname The remote hostname to connect to
+ * @param port The remote port to connect to
+ *
+ * @exception IOException If an error occurs
+ */
+ protected void connect (String host, int port) throws IOException
+ {
+ connect (new InetSocketAddress (InetAddress.getByName(host), port), 0);
+ }
+
+ /**
+ * Connects to the remote address and port specified as arguments.
+ *
+ * @param addr The remote address to connect to
+ * @param port The remote port to connect to
+ *
+ * @exception IOException If an error occurs
+ */
+ protected void connect (InetAddress host, int port) throws IOException
+ {
+ connect (new InetSocketAddress (host, port), 0);
+ }
+
+ protected native void connect (SocketAddress addr, int timeout)
+ throws IOException;
+
+ /**
+ * Binds to the specified port on the specified addr. Note that this addr
+ * must represent a local IP address. **** How bind to INADDR_ANY? ****
+ *
+ * @param addr The address to bind to
+ * @param port The port number to bind to
+ *
+ * @exception IOException If an error occurs
+ */
+ protected native void bind (InetAddress host, int port) throws IOException;
+
+ /**
+ * Starts listening for connections on a socket. The queuelen parameter
+ * is how many pending connections will queue up waiting to be serviced
+ * before being accept'ed. If the queue of pending requests exceeds this
+ * number, additional connections will be refused.
+ *
+ * @param queuelen The length of the pending connection queue
+ *
+ * @exception IOException If an error occurs
+ */
+ protected native void listen (int backlog) throws IOException;
+
+ private native void accept (PlainSocketImpl s) throws IOException;
+
+ /**
+ * Accepts a new connection on this socket and returns in in the
+ * passed in SocketImpl.
+ *
+ * @param impl The SocketImpl object to accept this connection.
+ */
+ protected void accept (SocketImpl s) throws IOException
+ {
+ accept((PlainSocketImpl) s);
+ }
+
+ /**
+ * Returns the number of bytes that the caller can read from this socket
+ * without blocking.
+ *
+ * @return The number of readable bytes before blocking
+ *
+ * @exception IOException If an error occurs
+ */
+ protected native int available() throws IOException;
+
+ /**
+ * Closes the socket. This will cause any InputStream or OutputStream
+ * objects for this Socket to be closed as well.
+ * <p>
+ * Note that if the SO_LINGER option is set on this socket, then the
+ * operation could block.
+ *
+ * @exception IOException If an error occurs
+ */
+ protected native void close () throws IOException;
+
+ protected native void sendUrgentData(int data)
+ throws IOException;
+
+ native int read() throws IOException;
+
+ /**
+ * Internal method used by SocketInputStream for reading data from
+ * the connection. Reads up to len bytes of data into the buffer
+ * buf starting at offset bytes into the buffer.
+ *
+ * @return The actual number of bytes read or -1 if end of stream.
+ *
+ * @exception IOException If an error occurs
+ */
+ native int read(byte[] buffer, int offset, int count)
+ throws IOException;
+
+ native void write(int c) throws IOException;
+
+ /**
+ * Internal method used by SocketOuputStream for writing data to
+ * the connection. Writes up to len bytes of data from the buffer
+ * buf starting at offset bytes into the buffer.
+ *
+ * @exception IOException If an error occurs
+ */
+ native void write(byte[] buffer, int offset, int count)
+ throws IOException;
+
+ /**
+ * Returns an InputStream object for reading from this socket. This will
+ * be an instance of SocketInputStream.
+ *
+ * @return An input stream attached to the socket.
+ *
+ * @exception IOException If an error occurs
+ */
+ protected synchronized InputStream getInputStream() throws IOException
+ {
+ if (in == null)
+ in = new SocketInputStream();
+
+ return in;
+ }
+
+ /**
+ * Returns an OutputStream object for writing to this socket. This will
+ * be an instance of SocketOutputStream.
+ *
+ * @return An output stream attached to the socket.
+ *
+ * @exception IOException If an error occurs
+ */
+ protected synchronized OutputStream getOutputStream() throws IOException
+ {
+ if (out == null)
+ out = new SocketOutputStream();
+
+ return out;
+ }
+
+ /**
+ * A stream which reads from the socket implementation.
+ *
+ * @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
+ */
+ class SocketInputStream
+ extends InputStream
+ {
+ SocketInputStream()
+ {
+ }
+
+ public final void close() throws IOException
+ {
+ PlainSocketImpl.this.close();
+ }
+
+ public final int available() throws IOException
+ {
+ return PlainSocketImpl.this.available();
+ }
+
+ public final int read() throws IOException
+ {
+ return PlainSocketImpl.this.read();
+ }
+
+ public final int read(byte[] buffer, int offset, int length)
+ throws IOException
+ {
+ return PlainSocketImpl.this.read(buffer, offset, length);
+ }
+
+ public final int read(byte[] buffer)
+ throws IOException
+ {
+ return PlainSocketImpl.this.read(buffer, 0, buffer.length);
+ }
+ }
+
+ /** A stream which writes to the socket implementation.
+ *
+ * @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
+ */
+ class SocketOutputStream
+ extends OutputStream
+ {
+ public final void close() throws IOException
+ {
+ PlainSocketImpl.this.close();
+ }
+
+ public final void write(int c) throws IOException
+ {
+ PlainSocketImpl.this.write(c);
+ }
+
+ public final void write(byte[] buffer, int offset, int length)
+ throws IOException
+ {
+ PlainSocketImpl.this.write(buffer, offset, length);
+ }
+
+ public final void write(byte[] buffer)
+ throws IOException
+ {
+ PlainSocketImpl.this.write(buffer, 0, buffer.length);
+ }
+ }
+}
--- /dev/null
+/* SocketInputStream.java -- An InputStream for Sockets
+ Copyright (C) 1998, 2000, 2002 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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 gnu.java.net;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * This class contains an implementation of <code>InputStream</code> for
+ * sockets. It in an internal only class used by <code>PlainSocketImpl</code>.
+ *
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ */
+class SocketInputStream extends InputStream
+{
+
+/*************************************************************************/
+
+/*
+ * Instance Variables
+ */
+
+/**
+ * The PlainSocketImpl object this stream is associated with
+ */
+private PlainSocketImpl impl;
+
+/*************************************************************************/
+
+/*
+ * Constructors
+ */
+
+/**
+ * Builds an instance of this class from a PlainSocketImpl object
+ */
+protected
+SocketInputStream(PlainSocketImpl impl)
+{
+ this.impl = impl;
+}
+
+/*************************************************************************/
+
+/*
+ * Instance Methods
+ */
+
+/**
+ * Returns the number of bytes available to be read before blocking
+ */
+public int
+available() throws IOException
+{
+ return(impl.available());
+}
+
+/*************************************************************************/
+
+/**
+ * Determines if "mark" functionality is supported on this stream. For
+ * sockets, this is always false. Note that the superclass default is
+ * false, but it is overridden out of safety concerns and/or paranoia.
+ */
+public boolean
+markSupported()
+{
+ return(false);
+}
+
+/*************************************************************************/
+
+/**
+ * Do nothing mark method since we don't support this functionality. Again,
+ * overriding out of paranoia.
+ *
+ * @param readlimit In theory, the number of bytes we can read before the mark becomes invalid
+ */
+public void
+mark(int readlimit)
+{
+}
+
+/*************************************************************************/
+
+/**
+ * Since we don't support mark, this method always throws an exception
+ *
+ * @exception IOException Everytime since we don't support this functionality
+ */
+public void
+reset() throws IOException
+{
+ throw new IOException("Socket InputStreams do not support mark/reset");
+}
+
+/*************************************************************************/
+
+/**
+ * This method not only closes the stream, it closes the underlying socket
+ * (and thus any connection) and invalidates any other Input/Output streams
+ * for the underlying impl object
+ */
+public void
+close() throws IOException
+{
+ impl.close();
+}
+
+/*************************************************************************/
+
+/**
+ * Reads the next byte of data and returns it as an int.
+ *
+ * @return The byte read (as an int) or -1 if end of stream);
+ *
+ * @exception IOException If an error occurs.
+ */
+public int
+read() throws IOException
+{
+ byte buf[] = new byte[1];
+
+ int bytes_read = read(buf, 0, buf.length);
+
+ if (bytes_read != -1)
+ return(buf[0] & 0xFF);
+ else
+ return(-1);
+}
+
+/*************************************************************************/
+
+/**
+ * Reads up to buf.length bytes of data into the caller supplied buffer.
+ *
+ * @return The actual number of bytes read or -1 if end of stream
+ *
+ * @exception IOException If an error occurs.
+ */
+public int
+read(byte[] buf) throws IOException
+{
+ return(read(buf, 0, buf.length));
+}
+
+/*************************************************************************/
+
+/**
+ * Reads up to len bytes of data into the caller supplied buffer starting
+ * at offset bytes from the start of the buffer
+ *
+ * @return The number of bytes actually read or -1 if end of stream
+ *
+ * @exception IOException If an error occurs.
+ */
+public int
+read(byte[] buf, int offset, int len) throws IOException
+{
+ int bytes_read = impl.read(buf, offset, len);
+ if (bytes_read == 0)
+ return(-1);
+
+ return(bytes_read);
+}
+
+} // class SocketInputStream
+
--- /dev/null
+/* SocketOutputStream.java -- OutputStream for PlainSocketImpl
+ Copyright (C) 1998,2000 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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 gnu.java.net;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+/**
+ * This class is used internally by <code>PlainSocketImpl</code> to be the
+ * <code>OutputStream</code> subclass returned by its
+ * <code>getOutputStream method</code>. It expects only to be used in that
+ * context.
+ *
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ */
+class SocketOutputStream extends OutputStream
+{
+
+/*************************************************************************/
+
+/*
+ * Instance Variables
+ */
+
+/**
+ * The PlainSocketImpl object this stream is associated with
+ */
+private PlainSocketImpl impl;
+
+/*************************************************************************/
+
+/*
+ * Constructors
+ */
+
+/**
+ * Build an instance of this class from a PlainSocketImpl object
+ */
+protected
+SocketOutputStream(PlainSocketImpl impl)
+{
+ this.impl = impl;
+}
+
+/*************************************************************************/
+
+/*
+ * Instance Methods
+ */
+
+/**
+ * This method closes the stream and the underlying socket connection. This
+ * action also effectively closes any other InputStream or OutputStream
+ * object associated with the connection.
+ *
+ * @exception IOException If an error occurs
+ */
+public void
+close() throws IOException
+{
+ impl.close();
+}
+
+/*************************************************************************/
+
+/**
+ * Hmmm, we don't seem to have a flush() method in Socket impl, so just
+ * return for now, but this might need to be looked at later.
+ *
+ * @exception IOException Can't happen
+ */
+public void
+flush() throws IOException
+{
+ return;
+}
+
+/*************************************************************************/
+
+/**
+ * Writes a byte (passed in as an int) to the given output stream
+ *
+ * @param b The byte to write
+ *
+ * @exception IOException If an error occurs
+ */
+public void
+write(int b) throws IOException
+{
+ byte buf[] = new byte[1];
+
+ Integer i = new Integer(b);
+ buf[0] = i.byteValue();
+
+ write(buf, 0, buf.length);
+}
+
+/*************************************************************************/
+
+/**
+ * Write an array of bytes to the output stream
+ *
+ * @param buf The array of bytes to write
+ *
+ * @exception IOException If an error occurs
+ */
+public void
+write(byte[] buf) throws IOException
+{
+ write(buf, 0, buf.length);
+}
+
+/*************************************************************************/
+
+/**
+ * Writes len number of bytes from the array buf to the stream starting
+ * at offset bytes into the buffer.
+ *
+ * @param buf The buffer
+ * @param offset Offset into the buffer to start writing from
+ * @param len The number of bytes to write
+ */
+public void
+write(byte[] buf, int offset, int len) throws IOException
+{
+ impl.write(buf, offset, len);
+}
+
+} // class SocketOutputStream
+
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+
+#include <gnu/java/net/PlainDatagramSocketImpl.h>
+#include <java/io/IOException.h>
+#include <java/lang/Object.h>
+#include <java/net/BindException.h>
+#include <java/net/DatagramPacket.h>
+#include <java/net/InetAddress.h>
+#include <java/net/NetworkInterface.h>
+#include <java/net/SocketException.h>
+
+void
+gnu::java::net::PlainDatagramSocketImpl::create ()
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("DatagramSocketImpl.create: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::bind (jint, ::java::net::InetAddress *)
+{
+ throw new ::java::net::BindException (
+ JvNewStringLatin1 ("DatagramSocketImpl.bind: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::connect (::java::net::InetAddress *, jint)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("DatagramSocketImpl.connect: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::disconnect ()
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("DatagramSocketImpl.disconnect: unimplemented"));
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::peek (::java::net::InetAddress *)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("DatagramSocketImpl.peek: unimplemented"));
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::peekData (::java::net::DatagramPacket *)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("DatagramSocketImpl.peekData: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::close ()
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("DatagramSocketImpl.close: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::send (::java::net::DatagramPacket *)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("DatagramSocketImpl.send: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::receive (::java::net::DatagramPacket *)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("DatagramSocketImpl.receive: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::setTimeToLive (jint)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("DatagramSocketImpl.setTimeToLive: unimplemented"));
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::getTimeToLive ()
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("DatagramSocketImpl.getTimeToLive: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::mcastGrp (::java::net::InetAddress *,
+ ::java::net::NetworkInterface *,
+ jboolean)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("DatagramSocketImpl.mcastGrp: unimplemented"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::setOption (jint, ::java::lang::Object *)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("DatagramSocketImpl.setOption: unimplemented"));
+}
+
+::java::lang::Object *
+gnu::java::net::PlainDatagramSocketImpl::getOption (jint)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("DatagramSocketImpl.getOption: unimplemented"));
+}
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#include <errno.h>
+#include <string.h>
+
+#if HAVE_BSTRING_H
+// Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
+#include <bstring.h>
+#endif
+
+#include <gcj/cni.h>
+#include <gnu/java/net/PlainDatagramSocketImpl.h>
+#include <java/io/IOException.h>
+#include <java/io/InterruptedIOException.h>
+#include <java/net/BindException.h>
+#include <java/net/SocketException.h>
+#include <java/net/InetAddress.h>
+#include <java/net/NetworkInterface.h>
+#include <java/net/DatagramPacket.h>
+#include <java/net/PortUnreachableException.h>
+#include <java/lang/InternalError.h>
+#include <java/lang/Object.h>
+#include <java/lang/Boolean.h>
+#include <java/lang/Integer.h>
+
+union SockAddr
+{
+ struct sockaddr_in address;
+#ifdef HAVE_INET6
+ struct sockaddr_in6 address6;
+#endif
+};
+
+union McastReq
+{
+#if HAVE_STRUCT_IP_MREQ
+ struct ip_mreq mreq;
+#endif
+#if HAVE_STRUCT_IPV6_MREQ
+ struct ipv6_mreq mreq6;
+#endif
+};
+
+union InAddr
+{
+ struct in_addr addr;
+#ifdef HAVE_INET6
+ struct in6_addr addr6;
+#endif
+};
+
+
+// FIXME: routines here and/or in natPlainSocketImpl.cc could throw
+// NoRouteToHostException; also consider UnknownHostException, ConnectException.
+
+void
+gnu::java::net::PlainDatagramSocketImpl::create ()
+{
+ int sock = _Jv_socket (AF_INET, SOCK_DGRAM, 0);
+
+ if (sock < 0)
+ {
+ char* strerr = strerror (errno);
+ throw new ::java::net::SocketException (JvNewStringUTF (strerr));
+ }
+
+ _Jv_platform_close_on_exec (sock);
+
+ // We use fnum in place of fd here. From leaving fd null we avoid
+ // the double close problem in FileDescriptor.finalize.
+ fnum = sock;
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::bind (jint lport,
+ ::java::net::InetAddress *host)
+{
+ union SockAddr u;
+ struct sockaddr *ptr = (struct sockaddr *) &u.address;
+ // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
+ jbyteArray haddress = host->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+
+ if (len == 4)
+ {
+ u.address.sin_family = AF_INET;
+
+ if (host != NULL)
+ memcpy (&u.address.sin_addr, bytes, len);
+ else
+ u.address.sin_addr.s_addr = htonl (INADDR_ANY);
+
+ len = sizeof (struct sockaddr_in);
+ u.address.sin_port = htons (lport);
+ }
+#ifdef HAVE_INET6
+ else if (len == 16)
+ {
+ u.address6.sin6_family = AF_INET6;
+ memcpy (&u.address6.sin6_addr, bytes, len);
+ len = sizeof (struct sockaddr_in6);
+ u.address6.sin6_port = htons (lport);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (_Jv_bind (fnum, ptr, len) == 0)
+ {
+ socklen_t addrlen = sizeof(u);
+
+ if (lport != 0)
+ localPort = lport;
+ else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
+ localPort = ntohs (u.address.sin_port);
+ else
+ goto error;
+
+ /* Allow broadcast by default. */
+ int broadcast = 1;
+ if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &broadcast,
+ sizeof (broadcast)) != 0)
+ goto error;
+
+ return;
+ }
+
+ error:
+ char* strerr = strerror (errno);
+ throw new ::java::net::BindException (JvNewStringUTF (strerr));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::connect (::java::net::InetAddress *, jint)
+{
+ throw new ::java::lang::InternalError (JvNewStringLatin1 (
+ "PlainDatagramSocketImpl::connect: not implemented yet"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::disconnect ()
+{
+ throw new ::java::lang::InternalError (JvNewStringLatin1 (
+ "PlainDatagramSocketImpl::disconnect: not implemented yet"));
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::peek (::java::net::InetAddress *i)
+{
+ // FIXME: Deal with Multicast and if the socket is connected.
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ ssize_t retlen =
+ ::recvfrom (fnum, (char *) NULL, 0, MSG_PEEK, (sockaddr*) &u,
+ &addrlen);
+ if (retlen < 0)
+ goto error;
+ // FIXME: Deal with Multicast addressing and if the socket is connected.
+ jbyteArray raddr;
+ jint rport;
+ if (u.address.sin_family == AF_INET)
+ {
+ raddr = JvNewByteArray (4);
+ memcpy (elements (raddr), &u.address.sin_addr, 4);
+ rport = ntohs (u.address.sin_port);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ raddr = JvNewByteArray (16);
+ memcpy (elements (raddr), &u.address6.sin6_addr, 16);
+ rport = ntohs (u.address6.sin6_port);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
+
+ i->addr = raddr;
+ return rport;
+ error:
+ char* strerr = strerror (errno);
+
+ if (errno == ECONNREFUSED)
+ throw new ::java::net::PortUnreachableException (JvNewStringUTF (strerr));
+
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::peekData (::java::net::DatagramPacket *p)
+{
+ // FIXME: Deal with Multicast and if the socket is connected.
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ jbyte *dbytes = elements (p->getData());
+ ssize_t retlen = 0;
+
+ // Do timeouts via select since SO_RCVTIMEO is not always available.
+ if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
+ {
+ fd_set rset;
+ struct timeval tv;
+ FD_ZERO(&rset);
+ FD_SET(fnum, &rset);
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ int retval;
+ if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
+ goto error;
+ else if (retval == 0)
+ throw new ::java::io::InterruptedIOException ();
+ }
+
+ retlen =
+ ::recvfrom (fnum, (char *) dbytes, p->getLength(), MSG_PEEK, (sockaddr*) &u,
+ &addrlen);
+ if (retlen < 0)
+ goto error;
+ // FIXME: Deal with Multicast addressing and if the socket is connected.
+ jbyteArray raddr;
+ jint rport;
+ if (u.address.sin_family == AF_INET)
+ {
+ raddr = JvNewByteArray (4);
+ memcpy (elements (raddr), &u.address.sin_addr, 4);
+ rport = ntohs (u.address.sin_port);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ raddr = JvNewByteArray (16);
+ memcpy (elements (raddr), &u.address6.sin6_addr, 16);
+ rport = ntohs (u.address6.sin6_port);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
+
+ p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+ p->setPort (rport);
+ p->setLength ((jint) retlen);
+ return rport;
+
+ error:
+ char* strerr = strerror (errno);
+
+ if (errno == ECONNREFUSED)
+ throw new ::java::net::PortUnreachableException (JvNewStringUTF (strerr));
+
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+}
+
+// Close(shutdown) the socket.
+void
+gnu::java::net::PlainDatagramSocketImpl::close ()
+{
+ // Avoid races from asynchronous finalization.
+ JvSynchronize sync (this);
+
+ // The method isn't declared to throw anything, so we disregard
+ // the return value.
+ _Jv_close (fnum);
+ fnum = -1;
+ timeout = 0;
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::send (::java::net::DatagramPacket *p)
+{
+ // FIXME: Deal with Multicast and if the socket is connected.
+ jint rport = p->getPort();
+ union SockAddr u;
+ jbyteArray haddress = p->getAddress()->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+ struct sockaddr *ptr = (struct sockaddr *) &u.address;
+ jbyte *dbytes = elements (p->getData());
+ if (len == 4)
+ {
+ u.address.sin_family = AF_INET;
+ memcpy (&u.address.sin_addr, bytes, len);
+ len = sizeof (struct sockaddr_in);
+ u.address.sin_port = htons (rport);
+ }
+#ifdef HAVE_INET6
+ else if (len == 16)
+ {
+ u.address6.sin6_family = AF_INET6;
+ memcpy (&u.address6.sin6_addr, bytes, len);
+ len = sizeof (struct sockaddr_in6);
+ u.address6.sin6_port = htons (rport);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (::sendto (fnum, (char *) dbytes, p->getLength(), 0, ptr, len) >= 0)
+ return;
+
+ char* strerr = strerror (errno);
+
+ if (errno == ECONNREFUSED)
+ throw new ::java::net::PortUnreachableException (JvNewStringUTF (strerr));
+
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::receive (::java::net::DatagramPacket *p)
+{
+ // FIXME: Deal with Multicast and if the socket is connected.
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ jbyte *dbytes = elements (p->getData());
+ ssize_t retlen = 0;
+
+ // Do timeouts via select since SO_RCVTIMEO is not always available.
+ if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
+ {
+ fd_set rset;
+ struct timeval tv;
+ FD_ZERO(&rset);
+ FD_SET(fnum, &rset);
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ int retval;
+ if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
+ goto error;
+ else if (retval == 0)
+ throw new ::java::io::InterruptedIOException ();
+ }
+
+ retlen =
+ ::recvfrom (fnum, (char *) dbytes, p->getLength(), 0, (sockaddr*) &u,
+ &addrlen);
+ if (retlen < 0)
+ goto error;
+ // FIXME: Deal with Multicast addressing and if the socket is connected.
+ jbyteArray raddr;
+ jint rport;
+ if (u.address.sin_family == AF_INET)
+ {
+ raddr = JvNewByteArray (4);
+ memcpy (elements (raddr), &u.address.sin_addr, 4);
+ rport = ntohs (u.address.sin_port);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ raddr = JvNewByteArray (16);
+ memcpy (elements (raddr), &u.address6.sin6_addr, 16);
+ rport = ntohs (u.address6.sin6_port);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
+
+ p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+ p->setPort (rport);
+ p->setLength ((jint) retlen);
+ return;
+
+ error:
+ char* strerr = strerror (errno);
+
+ if (errno == ECONNREFUSED)
+ throw new ::java::net::PortUnreachableException (JvNewStringUTF (strerr));
+
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::setTimeToLive (jint ttl)
+{
+ // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
+ char val = (char) ttl;
+ socklen_t val_len = sizeof(val);
+
+ if (::setsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, val_len) == 0)
+ return;
+
+ char* strerr = strerror (errno);
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::getTimeToLive ()
+{
+ // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
+ char val;
+ socklen_t val_len = sizeof(val);
+
+ if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, &val_len) == 0)
+ return ((int) val) & 0xFF;
+
+ char* strerr = strerror (errno);
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::mcastGrp (::java::net::InetAddress *inetaddr,
+ ::java::net::NetworkInterface *,
+ jboolean join)
+{
+ // FIXME: implement use of NetworkInterface
+
+ union McastReq u;
+ jbyteArray haddress = inetaddr->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+ int level, opname;
+ const char *ptr;
+ if (0)
+ ;
+#if HAVE_STRUCT_IP_MREQ
+ else if (len == 4)
+ {
+ level = IPPROTO_IP;
+ opname = join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP;
+ memcpy (&u.mreq.imr_multiaddr, bytes, len);
+ // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
+ // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
+ u.mreq.imr_interface.s_addr = htonl (INADDR_ANY);
+ len = sizeof (struct ip_mreq);
+ ptr = (const char *) &u.mreq;
+ }
+#endif
+#if HAVE_STRUCT_IPV6_MREQ
+ else if (len == 16)
+ {
+ level = IPPROTO_IPV6;
+
+ /* Prefer new RFC 2553 names. */
+#ifndef IPV6_JOIN_GROUP
+#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
+#endif
+#ifndef IPV6_LEAVE_GROUP
+#define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
+#endif
+
+ opname = join ? IPV6_JOIN_GROUP : IPV6_LEAVE_GROUP;
+ memcpy (&u.mreq6.ipv6mr_multiaddr, bytes, len);
+ // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
+ // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
+ u.mreq6.ipv6mr_interface = 0;
+ len = sizeof (struct ipv6_mreq);
+ ptr = (const char *) &u.mreq6;
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (::setsockopt (fnum, level, opname, ptr, len) == 0)
+ return;
+
+ char* strerr = strerror (errno);
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::setOption (jint optID,
+ ::java::lang::Object *value)
+{
+ int val;
+ socklen_t val_len = sizeof (val);
+
+ if (fnum < 0)
+ throw new ::java::net::SocketException (JvNewStringUTF ("Socket closed"));
+
+ if (_Jv_IsInstanceOf (value, &::java::lang::Boolean::class$))
+ {
+ ::java::lang::Boolean *boolobj =
+ static_cast< ::java::lang::Boolean *> (value);
+ val = boolobj->booleanValue() ? 1 : 0;
+ }
+ else if (_Jv_IsInstanceOf (value, &::java::lang::Integer::class$))
+ {
+ ::java::lang::Integer *intobj =
+ static_cast< ::java::lang::Integer *> (value);
+ val = (int) intobj->intValue();
+ }
+ // Else assume value to be an InetAddress for use with IP_MULTICAST_IF.
+
+ switch (optID)
+ {
+ case _Jv_TCP_NODELAY_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("TCP_NODELAY not valid for UDP"));
+ return;
+ case _Jv_SO_LINGER_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_LINGER not valid for UDP"));
+ return;
+ case _Jv_SO_KEEPALIVE_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
+ return;
+
+ case _Jv_SO_BROADCAST_ :
+ if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+ val_len) != 0)
+ goto error;
+ break;
+
+ case _Jv_SO_OOBINLINE_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_OOBINLINE: not valid for UDP"));
+ break;
+
+ case _Jv_SO_SNDBUF_ :
+ case _Jv_SO_RCVBUF_ :
+#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
+ int opt;
+ optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
+ if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
+ goto error;
+#else
+ throw new ::java::lang::InternalError (
+ JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
+#endif
+ return;
+ case _Jv_SO_REUSEADDR_ :
+#if defined(SO_REUSEADDR)
+ if (::setsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
+ val_len) != 0)
+ goto error;
+#else
+ throw new ::java::lang::InternalError (
+ JvNewStringUTF ("SO_REUSEADDR not supported"));
+#endif
+ return;
+ case _Jv_SO_BINDADDR_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_BINDADDR: read only option"));
+ return;
+ case _Jv_IP_MULTICAST_IF_ :
+ union InAddr u;
+ jbyteArray haddress;
+ jbyte *bytes;
+ int len;
+ int level, opname;
+ const char *ptr;
+
+ haddress = ((::java::net::InetAddress *) value)->addr;
+ bytes = elements (haddress);
+ len = haddress->length;
+ if (len == 4)
+ {
+ level = IPPROTO_IP;
+ opname = IP_MULTICAST_IF;
+ memcpy (&u.addr, bytes, len);
+ len = sizeof (struct in_addr);
+ ptr = (const char *) &u.addr;
+ }
+// Tru64 UNIX V5.0 has struct sockaddr_in6, but no IPV6_MULTICAST_IF
+#if defined (HAVE_INET6) && defined (IPV6_MULTICAST_IF)
+ else if (len == 16)
+ {
+ level = IPPROTO_IPV6;
+ opname = IPV6_MULTICAST_IF;
+ memcpy (&u.addr6, bytes, len);
+ len = sizeof (struct in6_addr);
+ ptr = (const char *) &u.addr6;
+ }
+#endif
+ else
+ throw
+ new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (::setsockopt (fnum, level, opname, ptr, len) != 0)
+ goto error;
+ return;
+
+ case _Jv_IP_MULTICAST_IF2_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
+ break;
+
+ case _Jv_IP_MULTICAST_LOOP_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_LOOP: not yet implemented"));
+ break;
+
+ case _Jv_IP_TOS_ :
+ if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+ val_len) != 0)
+ goto error;
+ return;
+
+ case _Jv_SO_TIMEOUT_ :
+ timeout = val;
+ return;
+ default :
+ errno = ENOPROTOOPT;
+ }
+
+ error:
+ char* strerr = strerror (errno);
+ throw new ::java::net::SocketException (JvNewStringUTF (strerr));
+}
+
+::java::lang::Object *
+gnu::java::net::PlainDatagramSocketImpl::getOption (jint optID)
+{
+ int val;
+ socklen_t val_len = sizeof(val);
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+
+ switch (optID)
+ {
+ case _Jv_TCP_NODELAY_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("TCP_NODELAY not valid for UDP"));
+ break;
+ case _Jv_SO_LINGER_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_LINGER not valid for UDP"));
+ break;
+ case _Jv_SO_KEEPALIVE_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
+ break;
+
+ case _Jv_SO_BROADCAST_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Boolean (val != 0);
+
+ case _Jv_SO_OOBINLINE_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_OOBINLINE not valid for UDP"));
+ break;
+
+ case _Jv_SO_RCVBUF_ :
+ case _Jv_SO_SNDBUF_ :
+#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
+ int opt;
+ optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
+ if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
+ goto error;
+ else
+ return new ::java::lang::Integer (val);
+#else
+ throw new ::java::lang::InternalError (
+ JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
+#endif
+ break;
+ case _Jv_SO_BINDADDR_:
+ // cache the local address
+ if (localAddress == NULL)
+ {
+ jbyteArray laddr;
+ if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
+ goto error;
+ if (u.address.sin_family == AF_INET)
+ {
+ laddr = JvNewByteArray (4);
+ memcpy (elements (laddr), &u.address.sin_addr, 4);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ laddr = JvNewByteArray (16);
+ memcpy (elements (laddr), &u.address6.sin6_addr, 16);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("invalid family"));
+ localAddress = new ::java::net::InetAddress (laddr, NULL);
+ }
+ return localAddress;
+ break;
+ case _Jv_SO_REUSEADDR_ :
+#if defined(SO_REUSEADDR)
+ if (::getsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Boolean (val != 0);
+#else
+ throw new ::java::lang::InternalError (
+ JvNewStringUTF ("SO_REUSEADDR not supported"));
+#endif
+ break;
+ case _Jv_IP_MULTICAST_IF_ :
+#ifdef HAVE_INET_NTOA
+ struct in_addr inaddr;
+ socklen_t inaddr_len;
+ char *bytes;
+
+ inaddr_len = sizeof(inaddr);
+ if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_IF, (char *) &inaddr,
+ &inaddr_len) != 0)
+ goto error;
+
+ bytes = inet_ntoa (inaddr);
+
+ return ::java::net::InetAddress::getByName (JvNewStringLatin1 (bytes));
+#else
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF: not available - no inet_ntoa()"));
+#endif
+ break;
+ case _Jv_SO_TIMEOUT_ :
+ return new ::java::lang::Integer (timeout);
+ break;
+
+ case _Jv_IP_MULTICAST_IF2_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
+ break;
+
+ case _Jv_IP_MULTICAST_LOOP_ :
+ if (::getsockopt (fnum, SOL_SOCKET, IP_MULTICAST_LOOP, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Boolean (val != 0);
+
+ case _Jv_IP_TOS_ :
+ if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Integer (val);
+
+ default :
+ errno = ENOPROTOOPT;
+ }
+
+ error:
+ char* strerr = strerror (errno);
+ throw new ::java::net::SocketException (JvNewStringUTF (strerr));
+}
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+#include <string.h>
+
+#if HAVE_BSTRING_H
+// Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
+#include <bstring.h>
+#endif
+
+#include <gnu/java/net/PlainDatagramSocketImpl.h>
+#include <java/io/IOException.h>
+#include <java/io/InterruptedIOException.h>
+#include <java/net/BindException.h>
+#include <java/net/SocketException.h>
+#include <java/net/InetAddress.h>
+#include <java/net/NetworkInterface.h>
+#include <java/net/DatagramPacket.h>
+#include <java/net/PortUnreachableException.h>
+#include <java/net/SocketTimeoutException.h>
+#include <java/lang/InternalError.h>
+#include <java/lang/Object.h>
+#include <java/lang/Boolean.h>
+#include <java/lang/Integer.h>
+
+union SockAddr
+{
+ struct sockaddr_in address;
+#ifdef HAVE_INET6
+ struct sockaddr_in6 address6;
+#endif
+};
+
+union McastReq
+{
+#if HAVE_STRUCT_IP_MREQ
+ struct ip_mreq mreq;
+#endif
+#if HAVE_STRUCT_IPV6_MREQ
+ struct ipv6_mreq mreq6;
+#endif
+};
+
+union InAddr
+{
+ struct in_addr addr;
+#ifdef HAVE_INET6
+ struct in6_addr addr6;
+#endif
+};
+
+// FIXME: routines here and/or in natPlainSocketImpl.cc could throw
+// NoRouteToHostException; also consider UnknownHostException, ConnectException.
+
+void
+gnu::java::net::PlainDatagramSocketImpl::create ()
+{
+ SOCKET sock = ::socket (AF_INET, SOCK_DGRAM, 0);
+
+ if (sock == INVALID_SOCKET)
+ {
+ _Jv_ThrowSocketException ();
+ }
+
+ _Jv_platform_close_on_exec (sock);
+
+ // We use fnum in place of fd here. From leaving fd null we avoid
+ // the double close problem in FileDescriptor.finalize.
+ fnum = (int) sock;
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::bind (jint lport,
+ ::java::net::InetAddress *host)
+{
+ union SockAddr u;
+ struct sockaddr *ptr = (struct sockaddr *) &u.address;
+ // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
+ jbyteArray haddress = host->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+
+ if (len == 4)
+ {
+ u.address.sin_family = AF_INET;
+
+ if (host != NULL)
+ memcpy (&u.address.sin_addr, bytes, len);
+ else
+ u.address.sin_addr.s_addr = htonl (INADDR_ANY);
+
+ len = sizeof (struct sockaddr_in);
+ u.address.sin_port = htons (lport);
+ }
+#ifdef HAVE_INET6
+ else if (len == 16)
+ {
+ u.address6.sin6_family = AF_INET6;
+ memcpy (&u.address6.sin6_addr, bytes, len);
+ len = sizeof (struct sockaddr_in6);
+ u.address6.sin6_port = htons (lport);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (::bind (fnum, ptr, len) == 0)
+ {
+ socklen_t addrlen = sizeof(u);
+
+ if (lport != 0)
+ localPort = lport;
+ else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
+ localPort = ntohs (u.address.sin_port);
+ else
+ goto error;
+
+ /* Allow broadcast by default. */
+ int broadcast = 1;
+ if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &broadcast,
+ sizeof (broadcast)) != 0)
+ goto error;
+
+ return;
+ }
+
+error:
+ DWORD dwErrorCode = WSAGetLastError ();
+ throw new ::java::net::BindException (_Jv_WinStrError (dwErrorCode));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::connect (::java::net::InetAddress *, jint)
+{
+ throw new ::java::lang::InternalError (JvNewStringLatin1 (
+ "PlainDatagramSocketImpl::connect: not implemented yet"));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::disconnect ()
+{
+ throw new ::java::lang::InternalError (JvNewStringLatin1 (
+ "PlainDatagramSocketImpl::disconnect: not implemented yet"));
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::peek (::java::net::InetAddress *i)
+{
+ // FIXME: Deal with Multicast and if the socket is connected.
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ ssize_t retlen =
+ ::recvfrom (fnum, (char *) NULL, 0, MSG_PEEK, (sockaddr*) &u,
+ &addrlen);
+ if (retlen < 0)
+ goto error;
+ // FIXME: Deal with Multicast addressing and if the socket is connected.
+ jbyteArray raddr;
+ jint rport;
+ if (u.address.sin_family == AF_INET)
+ {
+ raddr = JvNewByteArray (4);
+ memcpy (elements (raddr), &u.address.sin_addr, 4);
+ rport = ntohs (u.address.sin_port);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ raddr = JvNewByteArray (16);
+ memcpy (elements (raddr), &u.address6.sin6_addr, 16);
+ rport = ntohs (u.address6.sin6_port);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
+
+ i->addr = raddr;
+ return rport;
+error:
+ DWORD dwErrorCode = WSAGetLastError ();
+ if (dwErrorCode == WSAECONNRESET)
+ throw new ::java::net::PortUnreachableException (_Jv_WinStrError (dwErrorCode));
+
+ _Jv_ThrowIOException ();
+ return -1;
+ // we should never get here
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::peekData(::java::net::DatagramPacket *p)
+{
+ // FIXME: Deal with Multicast and if the socket is connected.
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ jbyte *dbytes = elements (p->getData());
+ ssize_t retlen = 0;
+
+ if (timeout > 0)
+ {
+ int nRet= ::setsockopt(fnum, SOL_SOCKET, SO_RCVTIMEO,
+ (char*)&timeout, sizeof(timeout));
+ if (nRet != NO_ERROR)
+ goto error;
+ }
+
+ retlen =
+ ::recvfrom (fnum, (char *) dbytes, p->getLength(), MSG_PEEK, (sockaddr*) &u,
+ &addrlen);
+ if (retlen == SOCKET_ERROR)
+ goto error;
+ // FIXME: Deal with Multicast addressing and if the socket is connected.
+ jbyteArray raddr;
+ jint rport;
+ if (u.address.sin_family == AF_INET)
+ {
+ raddr = JvNewByteArray (4);
+ memcpy (elements (raddr), &u.address.sin_addr, 4);
+ rport = ntohs (u.address.sin_port);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ raddr = JvNewByteArray (16);
+ memcpy (elements (raddr), &u.address6.sin6_addr, 16);
+ rport = ntohs (u.address6.sin6_port);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
+
+ p->setAddress (new InetAddress (raddr, NULL));
+ p->setPort (rport);
+ p->setLength ((jint) retlen);
+ return rport;
+
+error:
+ DWORD dwErrorCode = WSAGetLastError ();
+ if (dwErrorCode == WSAECONNRESET)
+ throw new ::java::net::PortUnreachableException (_Jv_WinStrError (dwErrorCode));
+ else if (dwErrorCode == WSAETIMEDOUT)
+ throw new ::java::net::SocketTimeoutException (_Jv_WinStrError (dwErrorCode));
+ else
+ _Jv_ThrowIOException ();
+
+ return -1;
+ // we should never get here
+}
+
+// Close(shutdown) the socket.
+void
+gnu::java::net::PlainDatagramSocketImpl::close ()
+{
+ // Avoid races from asynchronous finalization.
+ JvSynchronize sync (this);
+
+ // The method isn't declared to throw anything, so we disregard
+ // the return value.
+ ::closesocket (fnum);
+ fnum = -1;
+ timeout = 0;
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::send (::java::net::DatagramPacket *p)
+{
+ // FIXME: Deal with Multicast and if the socket is connected.
+ jint rport = p->getPort();
+ union SockAddr u;
+ jbyteArray haddress = p->getAddress()->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+ struct sockaddr *ptr = (struct sockaddr *) &u.address;
+ jbyte *dbytes = elements (p->getData());
+ if (len == 4)
+ {
+ u.address.sin_family = AF_INET;
+ memcpy (&u.address.sin_addr, bytes, len);
+ len = sizeof (struct sockaddr_in);
+ u.address.sin_port = htons (rport);
+ }
+#ifdef HAVE_INET6
+ else if (len == 16)
+ {
+ u.address6.sin6_family = AF_INET6;
+ memcpy (&u.address6.sin6_addr, bytes, len);
+ len = sizeof (struct sockaddr_in6);
+ u.address6.sin6_port = htons (rport);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (::sendto (fnum, (char *) dbytes, p->getLength(), 0, ptr, len) >= 0)
+ return;
+
+ DWORD dwErrorCode = WSAGetLastError ();
+ if (dwErrorCode == WSAECONNRESET)
+ throw new ::java::net::PortUnreachableException (_Jv_WinStrError (dwErrorCode));
+
+ _Jv_ThrowIOException ();
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::receive (::java::net::DatagramPacket *p)
+{
+ // FIXME: Deal with Multicast and if the socket is connected.
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ jbyte *dbytes = elements (p->getData());
+ ssize_t retlen = 0;
+
+ if (timeout > 0)
+ {
+ // This implementation doesn't allow specifying an infinite
+ // timeout after specifying a finite one, but Sun's JDK 1.4.1
+ // didn't seem to allow this either....
+ int nRet= ::setsockopt(fnum, SOL_SOCKET, SO_RCVTIMEO,
+ (char*)&timeout, sizeof(timeout));
+ if (nRet != NO_ERROR)
+ goto error;
+ }
+
+ retlen =
+ ::recvfrom (fnum, (char *) dbytes, p->getLength(), 0, (sockaddr*) &u,
+ &addrlen);
+ if (retlen < 0)
+ goto error;
+ // FIXME: Deal with Multicast addressing and if the socket is connected.
+ jbyteArray raddr;
+ jint rport;
+ if (u.address.sin_family == AF_INET)
+ {
+ raddr = JvNewByteArray (4);
+ memcpy (elements (raddr), &u.address.sin_addr, 4);
+ rport = ntohs (u.address.sin_port);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ raddr = JvNewByteArray (16);
+ memcpy (elements (raddr), &u.address6.sin6_addr, 16);
+ rport = ntohs (u.address6.sin6_port);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
+
+ p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+ p->setPort (rport);
+ p->setLength ((jint) retlen);
+ return;
+
+ error:
+ DWORD dwErrorCode = WSAGetLastError();
+ if (dwErrorCode == WSAECONNRESET)
+ throw new ::java::net::PortUnreachableException (_Jv_WinStrError (dwErrorCode));
+ else if (dwErrorCode == WSAETIMEDOUT)
+ throw new ::java::net::SocketTimeoutException (_Jv_WinStrError (dwErrorCode));
+ else
+ throw new ::java::io::IOException (_Jv_WinStrError (dwErrorCode));
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::setTimeToLive (jint ttl)
+{
+ // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
+ char val = (char) ttl;
+ socklen_t val_len = sizeof(val);
+
+ if (::setsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, val_len) == 0)
+ return;
+
+ _Jv_ThrowIOException ();
+}
+
+jint
+gnu::java::net::PlainDatagramSocketImpl::getTimeToLive ()
+{
+ // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
+ char val;
+ socklen_t val_len = sizeof(val);
+
+ if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, &val_len) == 0)
+ return ((int) val) & 0xFF;
+
+ _Jv_ThrowIOException ();
+
+ return -1;
+ // we should never get here
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::mcastGrp (::java::net::InetAddress *inetaddr,
+ ::java::net::NetworkInterface *,
+ jboolean join)
+{
+ // FIXME: implement use of NetworkInterface
+ jbyteArray haddress = inetaddr->addr;
+ int len = haddress->length;
+ int level, opname;
+ const char *ptr;
+ if (0)
+ ;
+#if HAVE_STRUCT_IP_MREQ
+ else if (len == 4)
+ {
+ level = IPPROTO_IP;
+ opname = join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP;
+ memcpy (&u.mreq.imr_multiaddr, bytes, len);
+ // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
+ // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
+ u.mreq.imr_interface.s_addr = htonl (INADDR_ANY);
+ len = sizeof (struct ip_mreq);
+ ptr = (const char *) &u.mreq;
+ }
+#endif
+#if HAVE_STRUCT_IPV6_MREQ
+ else if (len == 16)
+ {
+ level = IPPROTO_IPV6;
+
+ /* Prefer new RFC 2553 names. */
+#ifndef IPV6_JOIN_GROUP
+#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
+#endif
+#ifndef IPV6_LEAVE_GROUP
+#define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
+#endif
+
+ opname = join ? IPV6_JOIN_GROUP : IPV6_LEAVE_GROUP;
+ memcpy (&u.mreq6.ipv6mr_multiaddr, bytes, len);
+ // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
+ // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
+ u.mreq6.ipv6mr_interface = 0;
+ len = sizeof (struct ipv6_mreq);
+ ptr = (const char *) &u.mreq6;
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (::setsockopt (fnum, level, opname, ptr, len) == 0)
+ return;
+
+ _Jv_ThrowIOException ();
+}
+
+void
+gnu::java::net::PlainDatagramSocketImpl::setOption (jint optID,
+ ::java::lang::Object *value)
+{
+ int val;
+ socklen_t val_len = sizeof (val);
+
+ if (fnum < 0)
+ throw new ::java::net::SocketException (JvNewStringUTF ("Socket closed"));
+
+ if (_Jv_IsInstanceOf (value, &::java::lang::Boolean::class$))
+ {
+ ::java::lang::Boolean *boolobj =
+ static_cast< ::java::lang::Boolean *> (value);
+ val = boolobj->booleanValue() ? 1 : 0;
+ }
+ else if (_Jv_IsInstanceOf (value, &::java::lang::Integer::class$))
+ {
+ ::java::lang::Integer *intobj =
+ static_cast< ::java::lang::Integer *> (value);
+ val = (int) intobj->intValue();
+ }
+ // Else assume value to be an InetAddress for use with IP_MULTICAST_IF.
+
+ switch (optID)
+ {
+ case _Jv_TCP_NODELAY_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("TCP_NODELAY not valid for UDP"));
+ return;
+ case _Jv_SO_LINGER_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_LINGER not valid for UDP"));
+ return;
+ case _Jv_SO_KEEPALIVE_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
+ return;
+
+ case _Jv_SO_BROADCAST_ :
+ if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+ val_len) != 0)
+ goto error;
+ break;
+
+ case _Jv_SO_OOBINLINE_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_OOBINLINE: not valid for UDP"));
+ break;
+
+ case _Jv_SO_SNDBUF_ :
+ case _Jv_SO_RCVBUF_ :
+ int opt;
+ optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
+ if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
+ goto error;
+ return;
+ case _Jv_SO_REUSEADDR_ :
+ if (::setsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
+ val_len) != 0)
+ goto error;
+ return;
+ case _Jv_SO_BINDADDR_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_BINDADDR: read only option"));
+ return;
+ case _Jv_IP_MULTICAST_IF_ :
+ union InAddr u;
+ jbyteArray haddress;
+ jbyte *bytes;
+ int len;
+ int level, opname;
+ const char *ptr;
+
+ haddress = ((::java::net::InetAddress *) value)->addr;
+ bytes = elements (haddress);
+ len = haddress->length;
+ if (len == 4)
+ {
+ level = IPPROTO_IP;
+ opname = IP_MULTICAST_IF;
+ memcpy (&u.addr, bytes, len);
+ len = sizeof (struct in_addr);
+ ptr = (const char *) &u.addr;
+ }
+// Tru64 UNIX V5.0 has struct sockaddr_in6, but no IPV6_MULTICAST_IF
+#if defined (HAVE_INET6) && defined (IPV6_MULTICAST_IF)
+ else if (len == 16)
+ {
+ level = IPPROTO_IPV6;
+ opname = IPV6_MULTICAST_IF;
+ memcpy (&u.addr6, bytes, len);
+ len = sizeof (struct in6_addr);
+ ptr = (const char *) &u.addr6;
+ }
+#endif
+ else
+ throw
+ new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (::setsockopt (fnum, level, opname, ptr, len) != 0)
+ goto error;
+ return;
+
+ case _Jv_IP_MULTICAST_IF2_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
+ break;
+
+ case _Jv_IP_MULTICAST_LOOP_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_LOOP: not yet implemented"));
+ break;
+
+ case _Jv_IP_TOS_ :
+ if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+ val_len) != 0)
+ goto error;
+ return;
+
+ case _Jv_SO_TIMEOUT_ :
+ timeout = val;
+ return;
+ default :
+ WSASetLastError (WSAENOPROTOOPT);
+ }
+
+ error:
+ _Jv_ThrowSocketException ();
+}
+
+::java::lang::Object *
+gnu::java::net::PlainDatagramSocketImpl::getOption (jint optID)
+{
+ int val;
+ socklen_t val_len = sizeof(val);
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+
+ switch (optID)
+ {
+ case _Jv_TCP_NODELAY_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("TCP_NODELAY not valid for UDP"));
+ break;
+ case _Jv_SO_LINGER_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_LINGER not valid for UDP"));
+ break;
+ case _Jv_SO_KEEPALIVE_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
+ break;
+
+ case _Jv_SO_BROADCAST_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Boolean (val != 0);
+
+ case _Jv_SO_OOBINLINE_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_OOBINLINE not valid for UDP"));
+ break;
+
+ case _Jv_SO_RCVBUF_ :
+ case _Jv_SO_SNDBUF_ :
+ int opt;
+ optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
+ if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
+ goto error;
+ else
+ return new ::java::lang::Integer (val);
+ break;
+ case _Jv_SO_BINDADDR_:
+ // cache the local address
+ if (localAddress == NULL)
+ {
+ jbyteArray laddr;
+ if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
+ goto error;
+ if (u.address.sin_family == AF_INET)
+ {
+ laddr = JvNewByteArray (4);
+ memcpy (elements (laddr), &u.address.sin_addr, 4);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ laddr = JvNewByteArray (16);
+ memcpy (elements (laddr), &u.address6.sin6_addr, 16);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("invalid family"));
+ localAddress = new ::java::net::InetAddress (laddr, NULL);
+ }
+ return localAddress;
+ break;
+ case _Jv_SO_REUSEADDR_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Boolean (val != 0);
+ break;
+ case _Jv_IP_MULTICAST_IF_ :
+ struct in_addr inaddr;
+ socklen_t inaddr_len;
+ char *bytes;
+
+ inaddr_len = sizeof(inaddr);
+ if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_IF, (char *) &inaddr,
+ &inaddr_len) != 0)
+ goto error;
+
+ bytes = inet_ntoa (inaddr);
+
+ return ::java::net::InetAddress::getByName (JvNewStringLatin1 (bytes));
+ break;
+ case _Jv_SO_TIMEOUT_ :
+ return new ::java::lang::Integer (timeout);
+ break;
+
+ case _Jv_IP_MULTICAST_IF2_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
+ break;
+
+ case _Jv_IP_MULTICAST_LOOP_ :
+ if (::getsockopt (fnum, SOL_SOCKET, IP_MULTICAST_LOOP, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Boolean (val != 0);
+
+ case _Jv_IP_TOS_ :
+ if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Integer (val);
+
+ default :
+ WSASetLastError (WSAENOPROTOOPT);
+ }
+
+error:
+ _Jv_ThrowSocketException ();
+ return 0;
+ // we should never get here
+}
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+
+#include <gnu/java/net/PlainSocketImpl.h>
+#include <java/io/IOException.h>
+#include <java/net/BindException.h>
+#include <java/net/ConnectException.h>
+#include <java/net/SocketException.h>
+
+void
+gnu::java::net::PlainSocketImpl::create (jboolean)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("SocketImpl.create: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::bind (::java::net::InetAddress *, jint)
+{
+ throw new ::java::net::BindException (
+ JvNewStringLatin1 ("SocketImpl.bind: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::connect (::java::net::SocketAddress *, jint)
+{
+ throw new ::java::net::ConnectException (
+ JvNewStringLatin1 ("SocketImpl.connect: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::listen (jint)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("SocketImpl.listen: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::accept (gnu::java::net::PlainSocketImpl *)
+{
+ throw new ::java::io::IOException (
+ JvNewStringLatin1 ("SocketImpl.accept: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::setOption (jint, ::java::lang::Object *)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.setOption: unimplemented"));
+}
+
+::java::lang::Object *
+gnu::java::net::PlainSocketImpl::getOption (jint)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.getOption: unimplemented"));
+}
+
+jint
+gnu::java::net::PlainSocketImpl::read(void)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.read: unimplemented"));
+}
+
+jint
+gnu::java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.read: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::write(jint b)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::sendUrgentData(jint data)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.sendUrgentData: unimplemented"));
+}
+
+jint
+gnu::java::net::PlainSocketImpl::available(void)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.available: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::close(void)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.close: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::shutdownInput (void)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.shutdownInput: unimplemented"));
+}
+
+void
+gnu::java::net::PlainSocketImpl::shutdownOutput (void)
+{
+ throw new ::java::net::SocketException (
+ JvNewStringLatin1 ("SocketImpl.shutdownOutput: unimplemented"));
+}
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+
+#ifdef HAVE_SYS_IOCTL_H
+#define BSD_COMP /* Get FIONREAD on Solaris2. */
+#include <sys/ioctl.h>
+#endif
+
+// Pick up FIONREAD on Solaris 2.5.
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <errno.h>
+#include <string.h>
+
+#if HAVE_BSTRING_H
+// Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
+#include <bstring.h>
+#endif
+
+#include <gcj/cni.h>
+#include <gcj/javaprims.h>
+#include <gnu/java/net/PlainSocketImpl.h>
+#include <java/io/IOException.h>
+#include <java/io/InterruptedIOException.h>
+#include <java/net/BindException.h>
+#include <java/net/ConnectException.h>
+#include <java/net/InetAddress.h>
+#include <java/net/InetSocketAddress.h>
+#include <java/net/SocketException.h>
+#include <java/net/SocketTimeoutException.h>
+#include <java/lang/InternalError.h>
+#include <java/lang/Object.h>
+#include <java/lang/Boolean.h>
+#include <java/lang/Class.h>
+#include <java/lang/Integer.h>
+#include <java/lang/Thread.h>
+#include <java/lang/NullPointerException.h>
+#include <java/lang/ArrayIndexOutOfBoundsException.h>
+#include <java/lang/IllegalArgumentException.h>
+
+union SockAddr
+{
+ struct sockaddr_in address;
+#ifdef HAVE_INET6
+ struct sockaddr_in6 address6;
+#endif
+};
+
+void
+gnu::java::net::PlainSocketImpl::create (jboolean stream)
+{
+ int sock = _Jv_socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
+
+ if (sock < 0)
+ {
+ char* strerr = strerror (errno);
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+ }
+
+ _Jv_platform_close_on_exec (sock);
+
+ // We use fnum in place of fd here. From leaving fd null we avoid
+ // the double close problem in FileDescriptor.finalize.
+ fnum = sock;
+}
+
+void
+gnu::java::net::PlainSocketImpl::bind (::java::net::InetAddress *host, jint lport)
+{
+ union SockAddr u;
+ struct sockaddr *ptr = (struct sockaddr *) &u.address;
+ jbyteArray haddress = host->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+ int i = 1;
+
+ if (len == 4)
+ {
+ u.address.sin_family = AF_INET;
+
+ if (host != NULL)
+ memcpy (&u.address.sin_addr, bytes, len);
+ else
+ u.address.sin_addr.s_addr = htonl (INADDR_ANY);
+
+ len = sizeof (struct sockaddr_in);
+ u.address.sin_port = htons (lport);
+ }
+#ifdef HAVE_INET6
+ else if (len == 16)
+ {
+ u.address6.sin6_family = AF_INET6;
+ memcpy (&u.address6.sin6_addr, bytes, len);
+ len = sizeof (struct sockaddr_in6);
+ u.address6.sin6_port = htons (lport);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ // Enable SO_REUSEADDR, so that servers can reuse ports left in TIME_WAIT.
+ ::setsockopt(fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof(i));
+
+ if (_Jv_bind (fnum, ptr, len) == 0)
+ {
+ address = host;
+ socklen_t addrlen = sizeof(u);
+
+ if (lport != 0)
+ localport = lport;
+ else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
+ localport = ntohs (u.address.sin_port);
+ else
+ goto error;
+
+ return;
+ }
+
+ error:
+ char* strerr = strerror (errno);
+ throw new ::java::net::BindException (JvNewStringUTF (strerr));
+}
+
+void
+gnu::java::net::PlainSocketImpl::connect (::java::net::SocketAddress *addr,
+ jint timeout)
+{
+ ::java::net::InetSocketAddress *tmp = (::java::net::InetSocketAddress*) addr;
+ ::java::net::InetAddress *host = tmp->getAddress();
+ jint rport = tmp->getPort();
+
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ jbyteArray haddress = host->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+ struct sockaddr *ptr = (struct sockaddr *) &u.address;
+ if (len == 4)
+ {
+ u.address.sin_family = AF_INET;
+ memcpy (&u.address.sin_addr, bytes, len);
+ len = sizeof (struct sockaddr_in);
+ u.address.sin_port = htons (rport);
+ }
+#ifdef HAVE_INET6
+ else if (len == 16)
+ {
+ u.address6.sin6_family = AF_INET6;
+ memcpy (&u.address6.sin6_addr, bytes, len);
+ len = sizeof (struct sockaddr_in6);
+ u.address6.sin6_port = htons (rport);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (timeout > 0)
+ {
+ int flags = ::fcntl (fnum, F_GETFL);
+ ::fcntl (fnum, F_SETFL, flags | O_NONBLOCK);
+
+ if ((_Jv_connect (fnum, ptr, len) != 0) && (errno != EINPROGRESS))
+ goto error;
+
+ fd_set fset;
+ struct timeval tv;
+ FD_ZERO(&fset);
+ FD_SET(fnum, &fset);
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ int retval;
+
+ if ((retval = _Jv_select (fnum + 1, &fset, &fset, NULL, &tv)) < 0)
+ goto error;
+ else if (retval == 0)
+ throw new ::java::net::SocketTimeoutException
+ (JvNewStringUTF ("Connect timed out"));
+ // Set the socket back into a blocking state.
+ ::fcntl (fnum, F_SETFL, flags);
+ }
+ else
+ {
+ if (_Jv_connect (fnum, ptr, len) != 0)
+ goto error;
+ }
+
+ address = host;
+ port = rport;
+
+ // A bind may not have been done on this socket; if so, set localport now.
+ if (localport == 0)
+ {
+ if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
+ localport = ntohs (u.address.sin_port);
+ else
+ goto error;
+ }
+
+ return;
+
+ error:
+ char* strerr = strerror (errno);
+ throw new ::java::net::ConnectException (JvNewStringUTF (strerr));
+}
+
+void
+gnu::java::net::PlainSocketImpl::listen (jint backlog)
+{
+ if (::listen (fnum, backlog) != 0)
+ {
+ char* strerr = strerror (errno);
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+ }
+}
+
+void
+gnu::java::net::PlainSocketImpl::accept (gnu::java::net::PlainSocketImpl *s)
+{
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ int new_socket = 0;
+
+ // Do timeouts via select since SO_RCVTIMEO is not always available.
+ if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
+ {
+ fd_set fset;
+ struct timeval tv;
+ FD_ZERO(&fset);
+ FD_SET(fnum, &fset);
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ int retval;
+ if ((retval = _Jv_select (fnum + 1, &fset, &fset, NULL, &tv)) < 0)
+ goto error;
+ else if (retval == 0)
+ throw new ::java::net::SocketTimeoutException (
+ JvNewStringUTF("Accept timed out"));
+ }
+
+ new_socket = _Jv_accept (fnum, (sockaddr*) &u, &addrlen);
+
+ if (new_socket < 0)
+ goto error;
+
+ _Jv_platform_close_on_exec (new_socket);
+
+ jbyteArray raddr;
+ jint rport;
+ if (u.address.sin_family == AF_INET)
+ {
+ raddr = JvNewByteArray (4);
+ memcpy (elements (raddr), &u.address.sin_addr, 4);
+ rport = ntohs (u.address.sin_port);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ raddr = JvNewByteArray (16);
+ memcpy (elements (raddr), &u.address6.sin6_addr, 16);
+ rport = ntohs (u.address6.sin6_port);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
+
+ s->fnum = new_socket;
+ s->localport = localport;
+ s->address = new ::java::net::InetAddress (raddr, NULL);
+ s->port = rport;
+ return;
+
+ error:
+ char* strerr = strerror (errno);
+ throw new ::java::io::IOException (JvNewStringUTF (strerr));
+}
+
+// Close(shutdown) the socket.
+void
+gnu::java::net::PlainSocketImpl::close()
+{
+ // Avoid races from asynchronous finalization.
+ JvSynchronize sync (this);
+
+ // should we use shutdown here? how would that effect so_linger?
+ int res = _Jv_close (fnum);
+
+ if (res == -1)
+ {
+ // These three errors are not errors according to tests performed
+ // on the reference implementation.
+ if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
+ throw new ::java::io::IOException (JvNewStringUTF (strerror (errno)));
+ }
+ // Safe place to reset the file pointer.
+ fnum = -1;
+ timeout = 0;
+}
+
+// Write a byte to the socket.
+void
+gnu::java::net::PlainSocketImpl::write(jint b)
+{
+ jbyte d =(jbyte) b;
+ int r = 0;
+
+ while (r != 1)
+ {
+ r = _Jv_write (fnum, &d, 1);
+ if (r == -1)
+ {
+ if (::java::lang::Thread::interrupted())
+ {
+ ::java::io::InterruptedIOException *iioe
+ = new ::java::io::InterruptedIOException
+ (JvNewStringLatin1 (strerror (errno)));
+ iioe->bytesTransferred = 0;
+ throw iioe;
+ }
+ // Some errors should not cause exceptions.
+ if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
+ throw new ::java::io::IOException (JvNewStringUTF (strerror (errno)));
+ break;
+ }
+ }
+}
+
+// Write some bytes to the socket.
+void
+gnu::java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
+{
+ if (! b)
+ throw new ::java::lang::NullPointerException;
+ if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
+ throw new ::java::lang::ArrayIndexOutOfBoundsException;
+
+ jbyte *bytes = elements (b) + offset;
+ int written = 0;
+
+ while (len > 0)
+ {
+ int r = _Jv_write (fnum, bytes, len);
+
+ if (r == -1)
+ {
+ if (::java::lang::Thread::interrupted())
+ {
+ ::java::io::InterruptedIOException *iioe
+ = new ::java::io::InterruptedIOException
+ (JvNewStringLatin1 (strerror (errno)));
+ iioe->bytesTransferred = written;
+ throw iioe;
+ }
+ // Some errors should not cause exceptions.
+ if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
+ throw new ::java::io::IOException (JvNewStringUTF (strerror (errno)));
+ break;
+ }
+
+ written += r;
+ len -= r;
+ bytes += r;
+ }
+}
+
+void
+gnu::java::net::PlainSocketImpl::sendUrgentData (jint)
+{
+ throw new ::java::net::SocketException (JvNewStringLatin1 (
+ "PlainSocketImpl: sending of urgent data not supported by this socket"));
+}
+
+// Read a single byte from the socket.
+jint
+gnu::java::net::PlainSocketImpl::read(void)
+{
+ jbyte b;
+
+ // Do timeouts via select.
+ if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
+ {
+ // Create the file descriptor set.
+ fd_set read_fds;
+ FD_ZERO (&read_fds);
+ FD_SET (fnum,&read_fds);
+ // Create the timeout struct based on our internal timeout value.
+ struct timeval timeout_value;
+ timeout_value.tv_sec = timeout / 1000;
+ timeout_value.tv_usec = (timeout % 1000) * 1000;
+ // Select on the fds.
+ int sel_retval =
+ _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
+ // If select returns 0 we've waited without getting data...
+ // that means we've timed out.
+ if (sel_retval == 0)
+ throw new ::java::net::SocketTimeoutException
+ (JvNewStringUTF ("read timed out") );
+ // If select returns ok we know we either got signalled or read some data...
+ // either way we need to try to read.
+ }
+
+ int r = _Jv_read (fnum, &b, 1);
+
+ if (r == 0)
+ return -1;
+
+ if (::java::lang::Thread::interrupted())
+ {
+ ::java::io::InterruptedIOException *iioe =
+ new ::java::io::InterruptedIOException
+ (JvNewStringUTF("read interrupted"));
+ iioe->bytesTransferred = r == -1 ? 0 : r;
+ throw iioe;
+ }
+ else if (r == -1)
+ {
+ // Some errors cause us to return end of stream...
+ if (errno == ENOTCONN)
+ return -1;
+
+ // Other errors need to be signalled.
+ throw new ::java::io::IOException (JvNewStringUTF (strerror (errno)));
+ }
+
+ return b & 0xFF;
+}
+
+// Read count bytes into the buffer, starting at offset.
+jint
+gnu::java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
+{
+ if (! buffer)
+ throw new ::java::lang::NullPointerException;
+
+ jsize bsize = JvGetArrayLength (buffer);
+
+ if (offset < 0 || count < 0 || offset + count > bsize)
+ throw new ::java::lang::ArrayIndexOutOfBoundsException;
+
+ jbyte *bytes = elements (buffer) + offset;
+
+ // Do timeouts via select.
+ if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
+ {
+ // Create the file descriptor set.
+ fd_set read_fds;
+ FD_ZERO (&read_fds);
+ FD_SET (fnum, &read_fds);
+ // Create the timeout struct based on our internal timeout value.
+ struct timeval timeout_value;
+ timeout_value.tv_sec = timeout / 1000;
+ timeout_value.tv_usec =(timeout % 1000) * 1000;
+ // Select on the fds.
+ int sel_retval =
+ _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
+ // We're only interested in the 0 return.
+ // error returns still require us to try to read
+ // the socket to see what happened.
+ if (sel_retval == 0)
+ {
+ ::java::net::SocketTimeoutException *timeoutException =
+ new ::java::net::SocketTimeoutException
+ (JvNewStringUTF ("read timed out"));
+ throw timeoutException;
+ }
+ }
+
+ // Read the socket.
+ int r = ::recv (fnum, (char *) bytes, count, 0);
+
+ if (r == 0)
+ return -1;
+
+ if (::java::lang::Thread::interrupted())
+ {
+ ::java::io::InterruptedIOException *iioe =
+ new ::java::io::InterruptedIOException
+ (JvNewStringUTF ("read interrupted"));
+ iioe->bytesTransferred = r == -1 ? 0 : r;
+ throw iioe;
+ }
+ else if (r == -1)
+ {
+ // Some errors cause us to return end of stream...
+ if (errno == ENOTCONN)
+ return -1;
+
+ // Other errors need to be signalled.
+ throw new ::java::io::IOException (JvNewStringUTF (strerror (errno)));
+ }
+
+ return r;
+}
+
+// How many bytes are available?
+jint
+gnu::java::net::PlainSocketImpl::available(void)
+{
+#if defined(FIONREAD) || defined(HAVE_SELECT)
+ long num = 0;
+ int r = 0;
+ bool num_set = false;
+
+#if defined(FIONREAD)
+ r = ::ioctl (fnum, FIONREAD, &num);
+
+ if (r == -1 && errno == ENOTTY)
+ {
+ // If the ioctl doesn't work, we don't care.
+ r = 0;
+ num = 0;
+ }
+ else
+ num_set = true;
+#elif defined(HAVE_SELECT)
+ if (fnum < 0)
+ {
+ errno = EBADF;
+ r = -1;
+ }
+#endif
+
+ if (r == -1)
+ {
+ posix_error:
+ throw new ::java::io::IOException(JvNewStringUTF(strerror(errno)));
+ }
+
+ // If we didn't get anything we can use select.
+
+#if defined(HAVE_SELECT)
+ if (! num_set)
+ if (! num_set && fnum >= 0 && fnum < FD_SETSIZE)
+ {
+ fd_set rd;
+ FD_ZERO (&rd);
+ FD_SET (fnum, &rd);
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ r = _Jv_select (fnum + 1, &rd, NULL, NULL, &tv);
+ if(r == -1)
+ goto posix_error;
+ num = r == 0 ? 0 : 1;
+ }
+#endif /* HAVE_SELECT */
+
+ return (jint) num;
+#else
+ throw new ::java::io::IOException (JvNewStringUTF ("unimplemented"));
+#endif
+}
+
+void
+gnu::java::net::PlainSocketImpl::setOption (jint optID, ::java::lang::Object *value)
+{
+ int val;
+ socklen_t val_len = sizeof (val);
+
+ if (fnum < 0)
+ throw new ::java::net::SocketException (JvNewStringUTF ("Socket closed"));
+
+ if (_Jv_IsInstanceOf (value, &::java::lang::Boolean::class$))
+ {
+ ::java::lang::Boolean *boolobj =
+ static_cast< ::java::lang::Boolean *> (value);
+ if (boolobj->booleanValue())
+ val = 1;
+ else
+ {
+ if (optID == _Jv_SO_LINGER_)
+ val = -1;
+ else
+ val = 0;
+ }
+ }
+ else if (_Jv_IsInstanceOf (value, &::java::lang::Integer::class$))
+ {
+ ::java::lang::Integer *intobj =
+ static_cast< ::java::lang::Integer *> (value);
+ val = (int) intobj->intValue();
+ }
+ else
+ {
+ throw new ::java::lang::IllegalArgumentException (
+ JvNewStringLatin1 ("`value' must be Boolean or Integer"));
+ }
+
+ switch (optID)
+ {
+ case _Jv_TCP_NODELAY_ :
+#ifdef TCP_NODELAY
+ if (::setsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
+ val_len) != 0)
+ goto error;
+#else
+ throw new ::java::lang::InternalError
+ (JvNewStringUTF ("TCP_NODELAY not supported"));
+#endif /* TCP_NODELAY */
+ return;
+
+ case _Jv_SO_KEEPALIVE_ :
+ if (::setsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
+ val_len) != 0)
+ goto error;
+ break;
+
+ case _Jv_SO_BROADCAST_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
+ break;
+
+ case _Jv_SO_OOBINLINE_ :
+ if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
+ val_len) != 0)
+ goto error;
+ break;
+
+ case _Jv_SO_LINGER_ :
+#ifdef SO_LINGER
+ struct linger l_val;
+ l_val.l_onoff = (val != -1);
+ l_val.l_linger = val;
+
+ if (::setsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
+ sizeof(l_val)) != 0)
+ goto error;
+#else
+ throw new ::java::lang::InternalError (
+ JvNewStringUTF ("SO_LINGER not supported"));
+#endif /* SO_LINGER */
+ return;
+
+ case _Jv_SO_SNDBUF_ :
+ case _Jv_SO_RCVBUF_ :
+#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
+ int opt;
+ optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
+ if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
+ goto error;
+#else
+ throw new ::java::lang::InternalError (
+ JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
+#endif
+ return;
+
+ case _Jv_SO_BINDADDR_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_BINDADDR: read only option"));
+ return;
+
+ case _Jv_IP_MULTICAST_IF_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
+ return;
+
+ case _Jv_IP_MULTICAST_IF2_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
+ break;
+
+ case _Jv_IP_MULTICAST_LOOP_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
+ break;
+
+ case _Jv_IP_TOS_ :
+ if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+ val_len) != 0)
+ goto error;
+ break;
+
+ case _Jv_SO_REUSEADDR_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
+ return;
+
+ case _Jv_SO_TIMEOUT_ :
+ timeout = val;
+ return;
+
+ default :
+ errno = ENOPROTOOPT;
+ }
+
+ error:
+ char* strerr = strerror (errno);
+ throw new ::java::net::SocketException (JvNewStringUTF (strerr));
+}
+
+::java::lang::Object *
+gnu::java::net::PlainSocketImpl::getOption (jint optID)
+{
+ int val;
+ socklen_t val_len = sizeof(val);
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ struct linger l_val;
+ socklen_t l_val_len = sizeof(l_val);
+
+ switch (optID)
+ {
+#ifdef TCP_NODELAY
+ case _Jv_TCP_NODELAY_ :
+ if (::getsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ else
+ return new ::java::lang::Boolean (val != 0);
+#else
+ throw new ::java::lang::InternalError
+ (JvNewStringUTF ("TCP_NODELAY not supported"));
+#endif
+ break;
+
+ case _Jv_SO_LINGER_ :
+#ifdef SO_LINGER
+ if (::getsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
+ &l_val_len) != 0)
+ goto error;
+
+ if (l_val.l_onoff)
+ return new ::java::lang::Integer (l_val.l_linger);
+ else
+ return new ::java::lang::Boolean ((jboolean)false);
+#else
+ throw new ::java::lang::InternalError
+ (JvNewStringUTF ("SO_LINGER not supported"));
+#endif
+ break;
+
+ case _Jv_SO_KEEPALIVE_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ else
+ return new ::java::lang::Boolean (val != 0);
+
+ case _Jv_SO_BROADCAST_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Boolean ((jboolean)val);
+
+ case _Jv_SO_OOBINLINE_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Boolean ((jboolean)val);
+
+ case _Jv_SO_RCVBUF_ :
+ case _Jv_SO_SNDBUF_ :
+#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
+ int opt;
+ optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
+ if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
+ goto error;
+ else
+ return new ::java::lang::Integer (val);
+#else
+ throw new ::java::lang::InternalError
+ (JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
+#endif
+ break;
+ case _Jv_SO_BINDADDR_:
+ // cache the local address
+ if (localAddress == NULL)
+ {
+ jbyteArray laddr;
+
+ if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
+ goto error;
+
+ if (u.address.sin_family == AF_INET)
+ {
+ laddr = JvNewByteArray (4);
+ memcpy (elements (laddr), &u.address.sin_addr, 4);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ laddr = JvNewByteArray (16);
+ memcpy (elements (laddr), &u.address6.sin6_addr, 16);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("invalid family"));
+ localAddress = new ::java::net::InetAddress (laddr, NULL);
+ }
+
+ return localAddress;
+ break;
+ case _Jv_IP_MULTICAST_IF_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
+ break;
+
+ case _Jv_IP_MULTICAST_IF2_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
+ break;
+
+ case _Jv_IP_MULTICAST_LOOP_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
+ break;
+
+ case _Jv_IP_TOS_ :
+ if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+ &val_len) != 0)
+ goto error;
+ return new ::java::lang::Integer (val);
+ break;
+
+ case _Jv_SO_REUSEADDR_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
+ break;
+
+ case _Jv_SO_TIMEOUT_ :
+ return new ::java::lang::Integer (timeout);
+ break;
+
+ default :
+ errno = ENOPROTOOPT;
+ }
+
+ error:
+ char* strerr = strerror (errno);
+ throw new ::java::net::SocketException (JvNewStringUTF (strerr));
+}
+
+void
+gnu::java::net::PlainSocketImpl::shutdownInput (void)
+{
+ if (::shutdown (fnum, 0))
+ throw new ::java::net::SocketException (JvNewStringUTF (strerror (errno)));
+}
+
+void
+gnu::java::net::PlainSocketImpl::shutdownOutput (void)
+{
+ if (::shutdown (fnum, 1))
+ throw new ::java::net::SocketException (JvNewStringUTF (strerror (errno)));
+}
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+
+#undef STRICT
+#undef MAX_PRIORITY
+#undef MIN_PRIORITY
+
+#include <gnu/java/net/PlainSocketImpl.h>
+#include <java/io/IOException.h>
+#include <java/io/InterruptedIOException.h>
+#include <java/net/BindException.h>
+#include <java/net/ConnectException.h>
+#include <java/net/InetAddress.h>
+#include <java/net/InetSocketAddress.h>
+#include <java/net/SocketException.h>
+#include <java/net/SocketTimeoutException.h>
+#include <java/lang/InternalError.h>
+#include <java/lang/Object.h>
+#include <java/lang/Boolean.h>
+#include <java/lang/Class.h>
+#include <java/lang/Integer.h>
+#include <java/lang/Thread.h>
+#include <java/lang/NullPointerException.h>
+#include <java/lang/ArrayIndexOutOfBoundsException.h>
+#include <java/lang/IllegalArgumentException.h>
+
+union SockAddr
+{
+ struct sockaddr_in address;
+#ifdef HAVE_INET6
+ struct sockaddr_in6 address6;
+#endif
+};
+
+void
+gnu::java::net::PlainSocketImpl::create (jboolean stream)
+{
+ int sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
+
+ if (sock == int(INVALID_SOCKET))
+ {
+ _Jv_ThrowIOException ();
+ }
+
+ _Jv_platform_close_on_exec (sock);
+
+ // We use fnum in place of fd here. From leaving fd null we avoid
+ // the double close problem in FileDescriptor.finalize.
+ fnum = sock;
+}
+
+void
+gnu::java::net::PlainSocketImpl::bind (::java::net::InetAddress *host, jint lport)
+{
+ union SockAddr u;
+ struct sockaddr *ptr = (struct sockaddr *) &u.address;
+ jbyteArray haddress = host->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+ int i = 1;
+
+ if (len == 4)
+ {
+ u.address.sin_family = AF_INET;
+
+ if (host != NULL)
+ memcpy (&u.address.sin_addr, bytes, len);
+ else
+ u.address.sin_addr.s_addr = htonl (INADDR_ANY);
+
+ len = sizeof (struct sockaddr_in);
+ u.address.sin_port = htons (lport);
+ }
+#ifdef HAVE_INET6
+ else if (len == 16)
+ {
+ u.address6.sin6_family = AF_INET6;
+ memcpy (&u.address6.sin6_addr, bytes, len);
+ len = sizeof (struct sockaddr_in6);
+ u.address6.sin6_port = htons (lport);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ // Enable SO_REUSEADDR, so that servers can reuse ports left in TIME_WAIT.
+ ::setsockopt(fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof(i));
+
+ if (::bind (fnum, ptr, len) != SOCKET_ERROR)
+ {
+ address = host;
+ socklen_t addrlen = sizeof(u);
+
+ if (lport != 0)
+ localport = lport;
+ else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != SOCKET_ERROR)
+ localport = ntohs (u.address.sin_port);
+ else
+ goto error;
+
+ return;
+ }
+
+error:
+ DWORD dwErrorCode = WSAGetLastError ();
+ throw new ::java::net::BindException (_Jv_WinStrError (dwErrorCode));
+}
+
+static void
+throwConnectException (DWORD dwErrorCode)
+{
+ throw new ::java::net::ConnectException (_Jv_WinStrError (dwErrorCode));
+}
+
+static void
+throwConnectException ()
+{
+ throwConnectException (WSAGetLastError ());
+}
+
+void
+gnu::java::net::PlainSocketImpl::connect (::java::net::SocketAddress *addr,
+ jint timeout)
+{
+ ::java::net::InetSocketAddress *tmp = (::java::net::InetSocketAddress*) addr;
+ ::java::net::InetAddress *host = tmp->getAddress();
+ jint rport = tmp->getPort();
+
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ jbyteArray haddress = host->addr;
+ jbyte *bytes = elements (haddress);
+ int len = haddress->length;
+ struct sockaddr *ptr = (struct sockaddr *) &u.address;
+
+ if (len == 4)
+ {
+ u.address.sin_family = AF_INET;
+ memcpy (&u.address.sin_addr, bytes, len);
+ len = sizeof (struct sockaddr_in);
+ u.address.sin_port = htons (rport);
+ }
+#ifdef HAVE_INET6
+ else if (len == 16)
+ {
+ u.address6.sin6_family = AF_INET6;
+ memcpy (&u.address6.sin6_addr, bytes, len);
+ len = sizeof (struct sockaddr_in6);
+ u.address6.sin6_port = htons (rport);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
+
+ if (timeout > 0)
+ {
+ // FIXME: we're creating a fresh WSAEVENT for each connect().
+ WSAEventWrapper aWSAEventWrapper(fnum, FD_CONNECT);
+ WSAEVENT hEvent = aWSAEventWrapper.getEventHandle ();
+
+ if (::connect (fnum, ptr, len) == SOCKET_ERROR)
+ {
+ if (WSAGetLastError () != WSAEWOULDBLOCK)
+ throwConnectException ();
+
+ DWORD dwRet =
+ WSAWaitForMultipleEvents (1, &hEvent, true, timeout, false);
+ // use true, false instead of TRUE, FALSE because the
+ // MS constants got undefined
+
+ if (dwRet == WSA_WAIT_FAILED)
+ throwConnectException ();
+
+ else if (dwRet == WSA_WAIT_TIMEOUT)
+ throw new ::java::net::SocketTimeoutException
+ (JvNewStringUTF ("connect timed out"));
+
+ // If we get here, we still need to check whether the actual
+ // connect() succeeded. Use any socket-specific error code
+ // instead of the thread-based one.
+ int nErrCode; int nErrLen=sizeof(nErrCode);
+ if (::getsockopt(fnum, SOL_SOCKET, SO_ERROR, (char*) &nErrCode,
+ &nErrLen) == SOCKET_ERROR)
+ {
+ throwConnectException ();
+ }
+
+ if (nErrCode != NO_ERROR)
+ {
+ throwConnectException (nErrCode);
+ }
+ }
+ }
+ else
+ {
+ if (::connect (fnum, ptr, len) == SOCKET_ERROR)
+ throwConnectException();
+ }
+
+ address = host;
+ port = rport;
+
+ // A bind may not have been done on this socket; if so, set localport now.
+ if (localport == 0)
+ {
+ if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != SOCKET_ERROR)
+ localport = ntohs (u.address.sin_port);
+ else
+ throwConnectException();
+ }
+}
+
+void
+gnu::java::net::PlainSocketImpl::listen (jint backlog)
+{
+ if (::listen (fnum, backlog) == SOCKET_ERROR)
+ {
+ _Jv_ThrowIOException ();
+ }
+}
+
+void
+gnu::java::net::PlainSocketImpl::accept (::java::net::PlainSocketImpl *s)
+{
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ int new_socket = 0;
+
+ if (timeout > 0)
+ {
+ // FIXME: we're creating a fresh WSAEVENT for each accept().
+ // One possible alternative would be that fnum really points
+ // to an extended structure consisting of the SOCKET, its
+ // associated WSAEVENT, etc.
+ WSAEventWrapper aWSAEventWrapper(fnum, FD_ACCEPT);
+ WSAEVENT hEvent = aWSAEventWrapper.getEventHandle ();
+
+ for (;;)
+ {
+ new_socket = ::accept (fnum, (sockaddr*) &u, &addrlen);
+
+ if (new_socket != int(INVALID_SOCKET))
+ {
+ // This new child socket is nonblocking because the parent
+ // socket became nonblocking via the WSAEventSelect() call,
+ // so we set its mode back to blocking.
+ WSAEventSelect (new_socket, hEvent, 0);
+ // undo the hEvent <-> FD_ACCEPT association inherited
+ // inherited from our parent socket
+
+ unsigned long lSockOpt = 0L;
+ // blocking mode
+ if (ioctlsocket(new_socket, FIONBIO, &lSockOpt) == SOCKET_ERROR)
+ {
+ goto error;
+ }
+ break;
+ }
+ else if (WSAGetLastError () != WSAEWOULDBLOCK)
+ {
+ goto error;
+ }
+
+ DWORD dwRet =
+ WSAWaitForMultipleEvents (1, &hEvent, true, timeout, false);
+ // use true, false instead of TRUE, FALSE because the
+ // MS constants got undefined
+
+ if (dwRet == WSA_WAIT_FAILED)
+ goto error;
+ else if (dwRet == WSA_WAIT_TIMEOUT)
+ throw new ::java::net::SocketTimeoutException
+ (JvNewStringUTF ("accept timed out"));
+ }
+ }
+ else
+ {
+ new_socket = ::accept (fnum, (sockaddr*) &u, &addrlen);
+ }
+
+ if (new_socket == int(INVALID_SOCKET))
+ goto error;
+
+ _Jv_platform_close_on_exec (new_socket);
+
+ jbyteArray raddr;
+ jint rport;
+ if (u.address.sin_family == AF_INET)
+ {
+ raddr = JvNewByteArray (4);
+ memcpy (elements (raddr), &u.address.sin_addr, 4);
+ rport = ntohs (u.address.sin_port);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ raddr = JvNewByteArray (16);
+ memcpy (elements (raddr), &u.address6.sin6_addr, 16);
+ rport = ntohs (u.address6.sin6_port);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
+
+ s->fnum = new_socket;
+ s->localport = localport;
+ s->address = new InetAddress (raddr, NULL);
+ s->port = rport;
+ return;
+
+ error:
+ _Jv_ThrowIOException ();
+}
+
+// Close(shutdown) the socket.
+void
+gnu::java::net::PlainSocketImpl::close()
+{
+ // Avoid races from asynchronous finalization.
+ JvSynchronize sync (this);
+
+ // should we use shutdown here? how would that effect so_linger?
+ int res = ::closesocket (fnum);
+
+ if (res == -1)
+ {
+ // These three errors are not errors according to tests performed
+ // on the reference implementation.
+ DWORD dwErr = WSAGetLastError();
+ if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
+ && dwErr != WSAENOTSOCK)
+ _Jv_ThrowIOException ();
+ }
+ // Safe place to reset the file pointer.
+ fnum = -1;
+ timeout = 0;
+}
+
+// Write a byte to the socket.
+void
+gnu::java::net::PlainSocketImpl::write(jint b)
+{
+ jbyte d =(jbyte) b;
+ int r = 0;
+
+ while (r != 1)
+ {
+ r = ::send (fnum, (char*) &d, 1, 0);
+ if (r == -1)
+ {
+ DWORD dwErr = WSAGetLastError();
+ if (::java::lang::Thread::interrupted())
+ {
+ ::java::io::InterruptedIOException *iioe
+ = new ::java::io::InterruptedIOException
+ (_Jv_WinStrError (dwErr));
+ iioe->bytesTransferred = 0;
+ throw iioe;
+ }
+ // Some errors should not cause exceptions.
+ if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
+ && dwErr != WSAENOTSOCK)
+ _Jv_ThrowIOException ();
+ break;
+ }
+ }
+}
+
+// Write some bytes to the socket.
+void
+gnu::java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
+{
+ if (! b)
+ throw new ::java::lang::NullPointerException;
+ if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
+ throw new ::java::lang::ArrayIndexOutOfBoundsException;
+
+ jbyte *bytes = elements (b) + offset;
+ int written = 0;
+ while (len > 0)
+ {
+ int r = ::send (fnum, (char*) bytes, len, 0);
+
+ if (r == -1)
+ {
+ DWORD dwErr = WSAGetLastError();
+ if (::java::lang::Thread::interrupted())
+ {
+ ::java::io::InterruptedIOException *iioe
+ = new ::java::io::InterruptedIOException
+ (_Jv_WinStrError (dwErr));
+ iioe->bytesTransferred = written;
+ throw iioe;
+ }
+ // Some errors should not cause exceptions.
+ if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
+ && dwErr != WSAENOTSOCK)
+ _Jv_ThrowIOException ();
+ break;
+ }
+
+ written += r;
+ len -= r;
+ bytes += r;
+ }
+}
+
+void
+gnu::java::net::PlainSocketImpl::sendUrgentData (jint)
+{
+ throw new ::java::net::SocketException (JvNewStringLatin1 (
+ "PlainSocketImpl: sending of urgent data not supported by this socket"));
+}
+
+// read() helper
+static jint
+doRead(int fnum, void* buf, int count, int timeout)
+{
+ int r = 0;
+ DWORD dwErrorCode = 0;
+ // we are forced to declare this here because
+ // a call to Thread::interrupted() blanks out
+ // WSAGetLastError().
+
+ // FIXME: we unconditionally set SO_RCVTIMEO here
+ // because we can't detect whether someone has
+ // gone from a non-zero to zero timeout. What we'd
+ // really need is a member state variable in addition
+ // to timeout
+ int nRet= ::setsockopt(fnum, SOL_SOCKET, SO_RCVTIMEO,
+ (char*)&timeout, sizeof(timeout));
+ if (nRet != NO_ERROR)
+ {
+ dwErrorCode = WSAGetLastError ();
+ goto error;
+ }
+
+ r = ::recv (fnum, (char*) buf, count, 0);
+
+ if (r == 0)
+ return -1;
+
+ dwErrorCode = WSAGetLastError ();
+ // save WSAGetLastError() before calling Thread.interrupted()
+
+ if (::java::lang::Thread::interrupted())
+ {
+ ::java::io::InterruptedIOException *iioe =
+ new ::java::io::InterruptedIOException
+ (JvNewStringUTF("read interrupted"));
+ iioe->bytesTransferred = r == -1 ? 0 : r;
+ throw iioe;
+ }
+ else if (r == -1)
+ {
+error:
+ // Some errors cause us to return end of stream...
+ if (dwErrorCode == WSAENOTCONN)
+ return -1;
+
+ // Other errors need to be signalled.
+ if (dwErrorCode == WSAETIMEDOUT)
+ throw new ::java::net::SocketTimeoutException
+ (JvNewStringUTF ("read timed out") );
+ else
+ _Jv_ThrowIOException (dwErrorCode);
+ }
+
+ return r;
+}
+
+// Read a single byte from the socket.
+jint
+gnu::java::net::PlainSocketImpl::read(void)
+{
+ jbyte b;
+ doRead(fnum, &b, 1, timeout);
+ return b & 0xFF;
+}
+
+// Read count bytes into the buffer, starting at offset.
+jint
+gnu::java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
+{
+ if (! buffer)
+ throw new ::java::lang::NullPointerException;
+
+ jsize bsize = JvGetArrayLength (buffer);
+
+ if (offset < 0 || count < 0 || offset + count > bsize)
+ throw new ::java::lang::ArrayIndexOutOfBoundsException;
+
+ jbyte *bytes = elements (buffer) + offset;
+
+ // Read the socket.
+ return doRead(fnum, bytes, count, timeout);
+}
+
+// How many bytes are available?
+jint
+gnu::java::net::PlainSocketImpl::available(void)
+{
+ unsigned long num = 0;
+
+ if (::ioctlsocket (fnum, FIONREAD, &num) == SOCKET_ERROR)
+ _Jv_ThrowIOException ();
+
+ return (jint) num;
+}
+
+void
+gnu::java::net::PlainSocketImpl::setOption (jint optID, ::java::lang::Object *value)
+{
+ int val;
+ socklen_t val_len = sizeof (val);
+
+ if (fnum < 0)
+ throw new ::java::net::SocketException (JvNewStringUTF ("Socket closed"));
+
+ if (_Jv_IsInstanceOf (value, &::java::lang::Boolean::class$))
+ {
+ ::java::lang::Boolean *boolobj =
+ static_cast< ::java::lang::Boolean *> (value);
+ if (boolobj->booleanValue())
+ val = 1;
+ else
+ {
+ if (optID == _Jv_SO_LINGER_)
+ val = -1;
+ else
+ val = 0;
+ }
+ }
+ else if (_Jv_IsInstanceOf (value, &::java::lang::Integer::class$))
+ {
+ ::java::lang::Integer *intobj =
+ static_cast< ::java::lang::Integer *> (value);
+ val = (int) intobj->intValue();
+ }
+ else
+ {
+ throw new ::java::lang::IllegalArgumentException (
+ JvNewStringLatin1 ("`value' must be Boolean or Integer"));
+ }
+
+ switch (optID)
+ {
+ case _Jv_TCP_NODELAY_ :
+ if (::setsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
+ val_len) == SOCKET_ERROR)
+ goto error;
+ return;
+
+ case _Jv_SO_KEEPALIVE_ :
+ if (::setsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
+ val_len) == SOCKET_ERROR)
+ goto error;
+ break;
+
+ case _Jv_SO_BROADCAST_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
+ break;
+
+ case _Jv_SO_OOBINLINE_ :
+ if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
+ val_len) == SOCKET_ERROR)
+ goto error;
+ break;
+
+ case _Jv_SO_LINGER_ :
+ struct linger l_val;
+ l_val.l_onoff = (val != -1);
+ l_val.l_linger = val;
+
+ if (::setsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
+ sizeof(l_val)) == SOCKET_ERROR)
+ goto error;
+ return;
+
+ case _Jv_SO_SNDBUF_ :
+ case _Jv_SO_RCVBUF_ :
+ int opt;
+ optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
+ if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val,
+ val_len) == SOCKET_ERROR)
+ goto error;
+ return;
+
+ case _Jv_SO_BINDADDR_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_BINDADDR: read only option"));
+ return;
+
+ case _Jv_IP_MULTICAST_IF_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
+ return;
+
+ case _Jv_IP_MULTICAST_IF2_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
+ break;
+
+ case _Jv_IP_MULTICAST_LOOP_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
+ break;
+
+ case _Jv_IP_TOS_ :
+ if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+ val_len) == SOCKET_ERROR)
+ goto error;
+ break;
+
+ case _Jv_SO_REUSEADDR_ :
+ throw new ::java::net::SocketException (
+ JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
+ return;
+
+ case _Jv_SO_TIMEOUT_ :
+ timeout = val;
+ return;
+
+ default :
+ WSASetLastError (WSAENOPROTOOPT);
+ }
+
+error:
+ _Jv_ThrowSocketException ();
+}
+
+::java::lang::Object *
+gnu::java::net::PlainSocketImpl::getOption (jint optID)
+{
+ int val;
+ socklen_t val_len = sizeof(val);
+ union SockAddr u;
+ socklen_t addrlen = sizeof(u);
+ struct linger l_val;
+ socklen_t l_val_len = sizeof(l_val);
+
+ switch (optID)
+ {
+ case _Jv_TCP_NODELAY_ :
+ if (::getsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
+ &val_len) == SOCKET_ERROR)
+ goto error;
+ else
+ return new ::java::lang::Boolean (val != 0);
+ break;
+
+ case _Jv_SO_LINGER_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
+ &l_val_len) == SOCKET_ERROR)
+ goto error;
+
+ if (l_val.l_onoff)
+ return new ::java::lang::Integer (l_val.l_linger);
+ else
+ return new ::java::lang::Boolean ((jboolean)false);
+ break;
+
+ case _Jv_SO_KEEPALIVE_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
+ &val_len) == SOCKET_ERROR)
+ goto error;
+ else
+ return new ::java::lang::Boolean (val != 0);
+
+ case _Jv_SO_BROADCAST_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+ &val_len) == SOCKET_ERROR)
+ goto error;
+ return new ::java::lang::Boolean ((jboolean)val);
+
+ case _Jv_SO_OOBINLINE_ :
+ if (::getsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
+ &val_len) == SOCKET_ERROR)
+ goto error;
+ return new ::java::lang::Boolean ((jboolean)val);
+
+ case _Jv_SO_RCVBUF_ :
+ case _Jv_SO_SNDBUF_ :
+ int opt;
+ optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
+ if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val,
+ &val_len) == SOCKET_ERROR)
+ goto error;
+ else
+ return new ::java::lang::Integer (val);
+ break;
+ case _Jv_SO_BINDADDR_:
+ // cache the local address
+ if (localAddress == NULL)
+ {
+ jbyteArray laddr;
+
+ if (::getsockname (fnum, (sockaddr*) &u,
+ &addrlen) == SOCKET_ERROR)
+ goto error;
+
+ if (u.address.sin_family == AF_INET)
+ {
+ laddr = JvNewByteArray (4);
+ memcpy (elements (laddr), &u.address.sin_addr, 4);
+ }
+#ifdef HAVE_INET6
+ else if (u.address.sin_family == AF_INET6)
+ {
+ laddr = JvNewByteArray (16);
+ memcpy (elements (laddr), &u.address6.sin6_addr, 16);
+ }
+#endif
+ else
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("invalid family"));
+ localAddress = new ::java::net::InetAddress (laddr, NULL);
+ }
+
+ return localAddress;
+ break;
+ case _Jv_IP_MULTICAST_IF_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
+ break;
+
+ case _Jv_IP_MULTICAST_IF2_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
+ break;
+
+ case _Jv_IP_MULTICAST_LOOP_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
+ break;
+
+ case _Jv_IP_TOS_ :
+ if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+ &val_len) == SOCKET_ERROR)
+ goto error;
+ return new ::java::lang::Integer (val);
+ break;
+
+ case _Jv_SO_REUSEADDR_ :
+ throw new ::java::net::SocketException
+ (JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
+ break;
+
+ case _Jv_SO_TIMEOUT_ :
+ return new ::java::lang::Integer (timeout);
+ break;
+
+ default :
+ WSASetLastError (WSAENOPROTOOPT);
+ }
+
+error:
+ _Jv_ThrowSocketException ();
+ return 0;
+ // we should never get here
+}
+
+void
+gnu::java::net::PlainSocketImpl::shutdownInput (void)
+{
+ if (::shutdown (fnum, 0))
+ _Jv_ThrowSocketException ();
+}
+
+void
+gnu::java::net::PlainSocketImpl::shutdownOutput (void)
+{
+ if (::shutdown (fnum, 1))
+ _Jv_ThrowSocketException ();
+}
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.PlainDatagramSocketImpl;
import java.io.IOException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.IllegalBlockingModeException;
*/
public InetAddress getLocalAddress()
{
- // FIXME: JCL p. 510 says this should call checkConnect. But what
- // string should be used as the hostname? Maybe this is just a side
- // effect of calling InetAddress.getLocalHost.
- //
- // And is getOption with SO_BINDADDR the right way to get the address?
- // Doesn't seem to be since this method doesn't throw a SocketException
- // and SO_BINADDR can throw one.
- //
- // Also see RETURNS section in JCL p. 510 about returning any local
- // addr "if the current execution context is not allowed to connect to
- // the network interface that is actually bound to this datagram socket."
- // How is that done? via InetAddress.getLocalHost? But that throws
- // an UnknownHostException and this method doesn't.
- //
- // if (s != null)
- // s.checkConnect("localhost", -1);
+ if (impl == null
+ || closed)
+ return null;
+
+ InetAddress result;
+
try
{
- return (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR);
- }
- catch (SocketException ex)
- {
- }
+ result = (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR);
- try
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ s.checkConnect (result.getHostName(), -1);
+ }
+ catch (SecurityException e)
{
- return InetAddress.getLocalHost();
+ result = InetAddress.ANY_IF;
}
- catch (UnknownHostException ex)
+ catch (SocketException e)
{
- return null;
+ result = InetAddress.ANY_IF;
}
+
+ return result;
}
/**
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.PlainDatagramSocketImpl;
import java.io.IOException;
import java.util.Enumeration;
+++ /dev/null
-/* PlainDatagramSocketImpl.java -- Default DatagramSocket implementation
- Copyright (C) 1998, 1999, 2001 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., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 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 java.io.IOException;
-import gnu.classpath.Configuration;
-
-/**
- * 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 is the default socket implementation for datagram sockets.
- * It makes native calls to C routines that implement BSD style
- * SOCK_DGRAM sockets in the AF_INET family.
- *
- * @author Aaron M. Renn <arenn@urbanophile.com>
- * @author Warren Levy <warrenl@cygnus.com>
- */
-class PlainDatagramSocketImpl extends DatagramSocketImpl
-{
- // Static initializer to load native library
- static
- {
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary("javanet");
- }
- }
-
- // These fields are mirrored for use in native code to avoid cpp conflicts
- // when the #defines in system header files are the same as the public fields.
- static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
- _Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
- _Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
- _Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
- _Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
- _Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
- _Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
- _Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
- _Jv_IP_TOS_ = SocketOptions.IP_TOS,
- _Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
- _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
- _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
- _Jv_SO_RCVBUF_ = SocketOptions.SO_RCVBUF,
- _Jv_SO_KEEPALIVE_ = SocketOptions.SO_KEEPALIVE;
-
- /**
- * This is the actual underlying file descriptor
- */
- int fnum = -1;
-
- // FIXME: Is this necessary? Could it help w/ DatagramSocket.getLocalAddress?
- // InetAddress address;
-
- // localAddress cache
- InetAddress localAddress;
-
- // 'timeout' is set/read by setOption/getOption.
- int timeout = 0;
-
- /**
- * Default do nothing constructor
- */
- public PlainDatagramSocketImpl()
- {
- }
-
- /**
- * Binds this socket to a particular port and interface
- *
- * @param port The port to bind to
- * @param addr The address to bind to
- *
- * @exception SocketException If an error occurs
- */
- protected native void bind(int lport, InetAddress laddr)
- throws SocketException;
-
- protected native void connect (InetAddress i, int port)
- throws SocketException;
-
- protected native void disconnect ();
-
- /**
- * Creates a new datagram socket
- *
- * @exception SocketException If an error occurs
- */
- protected native void create() throws SocketException;
-
- protected native int peek(InetAddress i) throws IOException;
-
- protected native int peekData (DatagramPacket dp) throws IOException;
-
- /**
- * Sets the Time to Live value for the socket
- *
- * @param ttl The new TTL value
- *
- * @exception IOException If an error occurs
- */
- protected native void setTimeToLive(int ttl) throws IOException;
-
- /**
- * Gets the Time to Live value for the socket
- *
- * @return The TTL value
- *
- * @exception IOException If an error occurs
- */
- protected native int getTimeToLive() throws IOException;
-
- /**
- * Sends a packet of data to a remote host
- *
- * @param packet The packet to send
- *
- * @exception IOException If an error occurs
- */
- protected native void send(DatagramPacket p) throws IOException;
-
- /**
- * Receives a UDP packet from the network
- *
- * @param packet The packet to fill in with the data received
- *
- * @exception IOException IOException If an error occurs
- */
- protected native void receive(DatagramPacket p) throws IOException;
-
- /**
- * Sets the value of an option on the socket
- *
- * @param option_id The identifier of the option to set
- * @param val The value of the option to set
- *
- * @exception SocketException If an error occurs
- */
- public native void setOption(int optID, Object value) throws SocketException;
-
- /**
- * Retrieves the value of an option on the socket
- *
- * @param option_id The identifier of the option to retrieve
- *
- * @return The value of the option
- *
- * @exception SocketException If an error occurs
- */
- public native Object getOption(int optID) throws SocketException;
-
- private native void mcastGrp(InetAddress inetaddr, NetworkInterface netIf,
- boolean join) throws IOException;
-
- /**
- * Closes the socket
- */
- protected native void close();
-
- /**
- * Gets the Time to Live value for the socket
- *
- * @return The TTL value
- *
- * @exception IOException If an error occurs
- *
- * @deprecated 1.2
- */
- protected byte getTTL() throws IOException
- {
- return (byte) getTimeToLive();
- }
-
- /**
- * Sets the Time to Live value for the socket
- *
- * @param ttl The new TTL value
- *
- * @exception IOException If an error occurs
- *
- * @deprecated 1.2
- */
- protected void setTTL(byte ttl) throws IOException
- {
- setTimeToLive(((int) ttl) & 0xFF);
- }
-
- /**
- * Joins a multicast group
- *
- * @param addr The group to join
- *
- * @exception IOException If an error occurs
- */
- protected void join(InetAddress inetaddr) throws IOException
- {
- mcastGrp(inetaddr, null, true);
- }
-
- /**
- * Leaves a multicast group
- *
- * @param addr The group to leave
- *
- * @exception IOException If an error occurs
- */
- protected void leave(InetAddress inetaddr) throws IOException
- {
- mcastGrp(inetaddr, null, false);
- }
-
- protected void joinGroup (SocketAddress mcastaddr, NetworkInterface netIf)
- throws IOException
- {
- mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, true);
- }
-
- protected void leaveGroup (SocketAddress mcastaddr, NetworkInterface netIf)
- throws IOException
- {
- mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, false);
- }
-
- protected void finalize() throws Throwable
- {
- synchronized (this)
- {
- if (fnum != -1)
- close();
- }
- super.finalize();
- }
-}
+++ /dev/null
-/* PlainSocketImpl.java -- Default socket implementation
- Copyright (C) 1998, 1999 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., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 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 java.io.InputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import gnu.classpath.Configuration;
-
-/**
- * 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.
- */
-
-/**
- * Unless the application installs its own SocketImplFactory, this is the
- * default socket implemetation that will be used. It simply uses a
- * combination of Java and native routines to implement standard BSD
- * style sockets of family AF_INET and types SOCK_STREAM and SOCK_DGRAM
- *
- * @author Per Bothner <bothner@cygnus.com>
- * @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
- * @author Aaron M. Renn <arenn@urbanophile.com>
- */
-class PlainSocketImpl extends SocketImpl
-{
- // Static initializer to load native library.
- static
- {
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary("javanet");
- }
- }
-
- // These fields are mirrored for use in native code to avoid cpp conflicts
- // when the #defines in system header files are the same as the public fields.
- static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
- _Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
- _Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
- _Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
- _Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
- _Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
- _Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
- _Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
- _Jv_IP_TOS_ = SocketOptions.IP_TOS,
- _Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
- _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
- _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
- _Jv_SO_RCVBUF_ = SocketOptions.SO_RCVBUF,
- _Jv_SO_KEEPALIVE_ = SocketOptions.SO_KEEPALIVE;
-
- /**
- * The OS file handle representing the socket.
- * This is used for reads and writes to/from the socket and
- * to close it.
- *
- * When the socket is closed this is reset to -1.
- */
- int fnum = -1;
-
- // This value is set/read by setOption/getOption.
- int timeout = 0;
-
- // localAddress cache
- InetAddress localAddress;
-
- /**
- * A cached copy of the in stream for reading from the socket.
- */
- private InputStream in;
-
- /**
- * A cached copy of the out stream for writing to the socket.
- */
- private OutputStream out;
-
- /**
- * Default do nothing constructor
- */
- public PlainSocketImpl()
- {
- }
-
- protected void finalize() throws Throwable
- {
- synchronized (this)
- {
- if (fnum != -1)
- try
- {
- close();
- }
- catch (IOException ex)
- {
- // ignore
- }
- }
- super.finalize();
- }
-
- /**
- * Sets the specified option on a socket to the passed in object. For
- * options that take an integer argument, the passed in object is an
- * Integer. The option_id parameter is one of the defined constants in
- * this interface.
- *
- * @param option_id The identifier of the option
- * @param val The value to set the option to
- *
- * @exception SocketException If an error occurs
- */
- public native void setOption(int optID, Object value) throws SocketException;
-
- /**
- * Returns the current setting of the specified option. The Object returned
- * will be an Integer for options that have integer values. The option_id
- * is one of the defined constants in this interface.
- *
- * @param option_id The option identifier
- *
- * @return The current value of the option
- *
- * @exception SocketException If an error occurs
- */
- public native Object getOption(int optID) throws SocketException;
-
- public native void shutdownInput () throws IOException;
-
- public native void shutdownOutput () throws IOException;
-
- /**
- * Creates a new socket that is not bound to any local address/port and
- * is not connected to any remote address/port. This will be created as
- * a stream socket if the stream parameter is true, or a datagram socket
- * if the stream parameter is false.
- *
- * @param stream true for a stream socket, false for a datagram socket
- */
- protected native void create (boolean stream) throws IOException;
-
- /**
- * Connects to the remote hostname and port specified as arguments.
- *
- * @param hostname The remote hostname to connect to
- * @param port The remote port to connect to
- *
- * @exception IOException If an error occurs
- */
- protected void connect (String host, int port) throws IOException
- {
- connect (new InetSocketAddress (InetAddress.getByName(host), port), 0);
- }
-
- /**
- * Connects to the remote address and port specified as arguments.
- *
- * @param addr The remote address to connect to
- * @param port The remote port to connect to
- *
- * @exception IOException If an error occurs
- */
- protected void connect (InetAddress host, int port) throws IOException
- {
- connect (new InetSocketAddress (host, port), 0);
- }
-
- protected native void connect (SocketAddress addr, int timeout)
- throws IOException;
-
- /**
- * Binds to the specified port on the specified addr. Note that this addr
- * must represent a local IP address. **** How bind to INADDR_ANY? ****
- *
- * @param addr The address to bind to
- * @param port The port number to bind to
- *
- * @exception IOException If an error occurs
- */
- protected native void bind (InetAddress host, int port) throws IOException;
-
- /**
- * Starts listening for connections on a socket. The queuelen parameter
- * is how many pending connections will queue up waiting to be serviced
- * before being accept'ed. If the queue of pending requests exceeds this
- * number, additional connections will be refused.
- *
- * @param queuelen The length of the pending connection queue
- *
- * @exception IOException If an error occurs
- */
- protected native void listen (int backlog) throws IOException;
-
- private native void accept (PlainSocketImpl s) throws IOException;
-
- /**
- * Accepts a new connection on this socket and returns in in the
- * passed in SocketImpl.
- *
- * @param impl The SocketImpl object to accept this connection.
- */
- protected void accept (SocketImpl s) throws IOException
- {
- accept((PlainSocketImpl) s);
- }
-
- /**
- * Returns the number of bytes that the caller can read from this socket
- * without blocking.
- *
- * @return The number of readable bytes before blocking
- *
- * @exception IOException If an error occurs
- */
- protected native int available() throws IOException;
-
- /**
- * Closes the socket. This will cause any InputStream or OutputStream
- * objects for this Socket to be closed as well.
- * <p>
- * Note that if the SO_LINGER option is set on this socket, then the
- * operation could block.
- *
- * @exception IOException If an error occurs
- */
- protected native void close () throws IOException;
-
- protected native void sendUrgentData(int data)
- throws IOException;
-
- native int read() throws IOException;
-
- /**
- * Internal method used by SocketInputStream for reading data from
- * the connection. Reads up to len bytes of data into the buffer
- * buf starting at offset bytes into the buffer.
- *
- * @return The actual number of bytes read or -1 if end of stream.
- *
- * @exception IOException If an error occurs
- */
- native int read(byte[] buffer, int offset, int count)
- throws IOException;
-
- native void write(int c) throws IOException;
-
- /**
- * Internal method used by SocketOuputStream for writing data to
- * the connection. Writes up to len bytes of data from the buffer
- * buf starting at offset bytes into the buffer.
- *
- * @exception IOException If an error occurs
- */
- native void write(byte[] buffer, int offset, int count)
- throws IOException;
-
- /**
- * Returns an InputStream object for reading from this socket. This will
- * be an instance of SocketInputStream.
- *
- * @return An input stream attached to the socket.
- *
- * @exception IOException If an error occurs
- */
- protected synchronized InputStream getInputStream() throws IOException
- {
- if (in == null)
- in = new SocketInputStream();
-
- return in;
- }
-
- /**
- * Returns an OutputStream object for writing to this socket. This will
- * be an instance of SocketOutputStream.
- *
- * @return An output stream attached to the socket.
- *
- * @exception IOException If an error occurs
- */
- protected synchronized OutputStream getOutputStream() throws IOException
- {
- if (out == null)
- out = new SocketOutputStream();
-
- return out;
- }
-
- /**
- * A stream which reads from the socket implementation.
- *
- * @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
- */
- class SocketInputStream
- extends InputStream
- {
- SocketInputStream()
- {
- }
-
- public final void close() throws IOException
- {
- PlainSocketImpl.this.close();
- }
-
- public final int available() throws IOException
- {
- return PlainSocketImpl.this.available();
- }
-
- public final int read() throws IOException
- {
- return PlainSocketImpl.this.read();
- }
-
- public final int read(byte[] buffer, int offset, int length)
- throws IOException
- {
- return PlainSocketImpl.this.read(buffer, offset, length);
- }
-
- public final int read(byte[] buffer)
- throws IOException
- {
- return PlainSocketImpl.this.read(buffer, 0, buffer.length);
- }
- }
-
- /** A stream which writes to the socket implementation.
- *
- * @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
- */
- class SocketOutputStream
- extends OutputStream
- {
- public final void close() throws IOException
- {
- PlainSocketImpl.this.close();
- }
-
- public final void write(int c) throws IOException
- {
- PlainSocketImpl.this.write(c);
- }
-
- public final void write(byte[] buffer, int offset, int length)
- throws IOException
- {
- PlainSocketImpl.this.write(buffer, offset, length);
- }
-
- public final void write(byte[] buffer)
- throws IOException
- {
- PlainSocketImpl.this.write(buffer, 0, buffer.length);
- }
- }
-}
/* ServerSocket.java -- Class for implementing server side sockets
- Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
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.nio.channels.IllegalBlockingModeException;
import java.nio.channels.ServerSocketChannel;
/* Socket.java -- Client socket implementation
- Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
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.InputStream;
import java.io.IOException;
import java.io.OutputStream;
+++ /dev/null
-/* SocketInputStream.java -- An InputStream for Sockets
- Copyright (C) 1998, 2000, 2002 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., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 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 java.io.InputStream;
-import java.io.IOException;
-
-/**
- * This class contains an implementation of <code>InputStream</code> for
- * sockets. It in an internal only class used by <code>PlainSocketImpl</code>.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
-class SocketInputStream extends InputStream
-{
-
-/*************************************************************************/
-
-/*
- * Instance Variables
- */
-
-/**
- * The PlainSocketImpl object this stream is associated with
- */
-private PlainSocketImpl impl;
-
-/*************************************************************************/
-
-/*
- * Constructors
- */
-
-/**
- * Builds an instance of this class from a PlainSocketImpl object
- */
-protected
-SocketInputStream(PlainSocketImpl impl)
-{
- this.impl = impl;
-}
-
-/*************************************************************************/
-
-/*
- * Instance Methods
- */
-
-/**
- * Returns the number of bytes available to be read before blocking
- */
-public int
-available() throws IOException
-{
- return(impl.available());
-}
-
-/*************************************************************************/
-
-/**
- * Determines if "mark" functionality is supported on this stream. For
- * sockets, this is always false. Note that the superclass default is
- * false, but it is overridden out of safety concerns and/or paranoia.
- */
-public boolean
-markSupported()
-{
- return(false);
-}
-
-/*************************************************************************/
-
-/**
- * Do nothing mark method since we don't support this functionality. Again,
- * overriding out of paranoia.
- *
- * @param readlimit In theory, the number of bytes we can read before the mark becomes invalid
- */
-public void
-mark(int readlimit)
-{
-}
-
-/*************************************************************************/
-
-/**
- * Since we don't support mark, this method always throws an exception
- *
- * @exception IOException Everytime since we don't support this functionality
- */
-public void
-reset() throws IOException
-{
- throw new IOException("Socket InputStreams do not support mark/reset");
-}
-
-/*************************************************************************/
-
-/**
- * This method not only closes the stream, it closes the underlying socket
- * (and thus any connection) and invalidates any other Input/Output streams
- * for the underlying impl object
- */
-public void
-close() throws IOException
-{
- impl.close();
-}
-
-/*************************************************************************/
-
-/**
- * Reads the next byte of data and returns it as an int.
- *
- * @return The byte read (as an int) or -1 if end of stream);
- *
- * @exception IOException If an error occurs.
- */
-public int
-read() throws IOException
-{
- byte buf[] = new byte[1];
-
- int bytes_read = read(buf, 0, buf.length);
-
- if (bytes_read != -1)
- return(buf[0] & 0xFF);
- else
- return(-1);
-}
-
-/*************************************************************************/
-
-/**
- * Reads up to buf.length bytes of data into the caller supplied buffer.
- *
- * @return The actual number of bytes read or -1 if end of stream
- *
- * @exception IOException If an error occurs.
- */
-public int
-read(byte[] buf) throws IOException
-{
- return(read(buf, 0, buf.length));
-}
-
-/*************************************************************************/
-
-/**
- * Reads up to len bytes of data into the caller supplied buffer starting
- * at offset bytes from the start of the buffer
- *
- * @return The number of bytes actually read or -1 if end of stream
- *
- * @exception IOException If an error occurs.
- */
-public int
-read(byte[] buf, int offset, int len) throws IOException
-{
- int bytes_read = impl.read(buf, offset, len);
- if (bytes_read == 0)
- return(-1);
-
- return(bytes_read);
-}
-
-} // class SocketInputStream
-
+++ /dev/null
-/* SocketOutputStream.java -- OutputStream for PlainSocketImpl
- Copyright (C) 1998,2000 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., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 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 java.io.OutputStream;
-import java.io.IOException;
-
-/**
- * This class is used internally by <code>PlainSocketImpl</code> to be the
- * <code>OutputStream</code> subclass returned by its
- * <code>getOutputStream method</code>. It expects only to be used in that
- * context.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
-class SocketOutputStream extends OutputStream
-{
-
-/*************************************************************************/
-
-/*
- * Instance Variables
- */
-
-/**
- * The PlainSocketImpl object this stream is associated with
- */
-private PlainSocketImpl impl;
-
-/*************************************************************************/
-
-/*
- * Constructors
- */
-
-/**
- * Build an instance of this class from a PlainSocketImpl object
- */
-protected
-SocketOutputStream(PlainSocketImpl impl)
-{
- this.impl = impl;
-}
-
-/*************************************************************************/
-
-/*
- * Instance Methods
- */
-
-/**
- * This method closes the stream and the underlying socket connection. This
- * action also effectively closes any other InputStream or OutputStream
- * object associated with the connection.
- *
- * @exception IOException If an error occurs
- */
-public void
-close() throws IOException
-{
- impl.close();
-}
-
-/*************************************************************************/
-
-/**
- * Hmmm, we don't seem to have a flush() method in Socket impl, so just
- * return for now, but this might need to be looked at later.
- *
- * @exception IOException Can't happen
- */
-public void
-flush() throws IOException
-{
- return;
-}
-
-/*************************************************************************/
-
-/**
- * Writes a byte (passed in as an int) to the given output stream
- *
- * @param b The byte to write
- *
- * @exception IOException If an error occurs
- */
-public void
-write(int b) throws IOException
-{
- byte buf[] = new byte[1];
-
- Integer i = new Integer(b);
- buf[0] = i.byteValue();
-
- write(buf, 0, buf.length);
-}
-
-/*************************************************************************/
-
-/**
- * Write an array of bytes to the output stream
- *
- * @param buf The array of bytes to write
- *
- * @exception IOException If an error occurs
- */
-public void
-write(byte[] buf) throws IOException
-{
- write(buf, 0, buf.length);
-}
-
-/*************************************************************************/
-
-/**
- * Writes len number of bytes from the array buf to the stream starting
- * at offset bytes into the buffer.
- *
- * @param buf The buffer
- * @param offset Offset into the buffer to start writing from
- * @param len The number of bytes to write
- */
-public void
-write(byte[] buf, int offset, int len) throws IOException
-{
- impl.write(buf, offset, len);
-}
-
-} // class SocketOutputStream
-
+++ /dev/null
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-
-#include <java/io/IOException.h>
-#include <java/lang/Object.h>
-#include <java/net/BindException.h>
-#include <java/net/DatagramPacket.h>
-#include <java/net/InetAddress.h>
-#include <java/net/NetworkInterface.h>
-#include <java/net/PlainDatagramSocketImpl.h>
-#include <java/net/SocketException.h>
-
-void
-java::net::PlainDatagramSocketImpl::create ()
-{
- throw new SocketException (
- JvNewStringLatin1 ("DatagramSocketImpl.create: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::bind (jint, java::net::InetAddress *)
-{
- throw new BindException (
- JvNewStringLatin1 ("DatagramSocketImpl.bind: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::connect (java::net::InetAddress *, jint)
-{
- throw new SocketException (
- JvNewStringLatin1 ("DatagramSocketImpl.connect: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::disconnect ()
-{
- throw new SocketException (
- JvNewStringLatin1 ("DatagramSocketImpl.disconnect: unimplemented"));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("DatagramSocketImpl.peek: unimplemented"));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::peekData(java::net::DatagramPacket *)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("DatagramSocketImpl.peekData: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::close ()
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("DatagramSocketImpl.close: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::send (java::net::DatagramPacket *)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("DatagramSocketImpl.send: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::receive (java::net::DatagramPacket *)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("DatagramSocketImpl.receive: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setTimeToLive (jint)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("DatagramSocketImpl.setTimeToLive: unimplemented"));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::getTimeToLive ()
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("DatagramSocketImpl.getTimeToLive: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *,
- java::net::NetworkInterface *,
- jboolean)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("DatagramSocketImpl.mcastGrp: unimplemented"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setOption (jint, java::lang::Object *)
-{
- throw new SocketException (
- JvNewStringLatin1 ("DatagramSocketImpl.setOption: unimplemented"));
-}
-
-java::lang::Object *
-java::net::PlainDatagramSocketImpl::getOption (jint)
-{
- throw new SocketException (
- JvNewStringLatin1 ("DatagramSocketImpl.getOption: unimplemented"));
-}
+++ /dev/null
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#include <errno.h>
-#include <string.h>
-
-#if HAVE_BSTRING_H
-// Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
-#include <bstring.h>
-#endif
-
-#include <gcj/cni.h>
-#include <java/io/IOException.h>
-#include <java/io/InterruptedIOException.h>
-#include <java/net/BindException.h>
-#include <java/net/SocketException.h>
-#include <java/net/PlainDatagramSocketImpl.h>
-#include <java/net/InetAddress.h>
-#include <java/net/NetworkInterface.h>
-#include <java/net/DatagramPacket.h>
-#include <java/net/PortUnreachableException.h>
-#include <java/lang/InternalError.h>
-#include <java/lang/Object.h>
-#include <java/lang/Boolean.h>
-#include <java/lang/Integer.h>
-
-union SockAddr
-{
- struct sockaddr_in address;
-#ifdef HAVE_INET6
- struct sockaddr_in6 address6;
-#endif
-};
-
-union McastReq
-{
-#if HAVE_STRUCT_IP_MREQ
- struct ip_mreq mreq;
-#endif
-#if HAVE_STRUCT_IPV6_MREQ
- struct ipv6_mreq mreq6;
-#endif
-};
-
-union InAddr
-{
- struct in_addr addr;
-#ifdef HAVE_INET6
- struct in6_addr addr6;
-#endif
-};
-
-
-// FIXME: routines here and/or in natPlainSocketImpl.cc could throw
-// NoRouteToHostException; also consider UnknownHostException, ConnectException.
-
-void
-java::net::PlainDatagramSocketImpl::create ()
-{
- int sock = _Jv_socket (AF_INET, SOCK_DGRAM, 0);
-
- if (sock < 0)
- {
- char* strerr = strerror (errno);
- throw new java::net::SocketException (JvNewStringUTF (strerr));
- }
-
- _Jv_platform_close_on_exec (sock);
-
- // We use fnum in place of fd here. From leaving fd null we avoid
- // the double close problem in FileDescriptor.finalize.
- fnum = sock;
-}
-
-void
-java::net::PlainDatagramSocketImpl::bind (jint lport,
- java::net::InetAddress *host)
-{
- union SockAddr u;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
- jbyteArray haddress = host->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
-
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
-
- if (host != NULL)
- memcpy (&u.address.sin_addr, bytes, len);
- else
- u.address.sin_addr.s_addr = htonl (INADDR_ANY);
-
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (lport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (lport);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (_Jv_bind (fnum, ptr, len) == 0)
- {
- socklen_t addrlen = sizeof(u);
-
- if (lport != 0)
- localPort = lport;
- else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
- localPort = ntohs (u.address.sin_port);
- else
- goto error;
-
- /* Allow broadcast by default. */
- int broadcast = 1;
- if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &broadcast,
- sizeof (broadcast)) != 0)
- goto error;
-
- return;
- }
-
- error:
- char* strerr = strerror (errno);
- throw new java::net::BindException (JvNewStringUTF (strerr));
-}
-
-void
-java::net::PlainDatagramSocketImpl::connect (java::net::InetAddress *, jint)
-{
- throw new ::java::lang::InternalError (JvNewStringLatin1 (
- "PlainDatagramSocketImpl::connect: not implemented yet"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::disconnect ()
-{
- throw new ::java::lang::InternalError (JvNewStringLatin1 (
- "PlainDatagramSocketImpl::disconnect: not implemented yet"));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *i)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- ssize_t retlen =
- ::recvfrom (fnum, (char *) NULL, 0, MSG_PEEK, (sockaddr*) &u,
- &addrlen);
- if (retlen < 0)
- goto error;
- // FIXME: Deal with Multicast addressing and if the socket is connected.
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
-
- i->addr = raddr;
- return rport;
- error:
- char* strerr = strerror (errno);
-
- if (errno == ECONNREFUSED)
- throw new PortUnreachableException (JvNewStringUTF (strerr));
-
- throw new java::io::IOException (JvNewStringUTF (strerr));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::peekData(java::net::DatagramPacket *p)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- jbyte *dbytes = elements (p->getData());
- ssize_t retlen = 0;
-
- // Do timeouts via select since SO_RCVTIMEO is not always available.
- if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
- {
- fd_set rset;
- struct timeval tv;
- FD_ZERO(&rset);
- FD_SET(fnum, &rset);
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
- int retval;
- if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
- goto error;
- else if (retval == 0)
- throw new java::io::InterruptedIOException ();
- }
-
- retlen =
- ::recvfrom (fnum, (char *) dbytes, p->getLength(), MSG_PEEK, (sockaddr*) &u,
- &addrlen);
- if (retlen < 0)
- goto error;
- // FIXME: Deal with Multicast addressing and if the socket is connected.
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
-
- p->setAddress (new InetAddress (raddr, NULL));
- p->setPort (rport);
- p->setLength ((jint) retlen);
- return rport;
-
- error:
- char* strerr = strerror (errno);
-
- if (errno == ECONNREFUSED)
- throw new PortUnreachableException (JvNewStringUTF (strerr));
-
- throw new java::io::IOException (JvNewStringUTF (strerr));
-}
-
-// Close(shutdown) the socket.
-void
-java::net::PlainDatagramSocketImpl::close ()
-{
- // Avoid races from asynchronous finalization.
- JvSynchronize sync (this);
-
- // The method isn't declared to throw anything, so we disregard
- // the return value.
- _Jv_close (fnum);
- fnum = -1;
- timeout = 0;
-}
-
-void
-java::net::PlainDatagramSocketImpl::send (java::net::DatagramPacket *p)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- jint rport = p->getPort();
- union SockAddr u;
- jbyteArray haddress = p->getAddress()->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- jbyte *dbytes = elements (p->getData());
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
- memcpy (&u.address.sin_addr, bytes, len);
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (rport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (rport);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (::sendto (fnum, (char *) dbytes, p->getLength(), 0, ptr, len) >= 0)
- return;
-
- char* strerr = strerror (errno);
-
- if (errno == ECONNREFUSED)
- throw new PortUnreachableException (JvNewStringUTF (strerr));
-
- throw new java::io::IOException (JvNewStringUTF (strerr));
-}
-
-void
-java::net::PlainDatagramSocketImpl::receive (java::net::DatagramPacket *p)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- jbyte *dbytes = elements (p->getData());
- ssize_t retlen = 0;
-
- // Do timeouts via select since SO_RCVTIMEO is not always available.
- if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
- {
- fd_set rset;
- struct timeval tv;
- FD_ZERO(&rset);
- FD_SET(fnum, &rset);
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
- int retval;
- if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
- goto error;
- else if (retval == 0)
- throw new java::io::InterruptedIOException ();
- }
-
- retlen =
- ::recvfrom (fnum, (char *) dbytes, p->getLength(), 0, (sockaddr*) &u,
- &addrlen);
- if (retlen < 0)
- goto error;
- // FIXME: Deal with Multicast addressing and if the socket is connected.
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
-
- p->setAddress (new InetAddress (raddr, NULL));
- p->setPort (rport);
- p->setLength ((jint) retlen);
- return;
-
- error:
- char* strerr = strerror (errno);
-
- if (errno == ECONNREFUSED)
- throw new PortUnreachableException (JvNewStringUTF (strerr));
-
- throw new java::io::IOException (JvNewStringUTF (strerr));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setTimeToLive (jint ttl)
-{
- // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
- char val = (char) ttl;
- socklen_t val_len = sizeof(val);
-
- if (::setsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, val_len) == 0)
- return;
-
- char* strerr = strerror (errno);
- throw new java::io::IOException (JvNewStringUTF (strerr));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::getTimeToLive ()
-{
- // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
- char val;
- socklen_t val_len = sizeof(val);
-
- if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, &val_len) == 0)
- return ((int) val) & 0xFF;
-
- char* strerr = strerror (errno);
- throw new java::io::IOException (JvNewStringUTF (strerr));
-}
-
-void
-java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *inetaddr,
- java::net::NetworkInterface *,
- jboolean join)
-{
- // FIXME: implement use of NetworkInterface
-
- union McastReq u;
- jbyteArray haddress = inetaddr->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- int level, opname;
- const char *ptr;
- if (0)
- ;
-#if HAVE_STRUCT_IP_MREQ
- else if (len == 4)
- {
- level = IPPROTO_IP;
- opname = join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP;
- memcpy (&u.mreq.imr_multiaddr, bytes, len);
- // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
- // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
- u.mreq.imr_interface.s_addr = htonl (INADDR_ANY);
- len = sizeof (struct ip_mreq);
- ptr = (const char *) &u.mreq;
- }
-#endif
-#if HAVE_STRUCT_IPV6_MREQ
- else if (len == 16)
- {
- level = IPPROTO_IPV6;
-
- /* Prefer new RFC 2553 names. */
-#ifndef IPV6_JOIN_GROUP
-#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
-#endif
-#ifndef IPV6_LEAVE_GROUP
-#define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
-#endif
-
- opname = join ? IPV6_JOIN_GROUP : IPV6_LEAVE_GROUP;
- memcpy (&u.mreq6.ipv6mr_multiaddr, bytes, len);
- // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
- // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
- u.mreq6.ipv6mr_interface = 0;
- len = sizeof (struct ipv6_mreq);
- ptr = (const char *) &u.mreq6;
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (::setsockopt (fnum, level, opname, ptr, len) == 0)
- return;
-
- char* strerr = strerror (errno);
- throw new java::io::IOException (JvNewStringUTF (strerr));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setOption (jint optID,
- java::lang::Object *value)
-{
- int val;
- socklen_t val_len = sizeof (val);
-
- if (fnum < 0)
- throw new java::net::SocketException (JvNewStringUTF ("Socket closed"));
-
- if (_Jv_IsInstanceOf (value, &java::lang::Boolean::class$))
- {
- java::lang::Boolean *boolobj =
- static_cast<java::lang::Boolean *> (value);
- val = boolobj->booleanValue() ? 1 : 0;
- }
- else if (_Jv_IsInstanceOf (value, &java::lang::Integer::class$))
- {
- java::lang::Integer *intobj =
- static_cast<java::lang::Integer *> (value);
- val = (int) intobj->intValue();
- }
- // Else assume value to be an InetAddress for use with IP_MULTICAST_IF.
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("TCP_NODELAY not valid for UDP"));
- return;
- case _Jv_SO_LINGER_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_LINGER not valid for UDP"));
- return;
- case _Jv_SO_KEEPALIVE_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
- return;
-
- case _Jv_SO_BROADCAST_ :
- if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
- val_len) != 0)
- goto error;
- break;
-
- case _Jv_SO_OOBINLINE_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_OOBINLINE: not valid for UDP"));
- break;
-
- case _Jv_SO_SNDBUF_ :
- case _Jv_SO_RCVBUF_ :
-#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
- goto error;
-#else
- throw new java::lang::InternalError (
- JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
-#endif
- return;
- case _Jv_SO_REUSEADDR_ :
-#if defined(SO_REUSEADDR)
- if (::setsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
- val_len) != 0)
- goto error;
-#else
- throw new java::lang::InternalError (
- JvNewStringUTF ("SO_REUSEADDR not supported"));
-#endif
- return;
- case _Jv_SO_BINDADDR_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_BINDADDR: read only option"));
- return;
- case _Jv_IP_MULTICAST_IF_ :
- union InAddr u;
- jbyteArray haddress;
- jbyte *bytes;
- int len;
- int level, opname;
- const char *ptr;
-
- haddress = ((java::net::InetAddress *) value)->addr;
- bytes = elements (haddress);
- len = haddress->length;
- if (len == 4)
- {
- level = IPPROTO_IP;
- opname = IP_MULTICAST_IF;
- memcpy (&u.addr, bytes, len);
- len = sizeof (struct in_addr);
- ptr = (const char *) &u.addr;
- }
-// Tru64 UNIX V5.0 has struct sockaddr_in6, but no IPV6_MULTICAST_IF
-#if defined (HAVE_INET6) && defined (IPV6_MULTICAST_IF)
- else if (len == 16)
- {
- level = IPPROTO_IPV6;
- opname = IPV6_MULTICAST_IF;
- memcpy (&u.addr6, bytes, len);
- len = sizeof (struct in6_addr);
- ptr = (const char *) &u.addr6;
- }
-#endif
- else
- throw
- new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (::setsockopt (fnum, level, opname, ptr, len) != 0)
- goto error;
- return;
-
- case _Jv_IP_MULTICAST_IF2_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
- break;
-
- case _Jv_IP_MULTICAST_LOOP_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_LOOP: not yet implemented"));
- break;
-
- case _Jv_IP_TOS_ :
- if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
- val_len) != 0)
- goto error;
- return;
-
- case _Jv_SO_TIMEOUT_ :
- timeout = val;
- return;
- default :
- errno = ENOPROTOOPT;
- }
-
- error:
- char* strerr = strerror (errno);
- throw new java::net::SocketException (JvNewStringUTF (strerr));
-}
-
-java::lang::Object *
-java::net::PlainDatagramSocketImpl::getOption (jint optID)
-{
- int val;
- socklen_t val_len = sizeof(val);
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("TCP_NODELAY not valid for UDP"));
- break;
- case _Jv_SO_LINGER_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_LINGER not valid for UDP"));
- break;
- case _Jv_SO_KEEPALIVE_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
- break;
-
- case _Jv_SO_BROADCAST_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean (val != 0);
-
- case _Jv_SO_OOBINLINE_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_OOBINLINE not valid for UDP"));
- break;
-
- case _Jv_SO_RCVBUF_ :
- case _Jv_SO_SNDBUF_ :
-#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
- goto error;
- else
- return new java::lang::Integer (val);
-#else
- throw new java::lang::InternalError (
- JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
-#endif
- break;
- case _Jv_SO_BINDADDR_:
- // cache the local address
- if (localAddress == NULL)
- {
- jbyteArray laddr;
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
- goto error;
- if (u.address.sin_family == AF_INET)
- {
- laddr = JvNewByteArray (4);
- memcpy (elements (laddr), &u.address.sin_addr, 4);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- laddr = JvNewByteArray (16);
- memcpy (elements (laddr), &u.address6.sin6_addr, 16);
- }
-#endif
- else
- throw new java::net::SocketException (
- JvNewStringUTF ("invalid family"));
- localAddress = new java::net::InetAddress (laddr, NULL);
- }
- return localAddress;
- break;
- case _Jv_SO_REUSEADDR_ :
-#if defined(SO_REUSEADDR)
- if (::getsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean (val != 0);
-#else
- throw new java::lang::InternalError (
- JvNewStringUTF ("SO_REUSEADDR not supported"));
-#endif
- break;
- case _Jv_IP_MULTICAST_IF_ :
-#ifdef HAVE_INET_NTOA
- struct in_addr inaddr;
- socklen_t inaddr_len;
- char *bytes;
-
- inaddr_len = sizeof(inaddr);
- if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_IF, (char *) &inaddr,
- &inaddr_len) != 0)
- goto error;
-
- bytes = inet_ntoa (inaddr);
-
- return java::net::InetAddress::getByName (JvNewStringLatin1 (bytes));
-#else
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF: not available - no inet_ntoa()"));
-#endif
- break;
- case _Jv_SO_TIMEOUT_ :
- return new java::lang::Integer (timeout);
- break;
-
- case _Jv_IP_MULTICAST_IF2_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
- break;
-
- case _Jv_IP_MULTICAST_LOOP_ :
- if (::getsockopt (fnum, SOL_SOCKET, IP_MULTICAST_LOOP, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean (val != 0);
-
- case _Jv_IP_TOS_ :
- if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Integer (val);
-
- default :
- errno = ENOPROTOOPT;
- }
-
- error:
- char* strerr = strerror (errno);
- throw new java::net::SocketException (JvNewStringUTF (strerr));
-}
+++ /dev/null
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-#include <string.h>
-
-#if HAVE_BSTRING_H
-// Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
-#include <bstring.h>
-#endif
-
-#include <java/io/IOException.h>
-#include <java/io/InterruptedIOException.h>
-#include <java/net/BindException.h>
-#include <java/net/SocketException.h>
-#include <java/net/PlainDatagramSocketImpl.h>
-#include <java/net/InetAddress.h>
-#include <java/net/NetworkInterface.h>
-#include <java/net/DatagramPacket.h>
-#include <java/net/PortUnreachableException.h>
-#include <java/net/SocketTimeoutException.h>
-#include <java/lang/InternalError.h>
-#include <java/lang/Object.h>
-#include <java/lang/Boolean.h>
-#include <java/lang/Integer.h>
-
-union SockAddr
-{
- struct sockaddr_in address;
-#ifdef HAVE_INET6
- struct sockaddr_in6 address6;
-#endif
-};
-
-union McastReq
-{
-#if HAVE_STRUCT_IP_MREQ
- struct ip_mreq mreq;
-#endif
-#if HAVE_STRUCT_IPV6_MREQ
- struct ipv6_mreq mreq6;
-#endif
-};
-
-union InAddr
-{
- struct in_addr addr;
-#ifdef HAVE_INET6
- struct in6_addr addr6;
-#endif
-};
-
-// FIXME: routines here and/or in natPlainSocketImpl.cc could throw
-// NoRouteToHostException; also consider UnknownHostException, ConnectException.
-
-void
-java::net::PlainDatagramSocketImpl::create ()
-{
- SOCKET sock = ::socket (AF_INET, SOCK_DGRAM, 0);
-
- if (sock == INVALID_SOCKET)
- {
- _Jv_ThrowSocketException ();
- }
-
- _Jv_platform_close_on_exec (sock);
-
- // We use fnum in place of fd here. From leaving fd null we avoid
- // the double close problem in FileDescriptor.finalize.
- fnum = (int) sock;
-}
-
-void
-java::net::PlainDatagramSocketImpl::bind (jint lport,
- java::net::InetAddress *host)
-{
- union SockAddr u;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
- jbyteArray haddress = host->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
-
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
-
- if (host != NULL)
- memcpy (&u.address.sin_addr, bytes, len);
- else
- u.address.sin_addr.s_addr = htonl (INADDR_ANY);
-
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (lport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (lport);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (::bind (fnum, ptr, len) == 0)
- {
- socklen_t addrlen = sizeof(u);
-
- if (lport != 0)
- localPort = lport;
- else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
- localPort = ntohs (u.address.sin_port);
- else
- goto error;
-
- /* Allow broadcast by default. */
- int broadcast = 1;
- if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &broadcast,
- sizeof (broadcast)) != 0)
- goto error;
-
- return;
- }
-
-error:
- DWORD dwErrorCode = WSAGetLastError ();
- throw new java::net::BindException (_Jv_WinStrError (dwErrorCode));
-}
-
-void
-java::net::PlainDatagramSocketImpl::connect (java::net::InetAddress *, jint)
-{
- throw new ::java::lang::InternalError (JvNewStringLatin1 (
- "PlainDatagramSocketImpl::connect: not implemented yet"));
-}
-
-void
-java::net::PlainDatagramSocketImpl::disconnect ()
-{
- throw new ::java::lang::InternalError (JvNewStringLatin1 (
- "PlainDatagramSocketImpl::disconnect: not implemented yet"));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *i)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- ssize_t retlen =
- ::recvfrom (fnum, (char *) NULL, 0, MSG_PEEK, (sockaddr*) &u,
- &addrlen);
- if (retlen < 0)
- goto error;
- // FIXME: Deal with Multicast addressing and if the socket is connected.
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
-
- i->addr = raddr;
- return rport;
-error:
- DWORD dwErrorCode = WSAGetLastError ();
- if (dwErrorCode == WSAECONNRESET)
- throw new PortUnreachableException (_Jv_WinStrError (dwErrorCode));
-
- _Jv_ThrowIOException ();
- return -1;
- // we should never get here
-}
-
-jint
-java::net::PlainDatagramSocketImpl::peekData(java::net::DatagramPacket *p)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- jbyte *dbytes = elements (p->getData());
- ssize_t retlen = 0;
-
- if (timeout > 0)
- {
- int nRet= ::setsockopt(fnum, SOL_SOCKET, SO_RCVTIMEO,
- (char*)&timeout, sizeof(timeout));
- if (nRet != NO_ERROR)
- goto error;
- }
-
- retlen =
- ::recvfrom (fnum, (char *) dbytes, p->getLength(), MSG_PEEK, (sockaddr*) &u,
- &addrlen);
- if (retlen == SOCKET_ERROR)
- goto error;
- // FIXME: Deal with Multicast addressing and if the socket is connected.
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
-
- p->setAddress (new InetAddress (raddr, NULL));
- p->setPort (rport);
- p->setLength ((jint) retlen);
- return rport;
-
-error:
- DWORD dwErrorCode = WSAGetLastError ();
- if (dwErrorCode == WSAECONNRESET)
- throw new PortUnreachableException (_Jv_WinStrError (dwErrorCode));
- else if (dwErrorCode == WSAETIMEDOUT)
- throw new java::net::SocketTimeoutException (_Jv_WinStrError (dwErrorCode));
- else
- _Jv_ThrowIOException ();
-
- return -1;
- // we should never get here
-}
-
-// Close(shutdown) the socket.
-void
-java::net::PlainDatagramSocketImpl::close ()
-{
- // Avoid races from asynchronous finalization.
- JvSynchronize sync (this);
-
- // The method isn't declared to throw anything, so we disregard
- // the return value.
- ::closesocket (fnum);
- fnum = -1;
- timeout = 0;
-}
-
-void
-java::net::PlainDatagramSocketImpl::send (java::net::DatagramPacket *p)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- jint rport = p->getPort();
- union SockAddr u;
- jbyteArray haddress = p->getAddress()->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- jbyte *dbytes = elements (p->getData());
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
- memcpy (&u.address.sin_addr, bytes, len);
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (rport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (rport);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (::sendto (fnum, (char *) dbytes, p->getLength(), 0, ptr, len) >= 0)
- return;
-
- DWORD dwErrorCode = WSAGetLastError ();
- if (dwErrorCode == WSAECONNRESET)
- throw new PortUnreachableException (_Jv_WinStrError (dwErrorCode));
-
- _Jv_ThrowIOException ();
-}
-
-void
-java::net::PlainDatagramSocketImpl::receive (java::net::DatagramPacket *p)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- jbyte *dbytes = elements (p->getData());
- ssize_t retlen = 0;
-
- if (timeout > 0)
- {
- // This implementation doesn't allow specifying an infinite
- // timeout after specifying a finite one, but Sun's JDK 1.4.1
- // didn't seem to allow this either....
- int nRet= ::setsockopt(fnum, SOL_SOCKET, SO_RCVTIMEO,
- (char*)&timeout, sizeof(timeout));
- if (nRet != NO_ERROR)
- goto error;
- }
-
- retlen =
- ::recvfrom (fnum, (char *) dbytes, p->getLength(), 0, (sockaddr*) &u,
- &addrlen);
- if (retlen < 0)
- goto error;
- // FIXME: Deal with Multicast addressing and if the socket is connected.
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
-
- p->setAddress (new InetAddress (raddr, NULL));
- p->setPort (rport);
- p->setLength ((jint) retlen);
- return;
-
- error:
- DWORD dwErrorCode = WSAGetLastError();
- if (dwErrorCode == WSAECONNRESET)
- throw new PortUnreachableException (_Jv_WinStrError (dwErrorCode));
- else if (dwErrorCode == WSAETIMEDOUT)
- throw new java::net::SocketTimeoutException (_Jv_WinStrError (dwErrorCode));
- else
- throw new java::io::IOException (_Jv_WinStrError (dwErrorCode));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setTimeToLive (jint ttl)
-{
- // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
- char val = (char) ttl;
- socklen_t val_len = sizeof(val);
-
- if (::setsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, val_len) == 0)
- return;
-
- _Jv_ThrowIOException ();
-}
-
-jint
-java::net::PlainDatagramSocketImpl::getTimeToLive ()
-{
- // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
- char val;
- socklen_t val_len = sizeof(val);
-
- if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, &val_len) == 0)
- return ((int) val) & 0xFF;
-
- _Jv_ThrowIOException ();
-
- return -1;
- // we should never get here
-}
-
-void
-java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *inetaddr,
- java::net::NetworkInterface *,
- jboolean)
-{
- // FIXME: implement use of NetworkInterface
- jbyteArray haddress = inetaddr->addr;
- int len = haddress->length;
- int level, opname;
- const char *ptr;
- if (0)
- ;
-#if HAVE_STRUCT_IP_MREQ
- else if (len == 4)
- {
- level = IPPROTO_IP;
- opname = join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP;
- memcpy (&u.mreq.imr_multiaddr, bytes, len);
- // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
- // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
- u.mreq.imr_interface.s_addr = htonl (INADDR_ANY);
- len = sizeof (struct ip_mreq);
- ptr = (const char *) &u.mreq;
- }
-#endif
-#if HAVE_STRUCT_IPV6_MREQ
- else if (len == 16)
- {
- level = IPPROTO_IPV6;
-
- /* Prefer new RFC 2553 names. */
-#ifndef IPV6_JOIN_GROUP
-#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
-#endif
-#ifndef IPV6_LEAVE_GROUP
-#define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
-#endif
-
- opname = join ? IPV6_JOIN_GROUP : IPV6_LEAVE_GROUP;
- memcpy (&u.mreq6.ipv6mr_multiaddr, bytes, len);
- // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
- // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
- u.mreq6.ipv6mr_interface = 0;
- len = sizeof (struct ipv6_mreq);
- ptr = (const char *) &u.mreq6;
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (::setsockopt (fnum, level, opname, ptr, len) == 0)
- return;
-
- _Jv_ThrowIOException ();
-}
-
-void
-java::net::PlainDatagramSocketImpl::setOption (jint optID,
- java::lang::Object *value)
-{
- int val;
- socklen_t val_len = sizeof (val);
-
- if (fnum < 0)
- throw new java::net::SocketException (JvNewStringUTF ("Socket closed"));
-
- if (_Jv_IsInstanceOf (value, &java::lang::Boolean::class$))
- {
- java::lang::Boolean *boolobj =
- static_cast<java::lang::Boolean *> (value);
- val = boolobj->booleanValue() ? 1 : 0;
- }
- else if (_Jv_IsInstanceOf (value, &java::lang::Integer::class$))
- {
- java::lang::Integer *intobj =
- static_cast<java::lang::Integer *> (value);
- val = (int) intobj->intValue();
- }
- // Else assume value to be an InetAddress for use with IP_MULTICAST_IF.
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("TCP_NODELAY not valid for UDP"));
- return;
- case _Jv_SO_LINGER_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_LINGER not valid for UDP"));
- return;
- case _Jv_SO_KEEPALIVE_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
- return;
-
- case _Jv_SO_BROADCAST_ :
- if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
- val_len) != 0)
- goto error;
- break;
-
- case _Jv_SO_OOBINLINE_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_OOBINLINE: not valid for UDP"));
- break;
-
- case _Jv_SO_SNDBUF_ :
- case _Jv_SO_RCVBUF_ :
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
- goto error;
- return;
- case _Jv_SO_REUSEADDR_ :
- if (::setsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
- val_len) != 0)
- goto error;
- return;
- case _Jv_SO_BINDADDR_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_BINDADDR: read only option"));
- return;
- case _Jv_IP_MULTICAST_IF_ :
- union InAddr u;
- jbyteArray haddress;
- jbyte *bytes;
- int len;
- int level, opname;
- const char *ptr;
-
- haddress = ((java::net::InetAddress *) value)->addr;
- bytes = elements (haddress);
- len = haddress->length;
- if (len == 4)
- {
- level = IPPROTO_IP;
- opname = IP_MULTICAST_IF;
- memcpy (&u.addr, bytes, len);
- len = sizeof (struct in_addr);
- ptr = (const char *) &u.addr;
- }
-// Tru64 UNIX V5.0 has struct sockaddr_in6, but no IPV6_MULTICAST_IF
-#if defined (HAVE_INET6) && defined (IPV6_MULTICAST_IF)
- else if (len == 16)
- {
- level = IPPROTO_IPV6;
- opname = IPV6_MULTICAST_IF;
- memcpy (&u.addr6, bytes, len);
- len = sizeof (struct in6_addr);
- ptr = (const char *) &u.addr6;
- }
-#endif
- else
- throw
- new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (::setsockopt (fnum, level, opname, ptr, len) != 0)
- goto error;
- return;
-
- case _Jv_IP_MULTICAST_IF2_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
- break;
-
- case _Jv_IP_MULTICAST_LOOP_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_LOOP: not yet implemented"));
- break;
-
- case _Jv_IP_TOS_ :
- if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
- val_len) != 0)
- goto error;
- return;
-
- case _Jv_SO_TIMEOUT_ :
- timeout = val;
- return;
- default :
- WSASetLastError (WSAENOPROTOOPT);
- }
-
- error:
- _Jv_ThrowSocketException ();
-}
-
-java::lang::Object *
-java::net::PlainDatagramSocketImpl::getOption (jint optID)
-{
- int val;
- socklen_t val_len = sizeof(val);
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("TCP_NODELAY not valid for UDP"));
- break;
- case _Jv_SO_LINGER_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_LINGER not valid for UDP"));
- break;
- case _Jv_SO_KEEPALIVE_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
- break;
-
- case _Jv_SO_BROADCAST_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean (val != 0);
-
- case _Jv_SO_OOBINLINE_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_OOBINLINE not valid for UDP"));
- break;
-
- case _Jv_SO_RCVBUF_ :
- case _Jv_SO_SNDBUF_ :
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
- goto error;
- else
- return new java::lang::Integer (val);
- break;
- case _Jv_SO_BINDADDR_:
- // cache the local address
- if (localAddress == NULL)
- {
- jbyteArray laddr;
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
- goto error;
- if (u.address.sin_family == AF_INET)
- {
- laddr = JvNewByteArray (4);
- memcpy (elements (laddr), &u.address.sin_addr, 4);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- laddr = JvNewByteArray (16);
- memcpy (elements (laddr), &u.address6.sin6_addr, 16);
- }
-#endif
- else
- throw new java::net::SocketException (
- JvNewStringUTF ("invalid family"));
- localAddress = new java::net::InetAddress (laddr, NULL);
- }
- return localAddress;
- break;
- case _Jv_SO_REUSEADDR_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean (val != 0);
- break;
- case _Jv_IP_MULTICAST_IF_ :
- struct in_addr inaddr;
- socklen_t inaddr_len;
- char *bytes;
-
- inaddr_len = sizeof(inaddr);
- if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_IF, (char *) &inaddr,
- &inaddr_len) != 0)
- goto error;
-
- bytes = inet_ntoa (inaddr);
-
- return java::net::InetAddress::getByName (JvNewStringLatin1 (bytes));
- break;
- case _Jv_SO_TIMEOUT_ :
- return new java::lang::Integer (timeout);
- break;
-
- case _Jv_IP_MULTICAST_IF2_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
- break;
-
- case _Jv_IP_MULTICAST_LOOP_ :
- if (::getsockopt (fnum, SOL_SOCKET, IP_MULTICAST_LOOP, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean (val != 0);
-
- case _Jv_IP_TOS_ :
- if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Integer (val);
-
- default :
- WSASetLastError (WSAENOPROTOOPT);
- }
-
-error:
- _Jv_ThrowSocketException ();
- return 0;
- // we should never get here
-}
+++ /dev/null
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-
-#include <java/io/IOException.h>
-#include <java/net/BindException.h>
-#include <java/net/ConnectException.h>
-#include <java/net/PlainSocketImpl.h>
-#include <java/net/SocketException.h>
-
-void
-java::net::PlainSocketImpl::create (jboolean)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("SocketImpl.create: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::bind (java::net::InetAddress *, jint)
-{
- throw new BindException (
- JvNewStringLatin1 ("SocketImpl.bind: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::connect (java::net::SocketAddress *, jint)
-{
- throw new ConnectException (
- JvNewStringLatin1 ("SocketImpl.connect: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::listen (jint)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("SocketImpl.listen: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *)
-{
- throw new java::io::IOException (
- JvNewStringLatin1 ("SocketImpl.accept: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::setOption (jint, java::lang::Object *)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.setOption: unimplemented"));
-}
-
-java::lang::Object *
-java::net::PlainSocketImpl::getOption (jint)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.getOption: unimplemented"));
-}
-
-jint
-java::net::PlainSocketImpl::read(void)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.read: unimplemented"));
-}
-
-jint
-java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.read: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::write(jint b)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::sendUrgentData(jint data)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.sendUrgentData: unimplemented"));
-}
-
-jint
-java::net::PlainSocketImpl::available(void)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.available: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::close(void)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.close: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::shutdownInput (void)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.shutdownInput: unimplemented"));
-}
-
-void
-java::net::PlainSocketImpl::shutdownOutput (void)
-{
- throw new SocketException (
- JvNewStringLatin1 ("SocketImpl.shutdownOutput: unimplemented"));
-}
+++ /dev/null
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-
-#ifdef HAVE_SYS_IOCTL_H
-#define BSD_COMP /* Get FIONREAD on Solaris2. */
-#include <sys/ioctl.h>
-#endif
-
-// Pick up FIONREAD on Solaris 2.5.
-#ifdef HAVE_SYS_FILIO_H
-#include <sys/filio.h>
-#endif
-
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <errno.h>
-#include <string.h>
-
-#if HAVE_BSTRING_H
-// Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
-#include <bstring.h>
-#endif
-
-#include <gcj/cni.h>
-#include <gcj/javaprims.h>
-#include <java/io/IOException.h>
-#include <java/io/InterruptedIOException.h>
-#include <java/net/BindException.h>
-#include <java/net/ConnectException.h>
-#include <java/net/PlainSocketImpl.h>
-#include <java/net/InetAddress.h>
-#include <java/net/InetSocketAddress.h>
-#include <java/net/SocketException.h>
-#include <java/net/SocketTimeoutException.h>
-#include <java/lang/InternalError.h>
-#include <java/lang/Object.h>
-#include <java/lang/Boolean.h>
-#include <java/lang/Class.h>
-#include <java/lang/Integer.h>
-#include <java/lang/Thread.h>
-#include <java/lang/NullPointerException.h>
-#include <java/lang/ArrayIndexOutOfBoundsException.h>
-#include <java/lang/IllegalArgumentException.h>
-
-union SockAddr
-{
- struct sockaddr_in address;
-#ifdef HAVE_INET6
- struct sockaddr_in6 address6;
-#endif
-};
-
-void
-java::net::PlainSocketImpl::create (jboolean stream)
-{
- int sock = _Jv_socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
-
- if (sock < 0)
- {
- char* strerr = strerror (errno);
- throw new java::io::IOException (JvNewStringUTF (strerr));
- }
-
- _Jv_platform_close_on_exec (sock);
-
- // We use fnum in place of fd here. From leaving fd null we avoid
- // the double close problem in FileDescriptor.finalize.
- fnum = sock;
-}
-
-void
-java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
-{
- union SockAddr u;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- jbyteArray haddress = host->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- int i = 1;
-
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
-
- if (host != NULL)
- memcpy (&u.address.sin_addr, bytes, len);
- else
- u.address.sin_addr.s_addr = htonl (INADDR_ANY);
-
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (lport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (lport);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- // Enable SO_REUSEADDR, so that servers can reuse ports left in TIME_WAIT.
- ::setsockopt(fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof(i));
-
- if (_Jv_bind (fnum, ptr, len) == 0)
- {
- address = host;
- socklen_t addrlen = sizeof(u);
-
- if (lport != 0)
- localport = lport;
- else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
- localport = ntohs (u.address.sin_port);
- else
- goto error;
-
- return;
- }
-
- error:
- char* strerr = strerror (errno);
- throw new java::net::BindException (JvNewStringUTF (strerr));
-}
-
-void
-java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr,
- jint timeout)
-{
- java::net::InetSocketAddress *tmp = (java::net::InetSocketAddress*) addr;
- java::net::InetAddress *host = tmp->getAddress();
- jint rport = tmp->getPort();
-
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- jbyteArray haddress = host->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
- memcpy (&u.address.sin_addr, bytes, len);
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (rport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (rport);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (timeout > 0)
- {
- int flags = ::fcntl (fnum, F_GETFL);
- ::fcntl (fnum, F_SETFL, flags | O_NONBLOCK);
-
- if ((_Jv_connect (fnum, ptr, len) != 0) && (errno != EINPROGRESS))
- goto error;
-
- fd_set fset;
- struct timeval tv;
- FD_ZERO(&fset);
- FD_SET(fnum, &fset);
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
- int retval;
-
- if ((retval = _Jv_select (fnum + 1, &fset, &fset, NULL, &tv)) < 0)
- goto error;
- else if (retval == 0)
- throw new java::net::SocketTimeoutException
- (JvNewStringUTF ("Connect timed out"));
- // Set the socket back into a blocking state.
- ::fcntl (fnum, F_SETFL, flags);
- }
- else
- {
- if (_Jv_connect (fnum, ptr, len) != 0)
- goto error;
- }
-
- address = host;
- port = rport;
-
- // A bind may not have been done on this socket; if so, set localport now.
- if (localport == 0)
- {
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
- localport = ntohs (u.address.sin_port);
- else
- goto error;
- }
-
- return;
-
- error:
- char* strerr = strerror (errno);
- throw new java::net::ConnectException (JvNewStringUTF (strerr));
-}
-
-void
-java::net::PlainSocketImpl::listen (jint backlog)
-{
- if (::listen (fnum, backlog) != 0)
- {
- char* strerr = strerror (errno);
- throw new java::io::IOException (JvNewStringUTF (strerr));
- }
-}
-
-void
-java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s)
-{
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- int new_socket = 0;
-
- // Do timeouts via select since SO_RCVTIMEO is not always available.
- if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
- {
- fd_set fset;
- struct timeval tv;
- FD_ZERO(&fset);
- FD_SET(fnum, &fset);
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
- int retval;
- if ((retval = _Jv_select (fnum + 1, &fset, &fset, NULL, &tv)) < 0)
- goto error;
- else if (retval == 0)
- throw new java::net::SocketTimeoutException (
- JvNewStringUTF("Accept timed out"));
- }
-
- new_socket = _Jv_accept (fnum, (sockaddr*) &u, &addrlen);
-
- if (new_socket < 0)
- goto error;
-
- _Jv_platform_close_on_exec (new_socket);
-
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
-
- s->fnum = new_socket;
- s->localport = localport;
- s->address = new InetAddress (raddr, NULL);
- s->port = rport;
- return;
-
- error:
- char* strerr = strerror (errno);
- throw new java::io::IOException (JvNewStringUTF (strerr));
-}
-
-// Close(shutdown) the socket.
-void
-java::net::PlainSocketImpl::close()
-{
- // Avoid races from asynchronous finalization.
- JvSynchronize sync (this);
-
- // should we use shutdown here? how would that effect so_linger?
- int res = _Jv_close (fnum);
-
- if (res == -1)
- {
- // These three errors are not errors according to tests performed
- // on the reference implementation.
- if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
- throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
- }
- // Safe place to reset the file pointer.
- fnum = -1;
- timeout = 0;
-}
-
-// Write a byte to the socket.
-void
-java::net::PlainSocketImpl::write(jint b)
-{
- jbyte d =(jbyte) b;
- int r = 0;
-
- while (r != 1)
- {
- r = _Jv_write (fnum, &d, 1);
- if (r == -1)
- {
- if (java::lang::Thread::interrupted())
- {
- java::io::InterruptedIOException *iioe
- = new java::io::InterruptedIOException
- (JvNewStringLatin1 (strerror (errno)));
- iioe->bytesTransferred = 0;
- throw iioe;
- }
- // Some errors should not cause exceptions.
- if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
- throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
- break;
- }
- }
-}
-
-// Write some bytes to the socket.
-void
-java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
-{
- if (! b)
- throw new java::lang::NullPointerException;
- if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
- throw new java::lang::ArrayIndexOutOfBoundsException;
-
- jbyte *bytes = elements (b) + offset;
- int written = 0;
-
- while (len > 0)
- {
- int r = _Jv_write (fnum, bytes, len);
-
- if (r == -1)
- {
- if (java::lang::Thread::interrupted())
- {
- java::io::InterruptedIOException *iioe
- = new java::io::InterruptedIOException
- (JvNewStringLatin1 (strerror (errno)));
- iioe->bytesTransferred = written;
- throw iioe;
- }
- // Some errors should not cause exceptions.
- if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
- throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
- break;
- }
-
- written += r;
- len -= r;
- bytes += r;
- }
-}
-
-void
-java::net::PlainSocketImpl::sendUrgentData (jint)
-{
- throw new SocketException (JvNewStringLatin1 (
- "PlainSocketImpl: sending of urgent data not supported by this socket"));
-}
-
-// Read a single byte from the socket.
-jint
-java::net::PlainSocketImpl::read(void)
-{
- jbyte b;
-
- // Do timeouts via select.
- if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
- {
- // Create the file descriptor set.
- fd_set read_fds;
- FD_ZERO (&read_fds);
- FD_SET (fnum,&read_fds);
- // Create the timeout struct based on our internal timeout value.
- struct timeval timeout_value;
- timeout_value.tv_sec = timeout / 1000;
- timeout_value.tv_usec = (timeout % 1000) * 1000;
- // Select on the fds.
- int sel_retval =
- _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
- // If select returns 0 we've waited without getting data...
- // that means we've timed out.
- if (sel_retval == 0)
- throw new java::net::SocketTimeoutException
- (JvNewStringUTF ("read timed out") );
- // If select returns ok we know we either got signalled or read some data...
- // either way we need to try to read.
- }
-
- int r = _Jv_read (fnum, &b, 1);
-
- if (r == 0)
- return -1;
-
- if (java::lang::Thread::interrupted())
- {
- java::io::InterruptedIOException *iioe =
- new java::io::InterruptedIOException
- (JvNewStringUTF("read interrupted"));
- iioe->bytesTransferred = r == -1 ? 0 : r;
- throw iioe;
- }
- else if (r == -1)
- {
- // Some errors cause us to return end of stream...
- if (errno == ENOTCONN)
- return -1;
-
- // Other errors need to be signalled.
- throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
- }
-
- return b & 0xFF;
-}
-
-// Read count bytes into the buffer, starting at offset.
-jint
-java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
-{
- if (! buffer)
- throw new java::lang::NullPointerException;
-
- jsize bsize = JvGetArrayLength (buffer);
-
- if (offset < 0 || count < 0 || offset + count > bsize)
- throw new java::lang::ArrayIndexOutOfBoundsException;
-
- jbyte *bytes = elements (buffer) + offset;
-
- // Do timeouts via select.
- if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
- {
- // Create the file descriptor set.
- fd_set read_fds;
- FD_ZERO (&read_fds);
- FD_SET (fnum, &read_fds);
- // Create the timeout struct based on our internal timeout value.
- struct timeval timeout_value;
- timeout_value.tv_sec = timeout / 1000;
- timeout_value.tv_usec =(timeout % 1000) * 1000;
- // Select on the fds.
- int sel_retval =
- _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
- // We're only interested in the 0 return.
- // error returns still require us to try to read
- // the socket to see what happened.
- if (sel_retval == 0)
- {
- java::net::SocketTimeoutException *timeoutException =
- new java::net::SocketTimeoutException
- (JvNewStringUTF ("read timed out"));
- throw timeoutException;
- }
- }
-
- // Read the socket.
- int r = ::recv (fnum, (char *) bytes, count, 0);
-
- if (r == 0)
- return -1;
-
- if (java::lang::Thread::interrupted())
- {
- java::io::InterruptedIOException *iioe =
- new java::io::InterruptedIOException
- (JvNewStringUTF ("read interrupted"));
- iioe->bytesTransferred = r == -1 ? 0 : r;
- throw iioe;
- }
- else if (r == -1)
- {
- // Some errors cause us to return end of stream...
- if (errno == ENOTCONN)
- return -1;
-
- // Other errors need to be signalled.
- throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
- }
-
- return r;
-}
-
-// How many bytes are available?
-jint
-java::net::PlainSocketImpl::available(void)
-{
-#if defined(FIONREAD) || defined(HAVE_SELECT)
- long num = 0;
- int r = 0;
- bool num_set = false;
-
-#if defined(FIONREAD)
- r = ::ioctl (fnum, FIONREAD, &num);
-
- if (r == -1 && errno == ENOTTY)
- {
- // If the ioctl doesn't work, we don't care.
- r = 0;
- num = 0;
- }
- else
- num_set = true;
-#elif defined(HAVE_SELECT)
- if (fnum < 0)
- {
- errno = EBADF;
- r = -1;
- }
-#endif
-
- if (r == -1)
- {
- posix_error:
- throw new java::io::IOException(JvNewStringUTF(strerror(errno)));
- }
-
- // If we didn't get anything we can use select.
-
-#if defined(HAVE_SELECT)
- if (! num_set)
- if (! num_set && fnum >= 0 && fnum < FD_SETSIZE)
- {
- fd_set rd;
- FD_ZERO (&rd);
- FD_SET (fnum, &rd);
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- r = _Jv_select (fnum + 1, &rd, NULL, NULL, &tv);
- if(r == -1)
- goto posix_error;
- num = r == 0 ? 0 : 1;
- }
-#endif /* HAVE_SELECT */
-
- return (jint) num;
-#else
- throw new java::io::IOException (JvNewStringUTF ("unimplemented"));
-#endif
-}
-
-void
-java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
-{
- int val;
- socklen_t val_len = sizeof (val);
-
- if (fnum < 0)
- throw new java::net::SocketException (JvNewStringUTF ("Socket closed"));
-
- if (_Jv_IsInstanceOf (value, &java::lang::Boolean::class$))
- {
- java::lang::Boolean *boolobj =
- static_cast<java::lang::Boolean *> (value);
- if (boolobj->booleanValue())
- val = 1;
- else
- {
- if (optID == _Jv_SO_LINGER_)
- val = -1;
- else
- val = 0;
- }
- }
- else if (_Jv_IsInstanceOf (value, &java::lang::Integer::class$))
- {
- java::lang::Integer *intobj =
- static_cast<java::lang::Integer *> (value);
- val = (int) intobj->intValue();
- }
- else
- {
- throw new java::lang::IllegalArgumentException (
- JvNewStringLatin1 ("`value' must be Boolean or Integer"));
- }
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
-#ifdef TCP_NODELAY
- if (::setsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
- val_len) != 0)
- goto error;
-#else
- throw new java::lang::InternalError
- (JvNewStringUTF ("TCP_NODELAY not supported"));
-#endif /* TCP_NODELAY */
- return;
-
- case _Jv_SO_KEEPALIVE_ :
- if (::setsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
- val_len) != 0)
- goto error;
- break;
-
- case _Jv_SO_BROADCAST_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
- break;
-
- case _Jv_SO_OOBINLINE_ :
- if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
- val_len) != 0)
- goto error;
- break;
-
- case _Jv_SO_LINGER_ :
-#ifdef SO_LINGER
- struct linger l_val;
- l_val.l_onoff = (val != -1);
- l_val.l_linger = val;
-
- if (::setsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
- sizeof(l_val)) != 0)
- goto error;
-#else
- throw new java::lang::InternalError (
- JvNewStringUTF ("SO_LINGER not supported"));
-#endif /* SO_LINGER */
- return;
-
- case _Jv_SO_SNDBUF_ :
- case _Jv_SO_RCVBUF_ :
-#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
- goto error;
-#else
- throw new java::lang::InternalError (
- JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
-#endif
- return;
-
- case _Jv_SO_BINDADDR_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_BINDADDR: read only option"));
- return;
-
- case _Jv_IP_MULTICAST_IF_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
- return;
-
- case _Jv_IP_MULTICAST_IF2_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
- break;
-
- case _Jv_IP_MULTICAST_LOOP_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
- break;
-
- case _Jv_IP_TOS_ :
- if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
- val_len) != 0)
- goto error;
- break;
-
- case _Jv_SO_REUSEADDR_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
- return;
-
- case _Jv_SO_TIMEOUT_ :
- timeout = val;
- return;
-
- default :
- errno = ENOPROTOOPT;
- }
-
- error:
- char* strerr = strerror (errno);
- throw new java::net::SocketException (JvNewStringUTF (strerr));
-}
-
-java::lang::Object *
-java::net::PlainSocketImpl::getOption (jint optID)
-{
- int val;
- socklen_t val_len = sizeof(val);
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- struct linger l_val;
- socklen_t l_val_len = sizeof(l_val);
-
- switch (optID)
- {
-#ifdef TCP_NODELAY
- case _Jv_TCP_NODELAY_ :
- if (::getsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
- &val_len) != 0)
- goto error;
- else
- return new java::lang::Boolean (val != 0);
-#else
- throw new java::lang::InternalError
- (JvNewStringUTF ("TCP_NODELAY not supported"));
-#endif
- break;
-
- case _Jv_SO_LINGER_ :
-#ifdef SO_LINGER
- if (::getsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
- &l_val_len) != 0)
- goto error;
-
- if (l_val.l_onoff)
- return new java::lang::Integer (l_val.l_linger);
- else
- return new java::lang::Boolean ((jboolean)false);
-#else
- throw new java::lang::InternalError
- (JvNewStringUTF ("SO_LINGER not supported"));
-#endif
- break;
-
- case _Jv_SO_KEEPALIVE_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
- &val_len) != 0)
- goto error;
- else
- return new java::lang::Boolean (val != 0);
-
- case _Jv_SO_BROADCAST_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean ((jboolean)val);
-
- case _Jv_SO_OOBINLINE_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean ((jboolean)val);
-
- case _Jv_SO_RCVBUF_ :
- case _Jv_SO_SNDBUF_ :
-#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
- goto error;
- else
- return new java::lang::Integer (val);
-#else
- throw new java::lang::InternalError
- (JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
-#endif
- break;
- case _Jv_SO_BINDADDR_:
- // cache the local address
- if (localAddress == NULL)
- {
- jbyteArray laddr;
-
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
- goto error;
-
- if (u.address.sin_family == AF_INET)
- {
- laddr = JvNewByteArray (4);
- memcpy (elements (laddr), &u.address.sin_addr, 4);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- laddr = JvNewByteArray (16);
- memcpy (elements (laddr), &u.address6.sin6_addr, 16);
- }
-#endif
- else
- throw new java::net::SocketException
- (JvNewStringUTF ("invalid family"));
- localAddress = new java::net::InetAddress (laddr, NULL);
- }
-
- return localAddress;
- break;
- case _Jv_IP_MULTICAST_IF_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
- break;
-
- case _Jv_IP_MULTICAST_IF2_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
- break;
-
- case _Jv_IP_MULTICAST_LOOP_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
- break;
-
- case _Jv_IP_TOS_ :
- if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Integer (val);
- break;
-
- case _Jv_SO_REUSEADDR_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
- break;
-
- case _Jv_SO_TIMEOUT_ :
- return new java::lang::Integer (timeout);
- break;
-
- default :
- errno = ENOPROTOOPT;
- }
-
- error:
- char* strerr = strerror (errno);
- throw new java::net::SocketException (JvNewStringUTF (strerr));
-}
-
-void
-java::net::PlainSocketImpl::shutdownInput (void)
-{
- if (::shutdown (fnum, 0))
- throw new SocketException (JvNewStringUTF (strerror (errno)));
-}
-
-void
-java::net::PlainSocketImpl::shutdownOutput (void)
-{
- if (::shutdown (fnum, 1))
- throw new SocketException (JvNewStringUTF (strerror (errno)));
-}
+++ /dev/null
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-
-#undef STRICT
-#undef MAX_PRIORITY
-#undef MIN_PRIORITY
-
-#include <java/io/IOException.h>
-#include <java/io/InterruptedIOException.h>
-#include <java/net/BindException.h>
-#include <java/net/ConnectException.h>
-#include <java/net/PlainSocketImpl.h>
-#include <java/net/InetAddress.h>
-#include <java/net/InetSocketAddress.h>
-#include <java/net/SocketException.h>
-#include <java/net/SocketTimeoutException.h>
-#include <java/lang/InternalError.h>
-#include <java/lang/Object.h>
-#include <java/lang/Boolean.h>
-#include <java/lang/Class.h>
-#include <java/lang/Integer.h>
-#include <java/lang/Thread.h>
-#include <java/lang/NullPointerException.h>
-#include <java/lang/ArrayIndexOutOfBoundsException.h>
-#include <java/lang/IllegalArgumentException.h>
-
-union SockAddr
-{
- struct sockaddr_in address;
-#ifdef HAVE_INET6
- struct sockaddr_in6 address6;
-#endif
-};
-
-void
-java::net::PlainSocketImpl::create (jboolean stream)
-{
- int sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
-
- if (sock == int(INVALID_SOCKET))
- {
- _Jv_ThrowIOException ();
- }
-
- _Jv_platform_close_on_exec (sock);
-
- // We use fnum in place of fd here. From leaving fd null we avoid
- // the double close problem in FileDescriptor.finalize.
- fnum = sock;
-}
-
-void
-java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
-{
- union SockAddr u;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- jbyteArray haddress = host->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- int i = 1;
-
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
-
- if (host != NULL)
- memcpy (&u.address.sin_addr, bytes, len);
- else
- u.address.sin_addr.s_addr = htonl (INADDR_ANY);
-
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (lport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (lport);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- // Enable SO_REUSEADDR, so that servers can reuse ports left in TIME_WAIT.
- ::setsockopt(fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof(i));
-
- if (::bind (fnum, ptr, len) != SOCKET_ERROR)
- {
- address = host;
- socklen_t addrlen = sizeof(u);
-
- if (lport != 0)
- localport = lport;
- else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != SOCKET_ERROR)
- localport = ntohs (u.address.sin_port);
- else
- goto error;
-
- return;
- }
-
-error:
- DWORD dwErrorCode = WSAGetLastError ();
- throw new java::net::BindException (_Jv_WinStrError (dwErrorCode));
-}
-
-static void
-throwConnectException (DWORD dwErrorCode)
-{
- throw new java::net::ConnectException (_Jv_WinStrError (dwErrorCode));
-}
-
-static void
-throwConnectException ()
-{
- throwConnectException (WSAGetLastError ());
-}
-
-void
-java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr,
- jint timeout)
-{
- java::net::InetSocketAddress *tmp = (java::net::InetSocketAddress*) addr;
- java::net::InetAddress *host = tmp->getAddress();
- jint rport = tmp->getPort();
-
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- jbyteArray haddress = host->addr;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
-
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
- memcpy (&u.address.sin_addr, bytes, len);
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (rport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (rport);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
-
- if (timeout > 0)
- {
- // FIXME: we're creating a fresh WSAEVENT for each connect().
- WSAEventWrapper aWSAEventWrapper(fnum, FD_CONNECT);
- WSAEVENT hEvent = aWSAEventWrapper.getEventHandle ();
-
- if (::connect (fnum, ptr, len) == SOCKET_ERROR)
- {
- if (WSAGetLastError () != WSAEWOULDBLOCK)
- throwConnectException ();
-
- DWORD dwRet =
- WSAWaitForMultipleEvents (1, &hEvent, true, timeout, false);
- // use true, false instead of TRUE, FALSE because the
- // MS constants got undefined
-
- if (dwRet == WSA_WAIT_FAILED)
- throwConnectException ();
-
- else if (dwRet == WSA_WAIT_TIMEOUT)
- throw new java::net::SocketTimeoutException
- (JvNewStringUTF ("connect timed out"));
-
- // If we get here, we still need to check whether the actual
- // connect() succeeded. Use any socket-specific error code
- // instead of the thread-based one.
- int nErrCode; int nErrLen=sizeof(nErrCode);
- if (::getsockopt(fnum, SOL_SOCKET, SO_ERROR, (char*) &nErrCode,
- &nErrLen) == SOCKET_ERROR)
- {
- throwConnectException ();
- }
-
- if (nErrCode != NO_ERROR)
- {
- throwConnectException (nErrCode);
- }
- }
- }
- else
- {
- if (::connect (fnum, ptr, len) == SOCKET_ERROR)
- throwConnectException();
- }
-
- address = host;
- port = rport;
-
- // A bind may not have been done on this socket; if so, set localport now.
- if (localport == 0)
- {
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != SOCKET_ERROR)
- localport = ntohs (u.address.sin_port);
- else
- throwConnectException();
- }
-}
-
-void
-java::net::PlainSocketImpl::listen (jint backlog)
-{
- if (::listen (fnum, backlog) == SOCKET_ERROR)
- {
- _Jv_ThrowIOException ();
- }
-}
-
-void
-java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s)
-{
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- int new_socket = 0;
-
- if (timeout > 0)
- {
- // FIXME: we're creating a fresh WSAEVENT for each accept().
- // One possible alternative would be that fnum really points
- // to an extended structure consisting of the SOCKET, its
- // associated WSAEVENT, etc.
- WSAEventWrapper aWSAEventWrapper(fnum, FD_ACCEPT);
- WSAEVENT hEvent = aWSAEventWrapper.getEventHandle ();
-
- for (;;)
- {
- new_socket = ::accept (fnum, (sockaddr*) &u, &addrlen);
-
- if (new_socket != int(INVALID_SOCKET))
- {
- // This new child socket is nonblocking because the parent
- // socket became nonblocking via the WSAEventSelect() call,
- // so we set its mode back to blocking.
- WSAEventSelect (new_socket, hEvent, 0);
- // undo the hEvent <-> FD_ACCEPT association inherited
- // inherited from our parent socket
-
- unsigned long lSockOpt = 0L;
- // blocking mode
- if (ioctlsocket(new_socket, FIONBIO, &lSockOpt) == SOCKET_ERROR)
- {
- goto error;
- }
- break;
- }
- else if (WSAGetLastError () != WSAEWOULDBLOCK)
- {
- goto error;
- }
-
- DWORD dwRet =
- WSAWaitForMultipleEvents (1, &hEvent, true, timeout, false);
- // use true, false instead of TRUE, FALSE because the
- // MS constants got undefined
-
- if (dwRet == WSA_WAIT_FAILED)
- goto error;
- else if (dwRet == WSA_WAIT_TIMEOUT)
- throw new java::net::SocketTimeoutException
- (JvNewStringUTF ("accept timed out"));
- }
- }
- else
- {
- new_socket = ::accept (fnum, (sockaddr*) &u, &addrlen);
- }
-
- if (new_socket == int(INVALID_SOCKET))
- goto error;
-
- _Jv_platform_close_on_exec (new_socket);
-
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
-
- s->fnum = new_socket;
- s->localport = localport;
- s->address = new InetAddress (raddr, NULL);
- s->port = rport;
- return;
-
- error:
- _Jv_ThrowIOException ();
-}
-
-// Close(shutdown) the socket.
-void
-java::net::PlainSocketImpl::close()
-{
- // Avoid races from asynchronous finalization.
- JvSynchronize sync (this);
-
- // should we use shutdown here? how would that effect so_linger?
- int res = ::closesocket (fnum);
-
- if (res == -1)
- {
- // These three errors are not errors according to tests performed
- // on the reference implementation.
- DWORD dwErr = WSAGetLastError();
- if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
- && dwErr != WSAENOTSOCK)
- _Jv_ThrowIOException ();
- }
- // Safe place to reset the file pointer.
- fnum = -1;
- timeout = 0;
-}
-
-// Write a byte to the socket.
-void
-java::net::PlainSocketImpl::write(jint b)
-{
- jbyte d =(jbyte) b;
- int r = 0;
-
- while (r != 1)
- {
- r = ::send (fnum, (char*) &d, 1, 0);
- if (r == -1)
- {
- DWORD dwErr = WSAGetLastError();
- if (java::lang::Thread::interrupted())
- {
- java::io::InterruptedIOException *iioe
- = new java::io::InterruptedIOException
- (_Jv_WinStrError (dwErr));
- iioe->bytesTransferred = 0;
- throw iioe;
- }
- // Some errors should not cause exceptions.
- if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
- && dwErr != WSAENOTSOCK)
- _Jv_ThrowIOException ();
- break;
- }
- }
-}
-
-// Write some bytes to the socket.
-void
-java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
-{
- if (! b)
- throw new java::lang::NullPointerException;
- if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
- throw new java::lang::ArrayIndexOutOfBoundsException;
-
- jbyte *bytes = elements (b) + offset;
- int written = 0;
- while (len > 0)
- {
- int r = ::send (fnum, (char*) bytes, len, 0);
-
- if (r == -1)
- {
- DWORD dwErr = WSAGetLastError();
- if (java::lang::Thread::interrupted())
- {
- java::io::InterruptedIOException *iioe
- = new java::io::InterruptedIOException
- (_Jv_WinStrError (dwErr));
- iioe->bytesTransferred = written;
- throw iioe;
- }
- // Some errors should not cause exceptions.
- if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
- && dwErr != WSAENOTSOCK)
- _Jv_ThrowIOException ();
- break;
- }
-
- written += r;
- len -= r;
- bytes += r;
- }
-}
-
-void
-java::net::PlainSocketImpl::sendUrgentData (jint)
-{
- throw new SocketException (JvNewStringLatin1 (
- "PlainSocketImpl: sending of urgent data not supported by this socket"));
-}
-
-// read() helper
-static jint
-doRead(int fnum, void* buf, int count, int timeout)
-{
- int r = 0;
- DWORD dwErrorCode = 0;
- // we are forced to declare this here because
- // a call to Thread::interrupted() blanks out
- // WSAGetLastError().
-
- // FIXME: we unconditionally set SO_RCVTIMEO here
- // because we can't detect whether someone has
- // gone from a non-zero to zero timeout. What we'd
- // really need is a member state variable in addition
- // to timeout
- int nRet= ::setsockopt(fnum, SOL_SOCKET, SO_RCVTIMEO,
- (char*)&timeout, sizeof(timeout));
- if (nRet != NO_ERROR)
- {
- dwErrorCode = WSAGetLastError ();
- goto error;
- }
-
- r = ::recv (fnum, (char*) buf, count, 0);
-
- if (r == 0)
- return -1;
-
- dwErrorCode = WSAGetLastError ();
- // save WSAGetLastError() before calling Thread.interrupted()
-
- if (java::lang::Thread::interrupted())
- {
- java::io::InterruptedIOException *iioe =
- new java::io::InterruptedIOException
- (JvNewStringUTF("read interrupted"));
- iioe->bytesTransferred = r == -1 ? 0 : r;
- throw iioe;
- }
- else if (r == -1)
- {
-error:
- // Some errors cause us to return end of stream...
- if (dwErrorCode == WSAENOTCONN)
- return -1;
-
- // Other errors need to be signalled.
- if (dwErrorCode == WSAETIMEDOUT)
- throw new java::net::SocketTimeoutException
- (JvNewStringUTF ("read timed out") );
- else
- _Jv_ThrowIOException (dwErrorCode);
- }
-
- return r;
-}
-
-// Read a single byte from the socket.
-jint
-java::net::PlainSocketImpl::read(void)
-{
- jbyte b;
- doRead(fnum, &b, 1, timeout);
- return b & 0xFF;
-}
-
-// Read count bytes into the buffer, starting at offset.
-jint
-java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
-{
- if (! buffer)
- throw new java::lang::NullPointerException;
-
- jsize bsize = JvGetArrayLength (buffer);
-
- if (offset < 0 || count < 0 || offset + count > bsize)
- throw new java::lang::ArrayIndexOutOfBoundsException;
-
- jbyte *bytes = elements (buffer) + offset;
-
- // Read the socket.
- return doRead(fnum, bytes, count, timeout);
-}
-
-// How many bytes are available?
-jint
-java::net::PlainSocketImpl::available(void)
-{
- unsigned long num = 0;
-
- if (::ioctlsocket (fnum, FIONREAD, &num) == SOCKET_ERROR)
- _Jv_ThrowIOException ();
-
- return (jint) num;
-}
-
-void
-java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
-{
- int val;
- socklen_t val_len = sizeof (val);
-
- if (fnum < 0)
- throw new java::net::SocketException (JvNewStringUTF ("Socket closed"));
-
- if (_Jv_IsInstanceOf (value, &java::lang::Boolean::class$))
- {
- java::lang::Boolean *boolobj =
- static_cast<java::lang::Boolean *> (value);
- if (boolobj->booleanValue())
- val = 1;
- else
- {
- if (optID == _Jv_SO_LINGER_)
- val = -1;
- else
- val = 0;
- }
- }
- else if (_Jv_IsInstanceOf (value, &java::lang::Integer::class$))
- {
- java::lang::Integer *intobj =
- static_cast<java::lang::Integer *> (value);
- val = (int) intobj->intValue();
- }
- else
- {
- throw new java::lang::IllegalArgumentException (
- JvNewStringLatin1 ("`value' must be Boolean or Integer"));
- }
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
- if (::setsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
- val_len) == SOCKET_ERROR)
- goto error;
- return;
-
- case _Jv_SO_KEEPALIVE_ :
- if (::setsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
- val_len) == SOCKET_ERROR)
- goto error;
- break;
-
- case _Jv_SO_BROADCAST_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
- break;
-
- case _Jv_SO_OOBINLINE_ :
- if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
- val_len) == SOCKET_ERROR)
- goto error;
- break;
-
- case _Jv_SO_LINGER_ :
- struct linger l_val;
- l_val.l_onoff = (val != -1);
- l_val.l_linger = val;
-
- if (::setsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
- sizeof(l_val)) == SOCKET_ERROR)
- goto error;
- return;
-
- case _Jv_SO_SNDBUF_ :
- case _Jv_SO_RCVBUF_ :
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val,
- val_len) == SOCKET_ERROR)
- goto error;
- return;
-
- case _Jv_SO_BINDADDR_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_BINDADDR: read only option"));
- return;
-
- case _Jv_IP_MULTICAST_IF_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
- return;
-
- case _Jv_IP_MULTICAST_IF2_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
- break;
-
- case _Jv_IP_MULTICAST_LOOP_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
- break;
-
- case _Jv_IP_TOS_ :
- if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
- val_len) == SOCKET_ERROR)
- goto error;
- break;
-
- case _Jv_SO_REUSEADDR_ :
- throw new java::net::SocketException (
- JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
- return;
-
- case _Jv_SO_TIMEOUT_ :
- timeout = val;
- return;
-
- default :
- WSASetLastError (WSAENOPROTOOPT);
- }
-
-error:
- _Jv_ThrowSocketException ();
-}
-
-java::lang::Object *
-java::net::PlainSocketImpl::getOption (jint optID)
-{
- int val;
- socklen_t val_len = sizeof(val);
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- struct linger l_val;
- socklen_t l_val_len = sizeof(l_val);
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
- if (::getsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
- &val_len) == SOCKET_ERROR)
- goto error;
- else
- return new java::lang::Boolean (val != 0);
- break;
-
- case _Jv_SO_LINGER_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
- &l_val_len) == SOCKET_ERROR)
- goto error;
-
- if (l_val.l_onoff)
- return new java::lang::Integer (l_val.l_linger);
- else
- return new java::lang::Boolean ((jboolean)false);
- break;
-
- case _Jv_SO_KEEPALIVE_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
- &val_len) == SOCKET_ERROR)
- goto error;
- else
- return new java::lang::Boolean (val != 0);
-
- case _Jv_SO_BROADCAST_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
- &val_len) == SOCKET_ERROR)
- goto error;
- return new java::lang::Boolean ((jboolean)val);
-
- case _Jv_SO_OOBINLINE_ :
- if (::getsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
- &val_len) == SOCKET_ERROR)
- goto error;
- return new java::lang::Boolean ((jboolean)val);
-
- case _Jv_SO_RCVBUF_ :
- case _Jv_SO_SNDBUF_ :
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val,
- &val_len) == SOCKET_ERROR)
- goto error;
- else
- return new java::lang::Integer (val);
- break;
- case _Jv_SO_BINDADDR_:
- // cache the local address
- if (localAddress == NULL)
- {
- jbyteArray laddr;
-
- if (::getsockname (fnum, (sockaddr*) &u,
- &addrlen) == SOCKET_ERROR)
- goto error;
-
- if (u.address.sin_family == AF_INET)
- {
- laddr = JvNewByteArray (4);
- memcpy (elements (laddr), &u.address.sin_addr, 4);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- laddr = JvNewByteArray (16);
- memcpy (elements (laddr), &u.address6.sin6_addr, 16);
- }
-#endif
- else
- throw new java::net::SocketException
- (JvNewStringUTF ("invalid family"));
- localAddress = new java::net::InetAddress (laddr, NULL);
- }
-
- return localAddress;
- break;
- case _Jv_IP_MULTICAST_IF_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
- break;
-
- case _Jv_IP_MULTICAST_IF2_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
- break;
-
- case _Jv_IP_MULTICAST_LOOP_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
- break;
-
- case _Jv_IP_TOS_ :
- if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
- &val_len) == SOCKET_ERROR)
- goto error;
- return new java::lang::Integer (val);
- break;
-
- case _Jv_SO_REUSEADDR_ :
- throw new java::net::SocketException
- (JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
- break;
-
- case _Jv_SO_TIMEOUT_ :
- return new java::lang::Integer (timeout);
- break;
-
- default :
- WSASetLastError (WSAENOPROTOOPT);
- }
-
-error:
- _Jv_ThrowSocketException ();
- return 0;
- // we should never get here
-}
-
-void
-java::net::PlainSocketImpl::shutdownInput (void)
-{
- if (::shutdown (fnum, 0))
- _Jv_ThrowSocketException ();
-}
-
-void
-java::net::PlainSocketImpl::shutdownOutput (void)
-{
- if (::shutdown (fnum, 1))
- _Jv_ThrowSocketException ();
-}