b24513a1a2
libstdc++-v3: * configure.host (irix6.5*): Remove. * config/os/irix: Remove. * config/io/basic_file_stdio.cc (__basic_file<char>::showmanyc()) [_GLIBCXX_FIONREAD_TAKES_OFF_T]: Remove. * doc/xml/faq.xml: Remove IRIX reference. * doc/xml/manual/using.xml (Finding Dynamic or Shared Libraries): Remove IRIX example. * testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc: Remove mips-sgi-irix6* handling. * testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc: Likewise. * testsuite/21_strings/basic_string/pthread18185.cc: Likewise. * testsuite/21_strings/basic_string/pthread4.cc: Likewise. * testsuite/22_locale/locale/cons/12658_thread-1.cc: Likewise. * testsuite/22_locale/locale/cons/12658_thread-2.cc: Likewise. * testsuite/23_containers/list/pthread1.cc: Likewise. * testsuite/23_containers/list/pthread5.cc: Likewise. * testsuite/23_containers/map/pthread6.cc: Likewise. * testsuite/23_containers/vector/debug/multithreaded_swap.cc: Likewise. * testsuite/27_io/basic_ofstream/pthread2.cc: Likewise. * testsuite/27_io/basic_ostringstream/pthread3.cc: Likewise. * testsuite/30_threads/async/42819.cc: Likewise. * testsuite/30_threads/async/49668.cc: Likewise. * testsuite/30_threads/async/any.cc: Likewise. * testsuite/30_threads/async/async.cc: Likewise. * testsuite/30_threads/async/launch.cc: Likewise. * testsuite/30_threads/async/sync.cc: Likewise. * testsuite/30_threads/call_once/39909.cc: Likewise. * testsuite/30_threads/call_once/49668.cc: Likewise. * testsuite/30_threads/call_once/call_once1.cc: Likewise. * testsuite/30_threads/condition_variable/cons/1.cc: Likewise. * testsuite/30_threads/condition_variable/members/1.cc: Likewise. * testsuite/30_threads/condition_variable/members/2.cc: Likewise. * testsuite/30_threads/condition_variable/native_handle/typesizes.cc: Likewise. * testsuite/30_threads/condition_variable_any/50862.cc: Likewise. * testsuite/30_threads/condition_variable_any/cons/1.cc: Likewise. * testsuite/30_threads/condition_variable_any/members/1.cc: Likewise. * testsuite/30_threads/condition_variable_any/members/2.cc: Likewise. * testsuite/30_threads/future/cons/move.cc: Likewise. * testsuite/30_threads/future/members/45133.cc: Likewise. * testsuite/30_threads/future/members/get.cc: Likewise. * testsuite/30_threads/future/members/get2.cc: Likewise. * testsuite/30_threads/future/members/share.cc: Likewise. * testsuite/30_threads/future/members/valid.cc: Likewise. * testsuite/30_threads/future/members/wait.cc: Likewise. * testsuite/30_threads/future/members/wait_for.cc: Likewise. * testsuite/30_threads/future/members/wait_until.cc: Likewise. * testsuite/30_threads/lock/1.cc: Likewise. * testsuite/30_threads/lock/2.cc: Likewise. * testsuite/30_threads/lock/3.cc: Likewise. * testsuite/30_threads/lock/4.cc: Likewise. * testsuite/30_threads/lock_guard/cons/1.cc: Likewise. * testsuite/30_threads/mutex/cons/1.cc: Likewise. * testsuite/30_threads/mutex/dest/destructor_locked.cc: Likewise. * testsuite/30_threads/mutex/lock/1.cc: Likewise. * testsuite/30_threads/mutex/native_handle/1.cc: Likewise. * testsuite/30_threads/mutex/native_handle/typesizes.cc: Likewise. * testsuite/30_threads/mutex/try_lock/1.cc: Likewise. * testsuite/30_threads/mutex/try_lock/2.cc: Likewise. * testsuite/30_threads/mutex/unlock/1.cc: Likewise. * testsuite/30_threads/packaged_task/49668.cc: Likewise. * testsuite/30_threads/packaged_task/cons/1.cc: Likewise. * testsuite/30_threads/packaged_task/cons/2.cc: Likewise. * testsuite/30_threads/packaged_task/cons/3.cc: Likewise. * testsuite/30_threads/packaged_task/cons/alloc.cc: Likewise. * testsuite/30_threads/packaged_task/cons/move.cc: Likewise. * testsuite/30_threads/packaged_task/cons/move_assign.cc: Likewise. * testsuite/30_threads/packaged_task/members/get_future.cc: Likewise. * testsuite/30_threads/packaged_task/members/get_future2.cc: Likewise. * testsuite/30_threads/packaged_task/members/invoke.cc: Likewise. * testsuite/30_threads/packaged_task/members/invoke2.cc: Likewise. * testsuite/30_threads/packaged_task/members/invoke3.cc: Likewise. * testsuite/30_threads/packaged_task/members/invoke4.cc: Likewise. * testsuite/30_threads/packaged_task/members/invoke5.cc: Likewise. * testsuite/30_threads/packaged_task/members/reset.cc: Likewise. * testsuite/30_threads/packaged_task/members/reset2.cc: Likewise. * testsuite/30_threads/packaged_task/members/swap.cc: Likewise. * testsuite/30_threads/packaged_task/members/valid.cc: Likewise. * testsuite/30_threads/promise/cons/1.cc: Likewise. * testsuite/30_threads/promise/cons/alloc.cc: Likewise. * testsuite/30_threads/promise/cons/move.cc: Likewise. * testsuite/30_threads/promise/cons/move_assign.cc: Likewise. * testsuite/30_threads/promise/members/get_future.cc: Likewise. * testsuite/30_threads/promise/members/get_future2.cc: Likewise. * testsuite/30_threads/promise/members/set_exception.cc: Likewise. * testsuite/30_threads/promise/members/set_exception2.cc: Likewise. * testsuite/30_threads/promise/members/set_value.cc: Likewise. * testsuite/30_threads/promise/members/set_value2.cc: Likewise. * testsuite/30_threads/promise/members/set_value3.cc: Likewise. * testsuite/30_threads/promise/members/swap.cc: Likewise. * testsuite/30_threads/recursive_mutex/cons/1.cc: Likewise. * testsuite/30_threads/recursive_mutex/dest/destructor_locked.cc: Likewise. * testsuite/30_threads/recursive_mutex/lock/1.cc: Likewise. * testsuite/30_threads/recursive_mutex/native_handle/1.cc: Likewise. * testsuite/30_threads/recursive_mutex/native_handle/typesizes.cc: Likewise. * testsuite/30_threads/recursive_mutex/try_lock/1.cc: Likewise. * testsuite/30_threads/recursive_mutex/try_lock/2.cc: Likewise. * testsuite/30_threads/recursive_mutex/unlock/1.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/cons/1.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/dest/destructor_locked.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/lock/1.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/lock/2.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/native_handle/1.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/native_handle/typesizes.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/try_lock/1.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/try_lock/2.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/try_lock_for/1.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/try_lock_for/2.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/try_lock_for/3.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/try_lock_until/1.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/try_lock_until/2.cc: Likewise. * testsuite/30_threads/recursive_timed_mutex/unlock/1.cc: Likewise. * testsuite/30_threads/shared_future/cons/move.cc: Likewise. * testsuite/30_threads/shared_future/members/45133.cc: Likewise. * testsuite/30_threads/shared_future/members/get.cc: Likewise. * testsuite/30_threads/shared_future/members/get2.cc: Likewise. * testsuite/30_threads/shared_future/members/valid.cc: Likewise. * testsuite/30_threads/shared_future/members/wait.cc: Likewise. * testsuite/30_threads/shared_future/members/wait_for.cc: Likewise. * testsuite/30_threads/shared_future/members/wait_until.cc: Likewise. * testsuite/30_threads/this_thread/1.cc: Likewise. * testsuite/30_threads/this_thread/2.cc: Likewise. * testsuite/30_threads/this_thread/3.cc: Likewise. * testsuite/30_threads/this_thread/4.cc: Likewise. * testsuite/30_threads/thread/cons/1.cc: Likewise. * testsuite/30_threads/thread/cons/2.cc: Likewise. * testsuite/30_threads/thread/cons/3.cc: Likewise. * testsuite/30_threads/thread/cons/4.cc: Likewise. * testsuite/30_threads/thread/cons/49668.cc: Likewise. * testsuite/30_threads/thread/cons/5.cc: Likewise. * testsuite/30_threads/thread/cons/6.cc: Likewise. * testsuite/30_threads/thread/cons/7.cc: Likewise. * testsuite/30_threads/thread/cons/8.cc: Likewise. * testsuite/30_threads/thread/cons/9.cc: Likewise. * testsuite/30_threads/thread/cons/moveable.cc: Likewise. * testsuite/30_threads/thread/members/1.cc: Likewise. * testsuite/30_threads/thread/members/2.cc: Likewise. * testsuite/30_threads/thread/members/3.cc: Likewise. * testsuite/30_threads/thread/members/4.cc: Likewise. * testsuite/30_threads/thread/members/5.cc: Likewise. * testsuite/30_threads/thread/members/hardware_concurrency.cc: Likewise. * testsuite/30_threads/thread/native_handle/typesizes.cc: Likewise. * testsuite/30_threads/thread/swap/1.cc: Likewise. * testsuite/30_threads/timed_mutex/cons/1.cc: Likewise. * testsuite/30_threads/timed_mutex/dest/destructor_locked.cc: Likewise. * testsuite/30_threads/timed_mutex/lock/1.cc: Likewise. * testsuite/30_threads/timed_mutex/native_handle/1.cc: Likewise. * testsuite/30_threads/timed_mutex/native_handle/typesizes.cc: Likewise. * testsuite/30_threads/timed_mutex/try_lock/1.cc: Likewise. * testsuite/30_threads/timed_mutex/try_lock/2.cc: Likewise. * testsuite/30_threads/timed_mutex/try_lock_for/1.cc: Likewise. * testsuite/30_threads/timed_mutex/try_lock_for/2.cc: Likewise. * testsuite/30_threads/timed_mutex/try_lock_for/3.cc: Likewise. * testsuite/30_threads/timed_mutex/try_lock_until/1.cc: Likewise. * testsuite/30_threads/timed_mutex/try_lock_until/2.cc: Likewise. * testsuite/30_threads/timed_mutex/unlock/1.cc: Likewise. * testsuite/30_threads/try_lock/1.cc: Likewise. * testsuite/30_threads/try_lock/2.cc: Likewise. * testsuite/30_threads/try_lock/3.cc: Likewise. * testsuite/30_threads/try_lock/4.cc: Likewise. * testsuite/30_threads/unique_lock/cons/1.cc: Likewise. * testsuite/30_threads/unique_lock/cons/2.cc: Likewise. * testsuite/30_threads/unique_lock/cons/3.cc: Likewise. * testsuite/30_threads/unique_lock/cons/4.cc: Likewise. * testsuite/30_threads/unique_lock/cons/5.cc: Likewise. * testsuite/30_threads/unique_lock/cons/6.cc: Likewise. * testsuite/30_threads/unique_lock/locking/1.cc: Likewise. * testsuite/30_threads/unique_lock/locking/2.cc: Likewise. * testsuite/30_threads/unique_lock/locking/3.cc: Likewise. * testsuite/30_threads/unique_lock/locking/4.cc: Likewise. * testsuite/30_threads/unique_lock/modifiers/1.cc: Likewise. * testsuite/30_threads/unique_lock/modifiers/2.cc: Likewise. * testsuite/ext/rope/pthread7-rope.cc: Likewise. * testsuite/tr1/2_general_utilities/shared_ptr/thread/default_weaktoshared.cc: Likewise. * testsuite/tr1/2_general_utilities/shared_ptr/thread/mutex_weaktoshared.cc: Likewise. * testsuite/23_containers/vector/capacity/resize/1.cc: Remove dg-options for mips*-*-irix6*. * testsuite/27_io/ios_base/storage/1.cc: Likewise. * testsuite/27_io/ios_base/storage/2.cc: Likewise. * testsuite/27_io/ios_base/storage/3.cc: Likewise. * testsuite/lib/libstdc++.exp (v3-build_support): Remove IRIX 6 workaround. libjava: * configure.ac (libgcj_cv_exidx): Remove IRIX 6 ld workaround. (mips-sgi-irix6*): Remove. (mips-sgi-irix*): Remove. (AC_CHECK_HEADERS): Remove bstring.h. * configure: Regenerate. * include/config.h.in: Regenerate. * configure.host (mips-sgi-irix6*): Remove. * include/posix-signal.h [__sgi__]: Remove. * gnu/java/net/natPlainDatagramSocketImplPosix.cc [HAVE_BSTRING_H]: Remove. * gnu/java/net/natPlainDatagramSocketImplWin32.cc: Likewise. * gnu/java/net/natPlainSocketImplPosix.cc: Likewise. libitm: * configure.tgt (*-*-irix6*): Remove. libgomp: * configure.tgt (mips-sgi-irix6*): Remove. libgfortran: * intrinsics/c99_functions.c [__sgi__ && !HAVE_COMPLEX_H]: Remove. libgcc: * config.host (mips-sgi-irix6.5*): Remove. * config/mips/irix-crti.S: Remove. * config/mips/irix-crtn.S: Remove. * config/mips/irix6-unwind.h: Remove. * config/mips/t-irix6: Remove. * config/mips/t-slibgcc-irix: Remove. gnattools: * configure.ac (mips-sgi-irix*): Remove. * configure: Regenerate. gcc/testsuite: * g++.dg/other/anon5.C: Don't skip on mips-sgi-irix*. * g++.dg/tree-prof/partition1.C: Likewise. * g++.dg/tree-prof/partition2.C: Likewise. * g++.old-deja/g++.other/init19.C: Remove mips-sgi-irix* handling. * gcc.c-torture/compile/labels-3.c: Remove dg-options. * gcc.c-torture/execute/20010724-1.c: Remove. * gcc.c-torture/execute/20010724-1.x: Remove. * gcc.c-torture/execute/20040208-2.c: Remove. * gcc.c-torture/execute/20040208-2.x: Remove. * gcc.c-torture/execute/ieee/20000320-1.c [__mips__ && __sgi__]: Remove. (main) [__mips__ && __sgi__]: Remove. * gcc.c-torture/execute/ieee/copysign1.c: Remove IRIX reference. * gcc.c-torture/execute/ieee/copysign2.c: Likewise. * gcc.c-torture/execute/ieee/mul-subnormal-single-1.x: Remove mips-sgi-irix6* handling. * gcc.dg/cpp/assert4.c [__mips__]: Remove __sgi__, sgi. * gcc.dg/torture/20090618-1.c: Don't skip on mips-sgi-irix*. * gcc.dg/torture/builtin-frexp-1.c: Remove mips*-*-irix6* handling. * gcc.dg/torture/builtin-logb-1.c: Likewise. * gcc.dg/torture/pr47917.c: Remove mips-sgi-irix6.5 handling. * gcc.dg/tree-ssa/ssa-store-ccp-3.c: Don't skip on mips*-*-irix*. * gcc.misc-tests/linkage.exp: Remove mips-sgi-irix6* handling. * gcc.target/mips/args-1.c [!__sgi__]: Remove. * gcc.target/mips/interrupt_handler-2.c: Don't skip on mips-sgi-irix6*. * gcc.target/mips/interrupt_handler-3.c: Likewise. * gcc.target/mips/save-restore-1.c: Don't skip on mips-sgi-irix6*. * gcc.target/mips/save-restore-3.c: Likewise. * gcc.target/mips/save-restore-4.c: Likewise. * gcc.target/mips/save-restore-5.c: Likewise. * gfortran.dg/g77/cabs.f: Don't xfail on mips-sgi-irix6*. * lib/prune.exp (prune_gcc_output): Remove pruning of IRIX 6 ld messages. * lib/target-libpath.exp (set_ld_library_path_env_vars): Remove IRIX 6 handling. (restore_ld_library_path_env_vars): Likewise. * lib/target-supports.exp (check_profiling_available): Remove mips*-*-irix* handling. (check_ascii_locale_available): Remove mips-sgi-irix* handling. (add_options_for_c99_runtime): Remove mips-sgi-irix6.5* handling. * objc.dg/stabs-1.m: Don't xfail on mips-sgi-irix6.5. gcc/ada: * gcc-interface/Makefile.in (mips-sgi-irix6*): Remove. * a-intnam-irix.ads, mlib-tgt-specific-irix.adb, s-intman-irix.adb, s-mastop-irix.adb, s-osinte-irix.adb, s-osinte-irix.ads, s-proinf-irix-athread.adb, s-proinf-irix-athread.ads, s-taprop-irix.adb, s-tasinf-irix.ads, system-irix-n32.ads, system-irix-n64.ads, system-irix-o32.ads: Remove. * adaint.c [__mips && __sgi]: Remove. (__gnat_number_of_cpus) [__mips && __sgi]: Remove. [IS_CROSS && !(__mips && __sgi)]: Remove. * adaint.h [sgi && _LFAPI]: Remove. * cstreams.c (__gnat_full_name) [sgi]: Remove. * env.c (__gnat_unsetenv) [__mips && __sgi]: Remove. (__gnat_clearenv) [__mips && __sgi]: Remove. * errno.c (_SGI_MP_SOURCE): Remove. * gsocket.h [sgi]: Remove. * init.c: Remove IRIX reference. [sgi]: Remove. * link.c [sgi]: Remove. * s-oscons-tmplt.c [__mips && __sgi] (IOV_MAX): Don't define. (main) [__mips && __sgi] (MAX_tv_sec): Don't define. (CLOCK_SGI_FAST, CLOCK_SGI_CYCLE): Remove. * sysdep.c [sgi]: Remove. (getc_immediate_common) [sgi]: Remove. (__gnat_localtime_tzoff) [sgi]: Remove. * terminals.c [__mips && __sgi] (IRIX): Don't define. [IRIX] (USE_GETPTY): Don't define. (allocate_pty_desc) [USE_GETPTY]: Remove. * g-traceb.ads: Remove IRIX reference. * g-trasym.ads: Likewise. * memtrack.adb: Likewise. * s-interr-sigaction.adb: Likewise. * gnat_rm.texi (Implementation Advice): Remove SGI info. (Implementation Defined Characteristics): Likewise. * gnat_ugn.texi (Summary of Run-Time Configurations, mips-irix): Remove. (Irix-Specific Considerations): Remove. gcc/cp: * Make-lang.in (doc/g++.1): Remove IRIX 6.5 reference. gcc: * config.gcc (enable_obsolete): Remove mips-sgi-irix6.5. (mips-sgi-irix6.5*): Remove. * config.host (mips-sgi-irix*): Remove. * configure.ac (enable_fixed_point): Remove mips*-sgi-irix*. (set_have_as_tls): Remove *-*-irix6*. (gcc_cv_ld_static_dynamic): Remove mips-sgi-irix6*. * configure: Regenerate. * config/mips/iris6.h: Remove. * config/mips/iris6.opt: Remove. * config/mips/t-irix6: Remove. * config/mips/mips.h (TARGET_GPWORD): Remove IRIX 6 N64 handling. (TARGET_IRIX6): Remove. (TARGET_CPU_CPP_BUILTINS): Remove IRIX 6 handling. Don't define LANGUAGE_C, _LANGUAGE_C for Objective-C. * config/mips/mips.c (mips_build_builtin_va_list): Remove IRIX 6 handling. (mips_file_start): Likewise. * config/mips/mips-protos.h (irix_asm_output_align): Remove. * config/mips/driver-native.c [__sgi__]: Remove. (host_detect_local_cpu) [__sgi__]: Remove. * config/mips/gnu-user.h: Remove iris5.h reference. * config/mips/mips-modes.def: Remove IRIX 6 reference. * config/mips/gnu-user64.h (MIPS_TFMODE_FORMAT): Remove. * config/mips/mips.c (mips_option_override) [MIPS_TFMODE_FORMAT]: Remove. * gcc.c (main): Move asm_debug initialization ... (asm_debug): ... here. * ginclude/stddef.h (__STDDEF_H__): Don't define. * defaults.h (LINK_ELIMINATE_DUPLICATE_LDIRECTORIES): Remove. * system.h (LINK_ELIMINATE_DUPLICATE_LDIRECTORIES): Poison. * collect2.c [LINK_ELIMINATE_DUPLICATE_LDIRECTORIES]: Remove. (main) [LINK_ELIMINATE_DUPLICATE_LDIRECTORIES]: Remove. [LINK_ELIMINATE_DUPLICATE_LDIRECTORIES] (is_in_args): Remove. * doc/tm.texi.in (Driver, LINK_ELIMINATE_DUPLICATE_LDIRECTORIES): Remove. * doc/tm.texi: Regenerate. * doc/invoke.texi (Debugging Options, -gdwarf-<version>): Remove IRIX 6 reference. (MIPS Options, -march): Remove IRIX reference. * doc/install.texi (Binaries, SGI IRIX): Remove. (Specific, mips-sgi-irix6): Document IRIX 6.5 removal, remove rest of section. * doc/trouble.texi (Interoperation): Remove -lgl_s handling. fixincludes: * inclhack.def (broken_cabs): Remove IRIX and SunOS 4 support. (irix___restrict): Remove. (irix___generic1): Remove. (irix___generic2): Remove. (irix_asm_apostrophe): Remove. (irix_complex): Remove. (irix_pthread_init): Remove. (irix_socklen_t): Remove. (irix_stdint_c99_mode): Remove. (irix_stdint_c99_types): Remove. (irix_stdint_c99_macros): Remove. (irix_stdio_va_list): Remove IRIX 6.5 support. (irix_wcsftime): Remove. (stdio_va_list): Remove IRIX 6.5 support. (svr4_profil): Remove IRIX bypass. * fixincl.x: Regenerate. * tests/base/complex.h [IRIX_COMPLEX_CHECK]: Remove. * tests/base/internal/math_core.h: Remove. * tests/base/internal/sgimacros.h: Remove. * tests/base/internal/wchar_core.h: Remove. * tests/base/math.h [BROKEN_CABS_CHECK]: Remove IRIX and SunOS 4 support. * tests/base/pthread.h [IRIX_PTHREAD_INIT_CHECK]: Remove. * tests/base/stdint-irix65.h: Remove. * tests/base/stdint.h [IRIX_STDINT_C99_MODE_CHECK]: Remove. * tests/base/sys/asm.h: Remove. * tests/base/sys/socket.h [IRIX_SOCKLEN_T_CHECK]: Remove. contrib: * config-list.mk (LIST): Remove mips-sgi-irix6.5. toplevel: * MAINTAINERS (OS Port Maintainers): Remove irix. * configure.ac (enable_libgomp): Remove *-*-irix6*. (unsupported_languages): Remove mips-sgi-irix6.*. (noconfigdirs): Don't add ${libgcj} for mips*-*-irix6*. (with_stabs): Remove. * configure: Regenerate. From-SVN: r185390
864 lines
24 KiB
C++
864 lines
24 KiB
C++
/* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2012 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>
|
|
|
|
#include <gcj/cni.h>
|
|
#include <gcj/javaprims.h>
|
|
#include <gnu/java/net/PlainSocketImpl.h>
|
|
#include <gnu/java/net/PlainSocketImpl$SocketInputStream.h>
|
|
#include <gnu/java/net/PlainSocketImpl$SocketOutputStream.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>
|
|
#include <java/net/UnknownHostException.h>
|
|
|
|
union SockAddr
|
|
{
|
|
struct sockaddr_in address;
|
|
#ifdef HAVE_INET6
|
|
struct sockaddr_in6 address6;
|
|
#endif
|
|
};
|
|
|
|
void
|
|
gnu::java::net::PlainSocketImpl::create (jboolean stream)
|
|
{
|
|
// We might already have been create()d in the nio case.
|
|
if (native_fd != -1)
|
|
return;
|
|
|
|
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));
|
|
}
|
|
|
|
// We use native_fd in place of fd here. From leaving fd null we avoid
|
|
// the double close problem in FileDescriptor.finalize.
|
|
native_fd = 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;
|
|
|
|
// The following is needed for OS X/PPC, otherwise bind() fails with an
|
|
// error. I found the issue and following fix on some mailing list, but
|
|
// no explanation was given as to why this solved the problem.
|
|
memset (&u, 0, sizeof (u));
|
|
|
|
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 (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(native_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof(i));
|
|
|
|
if (_Jv_bind (native_fd, ptr, len) == 0)
|
|
{
|
|
socklen_t addrlen = sizeof(u);
|
|
|
|
if (lport != 0)
|
|
localport = lport;
|
|
else if (::getsockname (native_fd, (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();
|
|
if (! host)
|
|
throw new ::java::net::UnknownHostException(tmp->toString());
|
|
|
|
jint rport = tmp->getPort();
|
|
|
|
// Set the SocketImpl's address and port fields before we try to
|
|
// connect. Note that the fact that these are set doesn't imply
|
|
// that we're actually connected to anything. We need to record
|
|
// this data before we attempt the connect, since non-blocking
|
|
// SocketChannels will use this and almost certainly throw timeout
|
|
// exceptions.
|
|
address = host;
|
|
port = rport;
|
|
|
|
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 (native_fd, F_GETFL);
|
|
::fcntl (native_fd, F_SETFL, flags | O_NONBLOCK);
|
|
|
|
if ((_Jv_connect (native_fd, ptr, len) != 0) && (errno != EINPROGRESS))
|
|
goto error;
|
|
|
|
fd_set fset;
|
|
struct timeval tv;
|
|
FD_ZERO(&fset);
|
|
FD_SET(native_fd, &fset);
|
|
tv.tv_sec = timeout / 1000;
|
|
tv.tv_usec = (timeout % 1000) * 1000;
|
|
int retval;
|
|
|
|
if ((retval = _Jv_select (native_fd + 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 (native_fd, F_SETFL, flags);
|
|
}
|
|
else
|
|
{
|
|
if (_Jv_connect (native_fd, ptr, len) != 0)
|
|
goto error;
|
|
}
|
|
|
|
// A bind may not have been done on this socket; if so, set localport now.
|
|
if (localport == 0)
|
|
{
|
|
if (::getsockname (native_fd, (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 (native_fd, backlog) != 0)
|
|
{
|
|
char* strerr = strerror (errno);
|
|
throw new ::java::io::IOException (JvNewStringUTF (strerr));
|
|
}
|
|
}
|
|
|
|
static void
|
|
throw_on_sock_closed (gnu::java::net::PlainSocketImpl *soc_impl)
|
|
{
|
|
// Avoid races from asynchronous close().
|
|
JvSynchronize sync (soc_impl);
|
|
if (soc_impl->native_fd == -1)
|
|
{
|
|
using namespace java::net;
|
|
// Socket was closed.
|
|
SocketException *se =
|
|
new SocketException (JvNewStringUTF ("Socket Closed"));
|
|
throw se;
|
|
}
|
|
}
|
|
|
|
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 && native_fd >= 0 && native_fd < FD_SETSIZE)
|
|
{
|
|
fd_set fset;
|
|
struct timeval tv;
|
|
FD_ZERO(&fset);
|
|
FD_SET(native_fd, &fset);
|
|
tv.tv_sec = timeout / 1000;
|
|
tv.tv_usec = (timeout % 1000) * 1000;
|
|
int retval;
|
|
if ((retval = _Jv_select (native_fd + 1, &fset, &fset, NULL, &tv)) < 0)
|
|
goto error;
|
|
else if (retval == 0)
|
|
throw new ::java::net::SocketTimeoutException (
|
|
JvNewStringUTF("Accept timed out"));
|
|
}
|
|
|
|
new_socket = ::accept (native_fd, (sockaddr*) &u, &addrlen);
|
|
|
|
if (new_socket < 0)
|
|
goto error;
|
|
|
|
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->native_fd = new_socket;
|
|
s->localport = localport;
|
|
s->address = ::java::net::InetAddress::getByAddress (raddr);
|
|
s->port = rport;
|
|
return;
|
|
|
|
error:
|
|
char* strerr = strerror (errno);
|
|
throw_on_sock_closed (this);
|
|
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? Yes.
|
|
// How would that effect so_linger? Uncertain.
|
|
::shutdown (native_fd, 2);
|
|
// Ignore errors in shutdown as we are closing and all the same
|
|
// errors are handled in the close.
|
|
int res = _Jv_close (native_fd);
|
|
|
|
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.
|
|
native_fd = -1;
|
|
timeout = 0;
|
|
}
|
|
|
|
static void
|
|
write_helper (jint native_fd, jbyte *bytes, jint len);
|
|
|
|
// Write a byte to the socket.
|
|
void
|
|
gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jint b)
|
|
{
|
|
jbyte data = (jbyte) b;
|
|
write_helper (this$0->native_fd, &data, 1);
|
|
}
|
|
|
|
// Write some bytes to the socket.
|
|
void
|
|
gnu::java::net::PlainSocketImpl$SocketOutputStream::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;
|
|
|
|
write_helper (this$0->native_fd, elements (b) + offset, len);
|
|
}
|
|
|
|
static void
|
|
write_helper(jint native_fd, jbyte *bytes, jint len)
|
|
{
|
|
int written = 0;
|
|
|
|
while (len > 0)
|
|
{
|
|
int r = _Jv_write (native_fd, 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"));
|
|
}
|
|
|
|
static jint
|
|
read_helper (gnu::java::net::PlainSocketImpl *soc_impl,
|
|
jbyte *bytes, jint count);
|
|
|
|
// Read a single byte from the socket.
|
|
jint
|
|
gnu::java::net::PlainSocketImpl$SocketInputStream::read(void)
|
|
{
|
|
jbyte data;
|
|
|
|
if (read_helper (this$0, &data, 1) == 1)
|
|
return data & 0xFF;
|
|
|
|
return -1;
|
|
}
|
|
|
|
// Read count bytes into the buffer, starting at offset.
|
|
jint
|
|
gnu::java::net::PlainSocketImpl$SocketInputStream::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;
|
|
|
|
return read_helper (this$0, elements (buffer) + offset, count);
|
|
}
|
|
|
|
static jint
|
|
read_helper (gnu::java::net::PlainSocketImpl *soc_impl,
|
|
jbyte *bytes, jint count)
|
|
{
|
|
// If zero bytes were requested, short circuit so that recv
|
|
// doesn't signal EOF.
|
|
if (count == 0)
|
|
return 0;
|
|
|
|
// Do timeouts via select.
|
|
if (soc_impl->timeout > 0
|
|
&& soc_impl->native_fd >= 0
|
|
&& soc_impl->native_fd < FD_SETSIZE)
|
|
{
|
|
// Create the file descriptor set.
|
|
fd_set read_fds;
|
|
FD_ZERO (&read_fds);
|
|
FD_SET (soc_impl->native_fd, &read_fds);
|
|
// Create the timeout struct based on our internal timeout value.
|
|
struct timeval timeout_value;
|
|
timeout_value.tv_sec = soc_impl->timeout / 1000;
|
|
timeout_value.tv_usec =(soc_impl->timeout % 1000) * 1000;
|
|
// Select on the fds.
|
|
int sel_retval =
|
|
_Jv_select (soc_impl->native_fd + 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 (soc_impl->native_fd, (char *) bytes, count, 0);
|
|
|
|
if (r == 0)
|
|
{
|
|
throw_on_sock_closed (soc_impl);
|
|
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)
|
|
{
|
|
throw_on_sock_closed (soc_impl);
|
|
// 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)
|
|
int num = 0;
|
|
int r = 0;
|
|
bool num_set = false;
|
|
|
|
#if defined(FIONREAD)
|
|
r = ::ioctl (native_fd, 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 (native_fd < 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 && native_fd >= 0 && native_fd < FD_SETSIZE)
|
|
{
|
|
fd_set rd;
|
|
FD_ZERO (&rd);
|
|
FD_SET (native_fd, &rd);
|
|
struct timeval tv;
|
|
tv.tv_sec = 0;
|
|
tv.tv_usec = 0;
|
|
r = _Jv_select (native_fd + 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 (native_fd < 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 (native_fd, 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 (native_fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
|
|
val_len) != 0)
|
|
goto error;
|
|
return;
|
|
|
|
case _Jv_SO_BROADCAST_ :
|
|
throw new ::java::net::SocketException
|
|
(JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
|
|
return;
|
|
|
|
case _Jv_SO_OOBINLINE_ :
|
|
if (::setsockopt (native_fd, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
|
|
val_len) != 0)
|
|
goto error;
|
|
return;
|
|
|
|
case _Jv_SO_LINGER_ :
|
|
#ifdef SO_LINGER
|
|
struct linger l_val;
|
|
l_val.l_onoff = (val != -1);
|
|
l_val.l_linger = val;
|
|
|
|
if (::setsockopt (native_fd, 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 (native_fd, 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"));
|
|
return;
|
|
|
|
case _Jv_IP_MULTICAST_LOOP_ :
|
|
throw new ::java::net::SocketException (
|
|
JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
|
|
return;
|
|
|
|
case _Jv_IP_TOS_ :
|
|
if (::setsockopt (native_fd, SOL_SOCKET, IP_TOS, (char *) &val,
|
|
val_len) != 0)
|
|
goto error;
|
|
return;
|
|
|
|
case _Jv_SO_REUSEADDR_ :
|
|
#if defined(SO_REUSEADDR)
|
|
if (::setsockopt (native_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
|
|
val_len) != 0)
|
|
goto error;
|
|
return;
|
|
#else
|
|
throw new ::java::lang::InternalError (
|
|
JvNewStringUTF ("SO_REUSEADDR not supported"));
|
|
#endif
|
|
|
|
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 (native_fd, 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 (native_fd, 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 (native_fd, 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 (native_fd, SOL_SOCKET, SO_BROADCAST, (char *) &val,
|
|
&val_len) != 0)
|
|
goto error;
|
|
return new ::java::lang::Boolean ((jboolean)val);
|
|
|
|
case _Jv_SO_OOBINLINE_ :
|
|
if (::getsockopt (native_fd, 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 (native_fd, 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 (native_fd, (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 = ::java::net::InetAddress::getByAddress (laddr);
|
|
}
|
|
|
|
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 (native_fd, SOL_SOCKET, IP_TOS, (char *) &val,
|
|
&val_len) != 0)
|
|
goto error;
|
|
return new ::java::lang::Integer (val);
|
|
break;
|
|
|
|
case _Jv_SO_REUSEADDR_ :
|
|
#if defined(SO_REUSEADDR)
|
|
if (::getsockopt (native_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
|
|
&val_len) != 0)
|
|
goto error;
|
|
#else
|
|
throw new ::java::lang::InternalError (
|
|
JvNewStringUTF ("SO_REUSEADDR not supported"));
|
|
#endif
|
|
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 (native_fd, 0))
|
|
throw new ::java::net::SocketException (JvNewStringUTF (strerror (errno)));
|
|
}
|
|
|
|
void
|
|
gnu::java::net::PlainSocketImpl::shutdownOutput (void)
|
|
{
|
|
if (::shutdown (native_fd, 1))
|
|
throw new ::java::net::SocketException (JvNewStringUTF (strerror (errno)));
|
|
}
|