From 6511b78ff810ead55a110d42b01a08255a55b56d Mon Sep 17 00:00:00 2001 From: mquinson Date: Thu, 15 Apr 2004 00:17:02 +0000 Subject: [PATCH] 2004-04-09 Martin Quinson [Transport plugins] - factorize more code between RL and SG in socket creation - Complete the implementation and tests of: o TCP o file (only in RL, and mainly for debugging) I lost 3 days to design a portable address resolver, and then decided that the prototype mainly have to run on my box. Addressing portability too early may be like optimizing too early :-/ [Tests] - use gras_init in the Tests instead of the crappy parse_log_opt (the latter function is removed) [Conditional execution] - New functions: gras_if_RL/gras_if_SG (basic support for this) [Code reorganisation] - Get rid of libgrasutils.a since it makes more trouble than it solves. Build examples against the RL library, since there is no way to disable its creation for now. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@81 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- configure | 225 ++++++---- configure.ac | 10 +- cruft/doc/tmpl/comm_datadesc.sgml | 14 +- cruft/doc/tmpl/comm_socks.sgml | 16 +- cruft/doc/tmpl/gras-unused.sgml | 21 + cruft/doc/tmpl/gras_private.sgml | 15 - include/cond.h | 58 +++ include/core.h | 16 - include/gras.h | 4 +- include/module.h | 3 +- include/transport.h | 13 +- include/virtu.h | 60 +++ install-sh | 468 +++++++++++---------- src/gras/.cvsignore | 3 +- src/gras/Makefile.am | 27 +- src/gras/Transport/rl_transport.c | 57 +-- src/gras/Transport/transport.c | 165 +++++++- src/gras/Transport/transport_interface.h | 11 +- src/gras/Transport/transport_plugin_file.c | 286 +++++++++++++ src/gras/Transport/transport_plugin_sg.c | 4 - src/gras/Transport/transport_plugin_tcp.c | 161 +++---- src/gras/Transport/transport_private.h | 16 +- src/gras/Virtu/rl_conditional.c | 19 + src/gras/Virtu/sg_conditional.c | 19 + src/gras/gras_private.h | 2 + src/xbt/core_interface.h | 19 + src/xbt/log.c | 4 +- src/xbt/module.c | 27 +- testsuite/.cvsignore | 2 + testsuite/Makefile.am | 54 ++- testsuite/gras/test_utils.c | 19 - testsuite/gras/trp_file_client.c | 34 ++ testsuite/gras/trp_file_server.c | 38 ++ testsuite/gras/trp_file_usage.in | 4 + testsuite/gras/trp_tcp_client.c | 43 ++ testsuite/gras/trp_tcp_server.c | 40 ++ testsuite/gras/trp_tcp_usage.in | 6 + testsuite/xbt/config_usage.c | 4 +- testsuite/xbt/dict_crash.c | 4 +- testsuite/xbt/dict_usage.c | 7 +- testsuite/xbt/dynar_double.c | 6 +- testsuite/xbt/dynar_int.c | 4 +- testsuite/xbt/dynar_string.c | 4 +- testsuite/xbt/log_usage.c | 6 +- testsuite/xbt/set_usage.c | 4 +- 45 files changed, 1420 insertions(+), 602 deletions(-) create mode 100644 include/cond.h create mode 100644 include/virtu.h create mode 100644 src/gras/Transport/transport_plugin_file.c create mode 100644 src/gras/Virtu/rl_conditional.c create mode 100644 src/gras/Virtu/sg_conditional.c create mode 100644 src/xbt/core_interface.h delete mode 100644 testsuite/gras/test_utils.c create mode 100644 testsuite/gras/trp_file_client.c create mode 100644 testsuite/gras/trp_file_server.c create mode 100644 testsuite/gras/trp_file_usage.in create mode 100644 testsuite/gras/trp_tcp_client.c create mode 100644 testsuite/gras/trp_tcp_server.c create mode 100644 testsuite/gras/trp_tcp_usage.in diff --git a/configure b/configure index 589babd046..bfd4563a87 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac Revision: 1.4 . +# From configure.ac Revision: 1.5 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for GRAS 0.0.040304. # @@ -466,7 +466,7 @@ ac_includes_default="\ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM AWK SET_MAKE am__leading_dot CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB CPP CXX CXXFLAGS ac_ct_CXX CXXDEPMODE am__fastdepCXX_TRUE am__fastdepCXX_FALSE CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL LIBOBJS HTML_DIR PKG_CONFIG ENABLE_GTK_DOC_TRUE ENABLE_GTK_DOC_FALSE GTK_DOC_USE_LIBTOOL_TRUE GTK_DOC_USE_LIBTOOL_FALSE ACI_CACHE_PROG aci_module_desc_XML aci_pkg_config_XML HAVE_XML CFLAGS_XML LIBS_XML aci_module_desc_SimGrid aci_pkg_prefix_SimGrid aci_pkg_inc_SimGrid aci_pkg_lib_SimGrid aci_pkg_extra_SimGrid HAVE_SimGrid CFLAGS_SimGrid LIBS_SimGrid MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT cflags_set BASH WARNING LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB CPP CXX CXXFLAGS ac_ct_CXX CXXDEPMODE am__fastdepCXX_TRUE am__fastdepCXX_FALSE CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL LIBOBJS HTML_DIR PKG_CONFIG ENABLE_GTK_DOC_TRUE ENABLE_GTK_DOC_FALSE GTK_DOC_USE_LIBTOOL_TRUE GTK_DOC_USE_LIBTOOL_FALSE ACI_CACHE_PROG aci_module_desc_XML aci_pkg_config_XML HAVE_XML CFLAGS_XML LIBS_XML aci_module_desc_SimGrid aci_pkg_prefix_SimGrid aci_pkg_inc_SimGrid aci_pkg_lib_SimGrid aci_pkg_extra_SimGrid HAVE_SimGrid CFLAGS_SimGrid LIBS_SimGrid MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT cflags_set BASH WARNING LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -1035,12 +1035,12 @@ Optional Features: build static libraries [default=yes] --enable-fast-install[=PKGS] optimize for fast installation [default=yes] - --disable-dependency-tracking Speeds up one-time builds - --enable-dependency-tracking Do not reject slow dependency extractors + --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors --disable-libtool-lock avoid locking (might break parallel builds) --enable-gtk-doc use gtk-doc to build documentation default=no - --enable-maintainer-mode enable make rules and dependencies not useful - (and sometimes confusing) to the casual installer + --enable-maintainer-mode enable make rules and dependencies not useful + (and sometimes confusing) to the casual installer --enable-compile-warnings=no/minimum/yes Turn on compiler warnings. --enable-iso-c Try to warn if code is not ISO C @@ -1645,7 +1645,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_config_headers="$ac_config_headers src/gras_config.h" -am__api_version="1.7" +am__api_version="1.8" # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: @@ -1783,7 +1783,6 @@ _ACEOF program_transform_name=`echo $program_transform_name | sed -f conftest.sed` rm conftest.sed - # expand $ac_aux_dir to an absolute path am_aux_dir=`cd $ac_aux_dir && pwd` @@ -1797,6 +1796,31 @@ else echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} fi +if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then + # Keeping the `.' argument allows $(mkdir_p) to be used without + # argument. Indeed, we sometimes output rules like + # $(mkdir_p) $(somedir) + # where $(somedir) is conditionally defined. + # (`test -n '$(somedir)' && $(mkdir_p) $(somedir)' is a more + # expensive solution, as it forces Make to start a sub-shell.) + mkdir_p='mkdir -p -- .' +else + # On NextStep and OpenStep, the `mkdir' command does not + # recognize any option. It will interpret all options as + # directories to create, and then abort because `.' already + # exists. + for d in ./-p ./--version; + do + test -d $d && rmdir $d + done + # $(mkinstalldirs) is defined by Automake if mkinstalldirs exists. + if test -f "$ac_aux_dir/mkinstalldirs"; then + mkdir_p='$(mkinstalldirs)' + else + mkdir_p='$(install_sh) -d' + fi +fi + for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. @@ -1875,7 +1899,7 @@ else fi rmdir .tst 2>/dev/null - # test to see if srcdir already configured +# test to see if srcdir already configured if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { { echo "$as_me:$LINENO: error: source directory already configured; run \"make distclean\" there first" >&5 @@ -3124,7 +3148,9 @@ else : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c - : > sub/conftst$i.h + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf @@ -3658,7 +3684,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 3661 "configure"' > conftest.$ac_ext + echo '#line 3687 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -4831,7 +4857,9 @@ else : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c - : > sub/conftst$i.h + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf @@ -5215,7 +5243,7 @@ fi # Provide some information about the compiler. -echo "$as_me:5218:" \ +echo "$as_me:5246:" \ "checking for Fortran 77 compiler version" >&5 ac_compiler=`set X $ac_compile; echo $2` { (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 @@ -6247,11 +6275,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6250: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6278: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:6254: \$? = $ac_status" >&5 + echo "$as_me:6282: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -6480,11 +6508,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6483: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6511: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:6487: \$? = $ac_status" >&5 + echo "$as_me:6515: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -6540,11 +6568,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6543: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6571: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:6547: \$? = $ac_status" >&5 + echo "$as_me:6575: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -8715,7 +8743,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:11021: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:10997: \$? = $ac_status" >&5 + echo "$as_me:11025: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -11050,11 +11078,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:11053: $lt_compile\"" >&5) + (eval echo "\"\$as_me:11081: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:11057: \$? = $ac_status" >&5 + echo "$as_me:11085: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -12404,7 +12432,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:13360: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:13336: \$? = $ac_status" >&5 + echo "$as_me:13364: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -13389,11 +13417,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:13392: $lt_compile\"" >&5) + (eval echo "\"\$as_me:13420: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:13396: \$? = $ac_status" >&5 + echo "$as_me:13424: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -15421,11 +15449,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:15424: $lt_compile\"" >&5) + (eval echo "\"\$as_me:15452: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:15428: \$? = $ac_status" >&5 + echo "$as_me:15456: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -15654,11 +15682,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:15657: $lt_compile\"" >&5) + (eval echo "\"\$as_me:15685: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:15661: \$? = $ac_status" >&5 + echo "$as_me:15689: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -15714,11 +15742,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:15717: $lt_compile\"" >&5) + (eval echo "\"\$as_me:15745: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:15721: \$? = $ac_status" >&5 + echo "$as_me:15749: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -17889,7 +17917,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext < sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c - : > sub/conftst$i.h + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf @@ -23301,7 +23331,7 @@ fi WARNING="This file is generated, do not edit" - ac_config_files="$ac_config_files Makefile src/Makefile src/include/Makefile src/include/modules/Makefile src/base/Makefile src/base/Tests/Makefile src/base/Tests/gs_example src/base/Tests/run_tests src/modules/Makefile src/examples/Makefile src/examples/ping/Makefile src/examples/bandwidth/Makefile src/examples/saturate/Makefile src/examples/alnem/Makefile doc/Makefile" + ac_config_files="$ac_config_files Makefile src/Makefile src/include/Makefile src/include/modules/Makefile src/base/Makefile src/base/Tests/Makefile src/base/Tests/run_tests src/base/Tests/gs_example src/base/Tests/trp_tcp_usage src/base/Tests/trp_file_usage src/modules/Makefile src/examples/Makefile src/examples/ping/Makefile src/examples/bandwidth/Makefile src/examples/saturate/Makefile src/examples/alnem/Makefile doc/Makefile" cat >confcache <<\_ACEOF @@ -23894,8 +23924,10 @@ do "src/include/modules/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/include/modules/Makefile" ;; "src/base/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/base/Makefile" ;; "src/base/Tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/base/Tests/Makefile" ;; - "src/base/Tests/gs_example" ) CONFIG_FILES="$CONFIG_FILES src/base/Tests/gs_example" ;; "src/base/Tests/run_tests" ) CONFIG_FILES="$CONFIG_FILES src/base/Tests/run_tests" ;; + "src/base/Tests/gs_example" ) CONFIG_FILES="$CONFIG_FILES src/base/Tests/gs_example" ;; + "src/base/Tests/trp_tcp_usage" ) CONFIG_FILES="$CONFIG_FILES src/base/Tests/trp_tcp_usage" ;; + "src/base/Tests/trp_file_usage" ) CONFIG_FILES="$CONFIG_FILES src/base/Tests/trp_file_usage" ;; "src/modules/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/modules/Makefile" ;; "src/examples/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/examples/Makefile" ;; "src/examples/ping/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/examples/ping/Makefile" ;; @@ -24018,6 +24050,7 @@ s,@install_sh@,$install_sh,;t t s,@STRIP@,$STRIP,;t t s,@ac_ct_STRIP@,$ac_ct_STRIP,;t t s,@INSTALL_STRIP_PROGRAM@,$INSTALL_STRIP_PROGRAM,;t t +s,@mkdir_p@,$mkdir_p,;t t s,@AWK@,$AWK,;t t s,@SET_MAKE@,$SET_MAKE,;t t s,@am__leading_dot@,$am__leading_dot,;t t @@ -24324,50 +24357,90 @@ s,@INSTALL@,$ac_INSTALL,;t t # Run the commands associated with the file. case $ac_file in Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/include/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/include/modules/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/base/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/base/Tests/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; - src/base/Tests/gs_example ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/base/Tests/run_tests ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + src/base/Tests/gs_example ) ( cd src/include ; test -e gras || ln -s . gras ) + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + src/base/Tests/trp_tcp_usage ) ( cd src/include ; test -e gras || ln -s . gras ) + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + src/base/Tests/trp_file_usage ) ( cd src/include ; test -e gras || ln -s . gras ) + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/modules/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/examples/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/examples/ping/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/examples/bandwidth/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/examples/saturate/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; src/examples/alnem/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; doc/Makefile ) ( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests ;; esac done _ACEOF @@ -24758,14 +24831,14 @@ echo X"$mf" | grep '^DEP_FILES *= *[^ #]' < "$mf" > /dev/null || continue # Extract the definition of DEP_FILES from the Makefile without # running `make'. - DEPDIR=`sed -n -e '/^DEPDIR = / s///p' < "$mf"` + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue # When using ansi2knr, U may be empty or an underscore; expand it - U=`sed -n -e '/^U = / s///p' < "$mf"` + U=`sed -n 's/^U = //p' < "$mf"` test -d "$dirpart/$DEPDIR" || mkdir "$dirpart/$DEPDIR" # We invoke sed twice because it is the simplest approach to # changing $(DEPDIR) to its actual value in the expansion. - for file in `sed -n -e ' + for file in `sed -n ' /^DEP_FILES = .*\\\\$/ { s/^DEP_FILES = // :loop diff --git a/configure.ac b/configure.ac index c25b215e75..81d79db54b 100644 --- a/configure.ac +++ b/configure.ac @@ -79,8 +79,10 @@ AC_CONFIG_FILES([ src/include/modules/Makefile src/base/Makefile src/base/Tests/Makefile - src/base/Tests/gs_example src/base/Tests/run_tests + src/base/Tests/gs_example + src/base/Tests/trp_tcp_usage + src/base/Tests/trp_file_usage src/modules/Makefile src/examples/Makefile src/examples/ping/Makefile @@ -88,8 +90,10 @@ AC_CONFIG_FILES([ src/examples/alnem/Makefile doc/Makefile ],[( cd src/include ; test -e gras || ln -s . gras ) - test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; - test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests]) + test -e src/base/Tests/trp_tcp_usage && chmod +x src/base/Tests/trp_tcp_usage; + test -e src/base/Tests/trp_file_usage && chmod +x src/base/Tests/trp_file_usage; + test -e src/base/Tests/gs_example && chmod +x src/base/Tests/gs_example; + test -e src/base/Tests/run_tests && chmod +x src/base/Tests/run_tests]) AC_OUTPUT diff --git a/cruft/doc/tmpl/comm_datadesc.sgml b/cruft/doc/tmpl/comm_datadesc.sgml index cf9fb92b64..cbfbfc9017 100644 --- a/cruft/doc/tmpl/comm_datadesc.sgml +++ b/cruft/doc/tmpl/comm_datadesc.sgml @@ -19,13 +19,13 @@ Simple ways to describe data to exchange +@name: @desc: @howmany: -@dst: +@code: @Returns: -@name: -@code: +@dst: @@ -33,13 +33,13 @@ Simple ways to describe data to exchange -@def: -@dst: -@Returns: - @name: @Cdefinition: @code: +@Returns: + +@def: +@dst: diff --git a/cruft/doc/tmpl/comm_socks.sgml b/cruft/doc/tmpl/comm_socks.sgml index 091054c71b..e918bf5898 100644 --- a/cruft/doc/tmpl/comm_socks.sgml +++ b/cruft/doc/tmpl/comm_socks.sgml @@ -21,8 +21,11 @@ Open/close sockets, and get info on peer. @host: @Param2: -@sock: +@bufSize: +@dst: @Returns: + +@sock: @@ -41,16 +44,9 @@ Open/close sockets, and get info on peer. -@sock: -@Returns: - - - - - - - @sd: + +@sock: @Returns: diff --git a/cruft/doc/tmpl/gras-unused.sgml b/cruft/doc/tmpl/gras-unused.sgml index 0fa4acbfbc..4bd27dcd56 100644 --- a/cruft/doc/tmpl/gras-unused.sgml +++ b/cruft/doc/tmpl/gras-unused.sgml @@ -1563,6 +1563,19 @@ Sockets @ud: + + + + + +@d1: +@d2: +@Returns: +@dd1: +@c1: +@dd2: +@c2: + @@ -1666,6 +1679,14 @@ Sockets @sock: @Returns: + + + + + +@sd: +@Returns: + diff --git a/cruft/doc/tmpl/gras_private.sgml b/cruft/doc/tmpl/gras_private.sgml index 170da1192e..0fe64db20b 100644 --- a/cruft/doc/tmpl/gras_private.sgml +++ b/cruft/doc/tmpl/gras_private.sgml @@ -23,21 +23,6 @@ gras_private @size: - - - - - -@d1: -@d2: -@Returns: - -@dd1: -@c1: -@dd2: -@c2: - - diff --git a/include/cond.h b/include/cond.h new file mode 100644 index 0000000000..b39485ab1f --- /dev/null +++ b/include/cond.h @@ -0,0 +1,58 @@ +/* $Id$ */ + +/* gras/cond.h - public interface to conditional execution */ +/* (specific parts for SG or RL) */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003,2004 da GRAS posse. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef GRAS_COND_H +#define GRAS_COND_H + +#include /* offsetof() */ +#include /* size_t */ +#include + + +/*! C++ users need love */ +#ifndef BEGIN_DECL +# ifdef __cplusplus +# define BEGIN_DECL extern "C" { +# else +# define BEGIN_DECL +# endif +#endif + +/*! C++ users need love */ +#ifndef END_DECL +# ifdef __cplusplus +# define END_DECL } +# else +# define END_DECL +# endif +#endif +/* End of cruft for C++ */ + +BEGIN_DECL + +/** + * gras_if_RL: + * + * Returns true only if the program runs on real life + */ +int gras_if_RL(void); + +/** + * gras_if_SG: + * + * Returns true only if the program runs within the simulator + */ +int gras_if_SG(void); + +END_DECL + +#endif /* GRAS_COND_H */ + diff --git a/include/core.h b/include/core.h index acabba10e9..190361632f 100644 --- a/include/core.h +++ b/include/core.h @@ -57,22 +57,6 @@ typedef enum { free_after_use, free_never } e_gras_free_directive_t; const char * gras_get_my_fqdn(void); -/** - * gras_time: - * - * Get the time in number of second since the Epoch. - * (00:00:00 UTC, January 1, 1970 in Real Life, and begining of simulation in SG) - */ -double gras_time(void); - -/** - * gras_sleep: - * @sec: number of seconds to sleep - * @usec: number of microseconds to sleep - * - * sleeps for the given amount of seconds plus the given amount of microseconds. - */ -void gras_sleep(unsigned long sec, unsigned long usec); END_DECL diff --git a/include/gras.h b/include/gras.h index 6cc6123bbe..1b0d8433cd 100644 --- a/include/gras.h +++ b/include/gras.h @@ -28,8 +28,10 @@ #include -#include +#include /* FIXME: killme */ #include +#include +#include #include diff --git a/include/module.h b/include/module.h index b9a3ee477e..d97da11e3b 100644 --- a/include/module.h +++ b/include/module.h @@ -17,5 +17,6 @@ typedef gras_module_t (*gras_module_new_fct_t)(int argc, char **argv); typedef int (*gras_module_finalize_fct_t)(void); void gras_init(int argc,char **argv); -void gras_finalize(void); +void gras_init_defaultlog(int argc,char **argv, const char *defaultlog); +void gras_exit(void); #endif /* _GRAS_MODULE_H */ diff --git a/include/transport.h b/include/transport.h index 123b9f60d5..ad0a1bd70c 100644 --- a/include/transport.h +++ b/include/transport.h @@ -17,12 +17,17 @@ typedef struct s_gras_socket gras_socket_t; gras_error_t gras_socket_client(const char *host, unsigned short port, - unsigned int bufSize, /* OUT */ gras_socket_t **dst); gras_error_t gras_socket_server(unsigned short port, - unsigned int bufSize, /* OUT */ gras_socket_t **dst); -void gras_socket_close(gras_socket_t *sd); - +void gras_socket_close(gras_socket_t **sd); + + +/* debuging functions */ +gras_error_t gras_socket_client_from_file(const char*path, + /* OUT */ gras_socket_t **dst); +gras_error_t gras_socket_server_from_file(const char*path, + /* OUT */ gras_socket_t **dst); + #endif /* GRAS_TRANSPORT_H */ diff --git a/include/virtu.h b/include/virtu.h new file mode 100644 index 0000000000..2466a33592 --- /dev/null +++ b/include/virtu.h @@ -0,0 +1,60 @@ +/* $Id$ */ + +/* gras/virtu.h - public interface to virtualization (cross-OS portability) */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003,2004 da GRAS posse. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef GRAS_VIRTU_H +#define GRAS_VIRTU_H + +#include /* offsetof() */ +#include /* size_t */ +#include + + +/*! C++ users need love */ +#ifndef BEGIN_DECL +# ifdef __cplusplus +# define BEGIN_DECL extern "C" { +# else +# define BEGIN_DECL +# endif +#endif + +/*! C++ users need love */ +#ifndef END_DECL +# ifdef __cplusplus +# define END_DECL } +# else +# define END_DECL +# endif +#endif +/* End of cruft for C++ */ + +BEGIN_DECL + +/** + * gras_time: + * + * Get the time in number of second since the Epoch. + * (00:00:00 UTC, January 1, 1970 in Real Life, and begining of simulation in SG) + */ +double gras_time(void); + +/** + * gras_sleep: + * @sec: number of seconds to sleep + * @usec: number of microseconds to sleep + * + * sleeps for the given amount of seconds plus the given amount of microseconds. + */ +void gras_sleep(unsigned long sec, unsigned long usec); + +END_DECL + +#endif /* GRAS_VIRTU_H */ + diff --git a/install-sh b/install-sh index 0ec27bcd48..77bc38144f 100755 --- a/install-sh +++ b/install-sh @@ -1,7 +1,8 @@ #!/bin/sh -# # install - install a program, script, or datafile -# + +scriptversion=2004-02-15.20 + # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. @@ -41,13 +42,11 @@ # from scratch. It can only install one file at a time, a restriction # shared with many OS's install programs. - # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit="${DOITPROG-}" - # put in absolute paths if you don't have them in your path; or use env. vars. mvprog="${MVPROG-mv}" @@ -59,236 +58,259 @@ stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" mkdirprog="${MKDIRPROG-mkdir}" -transformbasename="" -transform_arg="" +transformbasename= +transform_arg= instcmd="$mvprog" chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" +chowncmd= +chgrpcmd= +stripcmd= rmcmd="$rmprog -f" mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd=$cpprog - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd=$stripprog - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac +src= +dst= +dir_arg= + +usage="Usage: $0 [OPTION]... SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 -d DIRECTORIES... + +In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default. +In the second, create the directory path DIR. + +Options: +-b=TRANSFORMBASENAME +-c copy source (using $cpprog) instead of moving (using $mvprog). +-d create directories instead of installing files. +-g GROUP $chgrp installed files to GROUP. +-m MODE $chmod installed files to MODE. +-o USER $chown installed files to USER. +-s strip installed files (using $stripprog). +-t=TRANSFORM +--help display this help and exit. +--version display version info and exit. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG +" + +while test -n "$1"; do + case $1 in + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + -c) instcmd=$cpprog + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + --help) echo "$usage"; exit 0;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -s) stripcmd=$stripprog + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + --version) echo "$0 $scriptversion"; exit 0;; + + *) # When -d is used, all remaining arguments are directories to create. + test -n "$dir_arg" && break + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dstarg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dstarg" + shift # fnord + fi + shift # arg + dstarg=$arg + done + break;; + esac done -if [ x"$src" = x ] -then - echo "$0: no input file specified" >&2 - exit 1 -else - : +if test -z "$1"; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call `install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 fi -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d "$dst" ]; then - instcmd=: - chmodcmd="" - else - instcmd=$mkdirprog - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f "$src" ] || [ -d "$src" ] - then - : - else - echo "$0: $src does not exist" >&2 - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "$0: no destination specified" >&2 - exit 1 - else - : - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d "$dst" ] - then - dst=$dst/`basename "$src"` - else - : - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' - ' -IFS="${IFS-$defaultIFS}" - -oIFS=$IFS -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS=$oIFS - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp=$pathcomp$1 - shift - - if [ ! -d "$pathcomp" ] ; - then - $mkdirprog "$pathcomp" - else - : - fi +for src +do + # Protect names starting with `-'. + case $src in + -*) src=./$src ;; + esac + + if test -n "$dir_arg"; then + dst=$src + src= + + if test -d "$dst"; then + instcmd=: + chmodcmd= + else + instcmd=$mkdirprog + fi + else + # Waiting for this to be detected by the "$instcmd $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dstarg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + + dst=$dstarg + # Protect names starting with `-'. + case $dst in + -*) dst=./$dst ;; + esac - pathcomp=$pathcomp/ + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + dst=$dst/`basename "$src"` + fi + fi + + # This sed command emulates the dirname command. + dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + + # Make sure that the destination directory exists. + + # Skip lots of stat calls in the usual case. + if test ! -d "$dstdir"; then + defaultIFS=' + ' + IFS="${IFS-$defaultIFS}" + + oIFS=$IFS + # Some sh's can't handle IFS=/ for some reason. + IFS='%' + set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` + IFS=$oIFS + + pathcomp= + + while test $# -ne 0 ; do + pathcomp=$pathcomp$1 + shift + if test ! -d "$pathcomp"; then + $mkdirprog "$pathcomp" || lasterr=$? + # mkdir can fail with a `File exist' error in case several + # install-sh are creating the directory concurrently. This + # is OK. + test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; } + fi + pathcomp=$pathcomp/ + done + fi + + if test -n "$dir_arg"; then + $doit $instcmd "$dst" \ + && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } + + else + # If we're going to rename the final executable, determine the name now. + if test -z "$transformarg"; then + dstfile=`basename "$dst"` + else + dstfile=`basename "$dst" $transformbasename \ + | sed $transformarg`$transformbasename + fi + + # don't allow the sed command to completely eliminate the filename. + test -z "$dstfile" && dstfile=`basename "$dst"` + + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 + trap '(exit $?); exit' 1 2 13 15 + + # Move or copy the file name to the temp name + $doit $instcmd "$src" "$dsttmp" && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $instcmd $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && + + # Now remove or move aside any old file at destination location. We + # try this two ways since rm can't unlink itself on some systems and + # the destination file might be busy for other reasons. In this case, + # the final cleanup might fail but the new file should still install + # successfully. + { + if test -f "$dstdir/$dstfile"; then + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ + || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ + || { + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 + (exit 1); exit + } + else + : + fi + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" + fi || { (exit 1); exit; } done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd "$dst" && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename "$dst"` - else - dstfile=`basename "$dst" $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename "$dst"` - else - : - fi - -# Make a couple of temp file names in the proper directory. - - dsttmp=$dstdir/#inst.$$# - rmtmp=$dstdir/#rm.$$# - -# Trap to clean up temp files at exit. - - trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 - trap '(exit $?); exit' 1 2 13 15 - -# Move or copy the file name to the temp name - - $doit $instcmd "$src" "$dsttmp" && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi && - -# Now remove or move aside any old file at destination location. We try this -# two ways since rm can't unlink itself on some systems and the destination -# file might be busy for other reasons. In this case, the final cleanup -# might fail but the new file should still install successfully. - -{ - if [ -f "$dstdir/$dstfile" ] - then - $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null || - $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null || - { - echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 - (exit 1); exit - } - else - : - fi -} && - -# Now rename the file to the real destination. - - $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" - -fi && # The final little trick to "correctly" pass the exit status to the exit trap. - { - (exit 0); exit + (exit 0); exit } + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/src/gras/.cvsignore b/src/gras/.cvsignore index 155be66bd3..2045a0cdca 100644 --- a/src/gras/.cvsignore +++ b/src/gras/.cvsignore @@ -1 +1,2 @@ -.deps .libs Makefile Makefile.in dict_usage dict_crash dynar_int dynar_double dynar_string +.deps .libs Makefile Makefile.in +cscope.files cscope.out diff --git a/src/gras/Makefile.am b/src/gras/Makefile.am index 56f2a70e27..27ed9ed18c 100644 --- a/src/gras/Makefile.am +++ b/src/gras/Makefile.am @@ -10,8 +10,6 @@ EXTRA_DIST= \ lib_LIBRARIES= libgrasrl.a libgrassg.a -noinst_LIBRARIES=libgrasutils.a - # Core/dict_multi.c # Common/gras.c Common/gras_datadesc.c Common/gras_msg.c # Messaging/messaging.c @@ -20,7 +18,7 @@ noinst_LIBRARIES=libgrasutils.a COMMON_S=\ \ - Core/module.c \ + Core/module.c Core/core_interface.h \ Core/log.c Core/log_default_appender.c Core/error.c \ Core/dynar.c \ Core/dict.c Core/dict_elm.c Core/dict_cursor.c \ @@ -29,15 +27,15 @@ COMMON_S=\ Core/config.c \ \ Transport/transport.c Transport/transport_private.h \ - Transport/transport_plugin_tcp.c \ - Transport/transport_plugin_sg.c \ - \ + Transport/transport_plugin_file.c \ + Transport/transport_plugin_tcp.c \ + Transport/transport_plugin_sg.c \ \ DataDesc/ddt_create.c DataDesc/ddt_declare.c \ DataDesc/ddt_remote.c DataDesc/ddt_use.c \ DataDesc/cbps.c DataDesc/datadesc.c \ DataDesc/datadesc_interface.h DataDesc/datadesc_private.h - + # DataDesc/datadesc.c \ # DataDesc/tools.c \ # DataDesc/categories.h \ @@ -55,23 +53,12 @@ COMMON_S=\ DataDesc/parse.yy.c: DataDesc/parse.yy.l flex -o$@ -Pgras_ddt_ $^ -libgrasutils_a_SOURCES = $(COMMON_S) -#Tests/gras_dummy.c - libgrasrl_a_SOURCES= $(COMMON_S) \ Transport/rl_transport.c \ - Virtu/rl_process.c Virtu/rl_time.c + Virtu/rl_process.c Virtu/rl_time.c Virtu/rl_conditional.c libgrassg_a_SOURCES= $(COMMON_S) \ Transport/sg_transport.c \ - Virtu/sg_process.c Virtu/sg_time.c + Virtu/sg_process.c Virtu/sg_time.c Virtu/sg_conditional.c # RL/gras_rl.c RL/gras_rl.h FIXME - -# $(foreach file,\ -# exp_smooth forc median mse_forc protocol \ -# dnsutil fbuff forecast_api last_value run_mean timeouts, \ -# $(top_srcdir)/src/nws_portability/build-@host@/obj/$(file).o) - - - diff --git a/src/gras/Transport/rl_transport.c b/src/gras/Transport/rl_transport.c index fe19f91ab7..5069c428c5 100644 --- a/src/gras/Transport/rl_transport.c +++ b/src/gras/Transport/rl_transport.c @@ -17,43 +17,6 @@ GRAS_LOG_EXTERNAL_CATEGORY(transport); GRAS_LOG_DEFAULT_CATEGORY(transport); -gras_error_t -gras_socket_server(unsigned short port, - unsigned int bufSize, - /* OUT */ gras_socket_t **dst) { - - gras_error_t errcode; - gras_trp_plugin_t *tcp; - - TRY(gras_trp_plugin_get_by_name("TCP",&tcp)); - TRY( tcp->socket_server(tcp, port, bufSize, dst)); - - (*dst)->incoming = 1; - (*dst)->accepting = 1; - - TRY(gras_dynar_push(_gras_trp_sockets,dst)); - - return no_error; -} - -gras_error_t -gras_socket_client(const char *host, - unsigned short port, - unsigned int bufSize, - /* OUT */ gras_socket_t **dst) { - - gras_error_t errcode; - gras_trp_plugin_t *tcp; - - TRY(gras_trp_plugin_get_by_name("TCP",&tcp)); - TRY( (*tcp->socket_client)(tcp, host, port, bufSize, dst)); - - (*dst)->incoming = 0; - (*dst)->accepting = 0; - - return no_error; -} - /** * gras_trp_select: @@ -98,9 +61,13 @@ gras_trp_select(double timeout, /* construct the set of socket to ear from */ FD_ZERO(&FDS); gras_dynar_foreach(_gras_trp_sockets,cursor,sock_iter) { - if (max_fds < sock_iter->sd) - max_fds = sock_iter->sd; - FD_SET(sock_iter->sd, &FDS); + if (sock_iter->incoming) { + if (max_fds < sock_iter->sd) + max_fds = sock_iter->sd; + FD_SET(sock_iter->sd, &FDS); + } else { + DEBUG1("Not considering socket %d for select",sock_iter->sd); + } } /* we cannot have more than FD_SETSIZE sockets */ @@ -127,6 +94,7 @@ gras_trp_select(double timeout, p_tout = NULL; } + DEBUG1("Selecting over %d socket(s)", max_fds-1); ready = select(max_fds, &FDS, NULL, NULL, p_tout); if (ready == -1) { switch (errno) { @@ -163,6 +131,8 @@ gras_trp_select(double timeout, TRY(sock_iter->plugin->socket_accept(sock_iter,&accepted)); TRY(gras_dynar_push(_gras_trp_sockets,&accepted)); } else { +#if 0 + FIXME: this fails of files. quite logical /* Make sure the socket is still alive by reading the first byte */ char lookahead; int recvd; @@ -171,18 +141,21 @@ gras_trp_select(double timeout, if (recvd < 0) { WARNING2("socket %d failed: %s", sock_iter->sd, strerror(errno)); /* done with this socket */ - gras_socket_close(sock_iter); + gras_socket_close(&sock_iter); cursor--; } else if (recvd == 0) { /* Connection reset (=closed) by peer. */ DEBUG1("Connection %d reset by peer", sock_iter->sd); - gras_socket_close(sock_iter); + gras_socket_close(&sock_iter); cursor--; } else { +#endif /* Got a suited socket ! */ *dst = sock_iter; return no_error; +#if 0 } +#endif } diff --git a/src/gras/Transport/transport.c b/src/gras/Transport/transport.c index 15874f4d9d..4b5d45a78e 100644 --- a/src/gras/Transport/transport.c +++ b/src/gras/Transport/transport.c @@ -41,7 +41,13 @@ gras_trp_init(void){ /* TCP */ TRY(gras_trp_tcp_init(&plug)); - TRY(gras_dict_insert(_gras_trp_plugins,plug->name, plug, gras_trp_plugin_free)); + TRY(gras_dict_insert(_gras_trp_plugins, + plug->name, plug, gras_trp_plugin_free)); + + /* FILE */ + TRY(gras_trp_file_init(&plug)); + TRY(gras_dict_insert(_gras_trp_plugins, + plug->name, plug, gras_trp_plugin_free)); return no_error; } @@ -65,20 +71,145 @@ void gras_trp_plugin_free(void *p) { } } -void gras_socket_close(gras_socket_t *sock) { + +/** + * gras_trp_socket_new: + * + * Malloc a new socket, and initialize it with defaults + */ +gras_error_t gras_trp_socket_new(int incoming, + gras_socket_t **dst) { + + gras_socket_t *sock; + + if (! (sock=malloc(sizeof(gras_socket_t))) ) + RAISE_MALLOC; + + sock->plugin = NULL; + sock->sd = -1; + + sock->incoming = incoming? 1:0; + sock->outgoing = incoming? 0:1; + sock->accepting = incoming? 1:0; + DEBUG3("in=%c out=%c accept=%c", + sock->incoming?'y':'n', + sock->outgoing?'y':'n', + sock->accepting?'y':'n'); + + sock->port = -1; + sock->peer_port = -1; + sock->peer_name = NULL; + + *dst = sock; + return no_error; +} + + +/** + * gras_socket_server: + * + * Opens a server socket and make it ready to be listened to. + * In real life, you'll get a TCP socket. + */ +gras_error_t +gras_socket_server(unsigned short port, + /* OUT */ gras_socket_t **dst) { + + gras_error_t errcode; + gras_trp_plugin_t *trp; + gras_socket_t *sock; + + *dst = NULL; + + TRY(gras_trp_plugin_get_by_name(gras_if_RL() ? "TCP" : "SG", + &trp)); + + /* defaults settings */ + TRY(gras_trp_socket_new(1,&sock)); + sock->plugin= trp; + sock->port=port; + + /* Call plugin socket creation function */ + errcode = trp->socket_server(trp, port, sock); + if (errcode != no_error) { + free(sock); + return errcode; + } + + *dst = sock; + /* Register this socket */ + errcode = gras_dynar_push(_gras_trp_sockets,dst); + if (errcode != no_error) { + free(sock); + *dst = NULL; + return errcode; + } + + return no_error; +} + +/** + * gras_socket_client: + * + * Opens a client socket to a remote host. + * In real life, you'll get a TCP socket. + */ +gras_error_t +gras_socket_client(const char *host, + unsigned short port, + /* OUT */ gras_socket_t **dst) { + + gras_error_t errcode; + gras_trp_plugin_t *trp; + gras_socket_t *sock; + + *dst = NULL; + + TRY(gras_trp_plugin_get_by_name(gras_if_RL() ? "TCP" : "SG", + &trp)); + + /* defaults settings */ + TRY(gras_trp_socket_new(0,&sock)); + sock->plugin= trp; + sock->peer_port = port; + sock->peer_name = strdup(host?host:"localhost"); + + /* plugin-specific */ + errcode= (* trp->socket_client)(trp, + host ? host : "localhost", port, + sock); + if (errcode != no_error) { + free(sock); + return errcode; + } + + /* register socket */ + *dst = sock; + errcode = gras_dynar_push(_gras_trp_sockets,dst); + if (errcode != no_error) { + free(sock); + *dst = NULL; + return errcode; + } + + return no_error; +} + +void gras_socket_close(gras_socket_t **sock) { gras_socket_t *sock_iter; int cursor; /* FIXME: Issue an event when the socket is closed */ - if (sock) { + if (sock && *sock) { gras_dynar_foreach(_gras_trp_sockets,cursor,sock_iter) { - if (sock == sock_iter) { + if (*sock == sock_iter) { gras_dynar_cursor_rm(_gras_trp_sockets,&cursor); - if (sock->plugin->socket_close) - (*sock->plugin->socket_close)(sock); + if ( (*sock)->plugin->socket_close) + (* (*sock)->plugin->socket_close)(*sock); /* free the memory */ - free(sock); + free(*sock); + *sock=NULL; return; } } @@ -95,6 +226,12 @@ gras_error_t gras_trp_chunk_send(gras_socket_t *sd, char *data, size_t size) { + gras_assert1(sd->outgoing, + "Socket not suited for data send (outgoing=%c)", + sd->outgoing?'y':'n'); + gras_assert1(sd->plugin->chunk_send, + "No function chunk_send on transport plugin %s", + sd->plugin->name); return (*sd->plugin->chunk_send)(sd,data,size); } /** @@ -102,10 +239,16 @@ gras_trp_chunk_send(gras_socket_t *sd, * * Receive a bunch of bytes from a socket */ -gras_error_t gras_trp_chunk_recv(gras_socket_t *sd, - char *data, - size_t size) { - return (*sd->plugin->chunk_recv)(sd,data,size); +gras_error_t +gras_trp_chunk_recv(gras_socket_t *sd, + char *data, + size_t size) { + gras_assert0(sd->incoming, + "Socket not suited for data receive"); + gras_assert1(sd->plugin->chunk_recv, + "No function chunk_recv on transport plugin %s", + sd->plugin->name); + return (sd->plugin->chunk_recv)(sd,data,size); } diff --git a/src/gras/Transport/transport_interface.h b/src/gras/Transport/transport_interface.h index 44f8dc3614..d24e43aa70 100644 --- a/src/gras/Transport/transport_interface.h +++ b/src/gras/Transport/transport_interface.h @@ -13,8 +13,6 @@ #ifndef GRAS_TRP_INTERFACE_H #define GRAS_TRP_INTERFACE_H -#include "gras_private.h" - /*** *** Main user functions ***/ @@ -60,15 +58,16 @@ typedef enum e_gras_trp_plugin { struct gras_trp_plugin_ { char *name; + /* dst pointers are created and initialized with default values + before call to socket_client/server*/ gras_error_t (*socket_client)(gras_trp_plugin_t *self, const char *host, unsigned short port, - unsigned int bufSize, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *dst); gras_error_t (*socket_server)(gras_trp_plugin_t *self, unsigned short port, - unsigned int bufSize, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *dst); + gras_error_t (*socket_accept)(gras_socket_t *sock, /* OUT */gras_socket_t **dst); diff --git a/src/gras/Transport/transport_plugin_file.c b/src/gras/Transport/transport_plugin_file.c new file mode 100644 index 0000000000..74774ae244 --- /dev/null +++ b/src/gras/Transport/transport_plugin_file.c @@ -0,0 +1,286 @@ +/* $Id$ */ + +/* File transport - send/receive a bunch of bytes from a file */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2004 Martin Quinson. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include +#include +#include +#include + +#include "gras_private.h" +#include "transport_private.h" + +GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(trp_file,transport); + +typedef struct { + int buffsize; +} gras_trp_tcp_sock_specific_t; + +/*** + *** Prototypes + ***/ +void gras_trp_file_close(gras_socket_t *sd); + +gras_error_t gras_trp_file_chunk_send(gras_socket_t *sd, + char *data, + size_t size); + +gras_error_t gras_trp_file_chunk_recv(gras_socket_t *sd, + char *data, + size_t size); + +void gras_trp_file_free_specific(void *s); + +/*** + *** Specific plugin part + ***/ + +typedef struct { + fd_set incoming_socks; +} gras_trp_file_specific_t; + +/*** + *** Specific socket part + ***/ + + +/*** + *** Code + ***/ +gras_error_t +gras_trp_file_init(gras_trp_plugin_t **dst) { + + gras_trp_plugin_t *res=malloc(sizeof(gras_trp_plugin_t)); + gras_trp_file_specific_t *specif = malloc(sizeof(gras_trp_file_specific_t)); + if (!res || !specif) + RAISE_MALLOC; + + FD_ZERO(&(specif->incoming_socks)); + + res->name = strdup("file"); + res->socket_client = NULL; + res->socket_server = NULL; + res->socket_accept = NULL; + res->socket_close = gras_trp_file_close; + + res->chunk_send = gras_trp_file_chunk_send; + res->chunk_recv = gras_trp_file_chunk_recv; + + res->specific = (void*)specif; + res->free_specific = gras_trp_file_free_specific; + + *dst = res; + return no_error; +} + +void gras_trp_file_free_specific(void *s) { + gras_trp_file_specific_t *specific = s; + free(specific); +} + +/** + * gras_socket_client_from_file: + * + * Create a client socket from a file path. + * + * This only possible in RL, and is mainly for debugging. + */ +gras_error_t +gras_socket_client_from_file(const char*path, + /* OUT */ gras_socket_t **dst) { + gras_error_t errcode; + gras_trp_plugin_t *trp; + + gras_assert0(gras_if_RL(), + "Cannot use file as socket in the simulator"); + + TRY(gras_trp_socket_new(0,dst)); + + TRY(gras_trp_plugin_get_by_name("file",&trp)); + (*dst)->plugin=trp; + + DEBUG3("in=%c out=%c accept=%c", + (*dst)->incoming?'y':'n', + (*dst)->outgoing?'y':'n', + (*dst)->accepting?'y':'n'); + + if (strcmp("-", path)) { + (*dst)->sd = open(path, O_RDONLY ); + + if ( (*dst)->sd < 0) { + RAISE2(system_error, + "Cannot create a client socket from file %s: %s", + path, strerror(errno)); + } + } else { + (*dst)->sd = 1; /* stdout */ + } + + DEBUG4("sd=%d in=%c out=%c accept=%c", + (*dst)->sd, + (*dst)->incoming?'y':'n', + (*dst)->outgoing?'y':'n', + (*dst)->accepting?'y':'n'); + /* register socket */ + errcode = gras_dynar_push(_gras_trp_sockets,dst); + if (errcode != no_error) { + free(*dst); + *dst = NULL; + return errcode; + } + + return no_error; +} + +/** + * gras_socket_server_from_file: + * + * Create a server socket from a file path. + * + * This only possible in RL, and is mainly for debugging. + */ +gras_error_t +gras_socket_server_from_file(const char*path, + /* OUT */ gras_socket_t **dst) { + gras_error_t errcode; + gras_trp_plugin_t *trp; + + gras_assert0(gras_if_RL(), + "Cannot use file as socket in the simulator"); + + TRY(gras_trp_socket_new(1,dst)); + + TRY(gras_trp_plugin_get_by_name("file",&trp)); + (*dst)->plugin=trp; + + + if (strcmp("-", path)) { + (*dst)->sd = open(path, O_WRONLY ); + + if ( (*dst)->sd < 0) { + RAISE2(system_error, + "Cannot create a server socket from file %s: %s", + path, strerror(errno)); + } + } else { + (*dst)->sd = 0; /* stdin */ + } + + DEBUG4("sd=%d in=%c out=%c accept=%c", + (*dst)->sd, + (*dst)->incoming?'y':'n', + (*dst)->outgoing?'y':'n', + (*dst)->accepting?'y':'n'); + + /* register socket */ + errcode = gras_dynar_push(_gras_trp_sockets,dst); + if (errcode != no_error) { + free(*dst); + *dst = NULL; + return errcode; + } + + return no_error; +} + +void gras_trp_file_close(gras_socket_t *sock){ + gras_trp_file_specific_t *specific; + + if (!sock) return; /* close only once */ + specific=sock->plugin->specific; + + if (sock->sd == 0) { + DEBUG0("Do not close stdin"); + } else if (sock->sd == 1) { + DEBUG0("Do not close stdout"); + } else { + DEBUG1("close file connection %d\n", sock->sd); + + /* forget about the socket */ + FD_CLR(sock->sd, &(specific->incoming_socks)); + + /* close the socket */ + if(close(sock->sd) < 0) { + WARNING2("error while closing file %d: %s\n", + sock->sd, strerror(errno)); + } + } +} + +/** + * gras_trp_file_chunk_send: + * + * Send data on a file pseudo-socket + */ +gras_error_t +gras_trp_file_chunk_send(gras_socket_t *sock, + char *data, + size_t size) { + + gras_assert0(size >= 0, "Cannot send a negative amount of data"); + + while (size) { + int status = 0; + + status = write(sock->sd, data, (size_t)size); + DEBUG3("write(%d, %p, %ld);\n", sock->sd, data, size); + + if (status == -1) { + RAISE4(system_error,"write(%d,%p,%d) failed: %s", + sock->sd, data, (int)size, + strerror(errno)); + } + + if (status) { + size -= status; + data += status; + } else { + RAISE0(system_error,"file descriptor closed"); + } + } + + return no_error; +} +/** + * gras_trp_file_chunk_recv: + * + * Receive data on a file pseudo-socket. + */ +gras_error_t +gras_trp_file_chunk_recv(gras_socket_t *sock, + char *data, + size_t size) { + + /* TCP sockets are in duplex mode, don't check direction */ + gras_assert0(sock, "Cannot recv on an NULL socket"); + gras_assert0(size >= 0, "Cannot receive a negative amount of data"); + + while (size) { + int status = 0; + + status = read(sock->sd, data, (size_t)size); + DEBUG3("read(%d, %p, %ld);\n", sock->sd, data, size); + + if (status == -1) { + RAISE4(system_error,"read(%d,%p,%d) failed: %s", + sock->sd, data, (int)size, + strerror(errno)); + } + + if (status) { + size -= status; + data += status; + } else { + RAISE0(system_error,"file descriptor closed"); + } + } + + return no_error; +} + diff --git a/src/gras/Transport/transport_plugin_sg.c b/src/gras/Transport/transport_plugin_sg.c index 27790588a2..822812e177 100644 --- a/src/gras/Transport/transport_plugin_sg.c +++ b/src/gras/Transport/transport_plugin_sg.c @@ -26,11 +26,9 @@ void gras_trp_sg_exit(gras_trp_plugin_t *plugin); gras_error_t gras_trp_sg_socket_client(const char *host, unsigned short port, int raw, - unsigned int bufSize, /* OUT */ gras_socket_t **dst); gras_error_t gras_trp_sg_socket_server(unsigned short port, int raw, - unsigned int bufSize, /* OUT */ gras_socket_t **dst); void gras_trp_sg_socket_close(gras_socket_t **sd); gras_error_t gras_trp_sg_select(double timeOut, @@ -81,14 +79,12 @@ gras_trp_sg_exit(gras_trp_plugin_t *plugin) { gras_error_t gras_trp_sg_socket_client(const char *host, unsigned short port, int raw, - unsigned int bufSize, /* OUT */ gras_socket_t **dst){ RAISE_UNIMPLEMENTED; } gras_error_t gras_trp_sg_socket_server(unsigned short port, int raw, - unsigned int bufSize, /* OUT */ gras_socket_t **dst){ RAISE_UNIMPLEMENTED; } diff --git a/src/gras/Transport/transport_plugin_tcp.c b/src/gras/Transport/transport_plugin_tcp.c index 490ceeb430..3d0cd1625a 100644 --- a/src/gras/Transport/transport_plugin_tcp.c +++ b/src/gras/Transport/transport_plugin_tcp.c @@ -19,7 +19,7 @@ #include /* waitpid() */ #include /* getpeername() socket() */ #include - +#include /* memset */ #include "gras_private.h" #include "transport_private.h" @@ -36,24 +36,22 @@ typedef struct { gras_error_t gras_trp_tcp_socket_client(gras_trp_plugin_t *self, const char *host, unsigned short port, - unsigned int bufSize, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *sock); gras_error_t gras_trp_tcp_socket_server(gras_trp_plugin_t *self, unsigned short port, - unsigned int bufSize, - /* OUT */ gras_socket_t **dst); + /* OUT */ gras_socket_t *sock); gras_error_t gras_trp_tcp_socket_accept(gras_socket_t *sock, gras_socket_t **dst); void gras_trp_tcp_socket_close(gras_socket_t *sd); -gras_error_t gras_trp_tcp_bloc_send(gras_socket_t *sd, - char *data, - size_t size); +gras_error_t gras_trp_tcp_chunk_send(gras_socket_t *sd, + char *data, + size_t size); -gras_error_t gras_trp_tcp_bloc_recv(gras_socket_t *sd, - char *data, - size_t size); +gras_error_t gras_trp_tcp_chunk_recv(gras_socket_t *sd, + char *data, + size_t size); void gras_trp_tcp_free_specific(void *s); @@ -85,11 +83,15 @@ gras_trp_tcp_init(gras_trp_plugin_t **dst) { FD_ZERO(&(tcp->incoming_socks)); + res->name = strdup("TCP"); res->socket_client = gras_trp_tcp_socket_client; res->socket_server = gras_trp_tcp_socket_server; res->socket_accept = gras_trp_tcp_socket_accept; res->socket_close = gras_trp_tcp_socket_close; + res->chunk_send = gras_trp_tcp_chunk_send; + res->chunk_recv = gras_trp_tcp_chunk_recv; + res->specific = (void*)tcp; res->free_specific = gras_trp_tcp_free_specific; @@ -105,92 +107,88 @@ void gras_trp_tcp_free_specific(void *s) { gras_error_t gras_trp_tcp_socket_client(gras_trp_plugin_t *self, const char *host, unsigned short port, - unsigned int bufSize, - /* OUT */ gras_socket_t **dst){ - - int addrCount; - IPAddress addresses[10]; - int i; - int sd; + /* OUT */ gras_socket_t *sock){ - if (!(*sock=malloc(sizeof(gras_socket_t)))) - RAISE_MALLOC; + struct sockaddr_in addr; + struct hostent *he; + struct in_addr *haddr; + + sock->incoming = 1; /* TCP sockets are duplex'ed */ + + sock->sd = socket (AF_INET, SOCK_STREAM, 0); - (*sock)->peer_addr=NULL; + if (sock->sd < 0) { + RAISE1(system_error, + "Failed to create socket: %s", + strerror (errno)); + } - if (!(addrCount = IPAddressValues(host, addresses, 10))) { + he = gethostbyname (host); + if (he == NULL) { RAISE2(system_error, - "tcp address retrieval of '%s' failed: %s", - host,strerror(errno)); + "Failed to lookup hostname %s: %s", + host, strerror (errno)); } - for(i = 0; i < addrCount && i<10 ; i++) { - if(CallAddr(addresses[i], port, &sd, -1)) { - (*sock)->sock = sd; - (*sock)->port = port; - return no_error; - } + haddr = ((struct in_addr *) (he->h_addr_list)[0]); + + memset(&addr, 0, sizeof(struct sockaddr_in)); + memcpy (&addr.sin_addr, haddr, sizeof(struct in_addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons (port); + + if (connect (sock->sd, (struct sockaddr*) &addr, sizeof (addr)) < 0) { + close(sock->sd); + RAISE3(system_error, + "Failed to connect socket to %s:%d (%s)", + host, port, strerror (errno)); } - free(*sock); - RAISE2(system_error,"Something wicked happenned while connecting to %s:%d", - host,port); + + return no_error; } /** * gras_trp_tcp_socket_server: * - * Open a socket used to receive messages. bufSize is in ko. + * Open a socket used to receive messages. */ gras_error_t gras_trp_tcp_socket_server(gras_trp_plugin_t *self, unsigned short port, - unsigned int bufSize, - /* OUT */ gras_socket_t **dst){ - int size = bufSize * 1024; + /* OUT */ gras_socket_t *sock){ +// int size = bufSize * 1024; int on = 1; - int sd = -1; struct sockaddr_in server; - gras_socket_t *res; gras_trp_tcp_specific_t *data=(gras_trp_tcp_specific_t*)self -> specific; - res=malloc(sizeof(gras_socket_t)); - if (!res) - RAISE_MALLOC; + sock->outgoing = 1; /* TCP => duplex mode */ server.sin_port = htons((u_short)port); server.sin_addr.s_addr = INADDR_ANY; server.sin_family = AF_INET; - if((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - free(res); + if((sock->sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { RAISE1(system_error,"socket allocation failed: %s", strerror(errno)); } - (void)setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); + (void)setsockopt(sock->sd, SOL_SOCKET, SO_REUSEADDR, + (char *)&on, sizeof(on)); + /* (void)setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size)); (void)setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (char *)&size, sizeof(size)); - if (bind(sd, (struct sockaddr *)&server, sizeof(server)) == -1) { - free(res); - close(sd); + */ + if (bind(sock->sd, (struct sockaddr *)&server, sizeof(server)) == -1) { + close(sock->sd); RAISE2(system_error,"Cannot bind to port %d: %s",port, strerror(errno)); } - if (listen(sd, 5) != -1) { - free(res); - close(sd); + if (listen(sock->sd, 5) < 0) { + close(sock->sd); RAISE2(system_error,"Cannot listen to port %d: %s",port,strerror(errno)); } - FD_SET(sd, &(data->incoming_socks)); + FD_SET(sock->sd, &(data->incoming_socks)); - *dst=res; - res->plugin = self; - res->incoming = 1; - res->sd = sd; - res->port=port; - res->peer_port=-1; - res->peer_name=NULL; - - DEBUG2("Openned a server socket on port %d (sock %d)",port,sd); + DEBUG2("Openned a server socket on port %d (sock %d)",port,sock->sd); return no_error; } @@ -214,7 +212,7 @@ gras_trp_tcp_socket_accept(gras_socket_t *sock, tmp_errno = errno; if(sd == -1) { - gras_socket_close(sock); + gras_socket_close(&sock); RAISE1(system_error, "Accept failed (%s). Droping server socket.", strerror(tmp_errno)); } else { @@ -226,18 +224,23 @@ gras_trp_tcp_socket_accept(gras_socket_t *sock, WARNING0("setsockopt failed, cannot condition the accepted socket"); } + /* FIXME: bufSize removed until we can have optionsets i = ((gras_trp_tcp_sock_specific_t*)sock->specific)->buffsize; if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (char *)&i, s) || setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (char *)&i, s)) { WARNING0("setsockopt failed, cannot set buffsize"); } - - res->plugin = sock->plugin; - res->incoming = 1; - res->sd = sd; - res->port= -1; - res->peer_port= peer_in.sin_port; - + */ + + res->plugin = sock->plugin; + res->incoming = sock->incoming; + res->outgoing = sock->outgoing; + res->accepting = 0; + res->sd = sd; + res->port = -1; + res->peer_port = peer_in.sin_port; + + /* FIXME: Lock to protect inet_ntoa */ if (((struct sockaddr *)&peer_in)->sa_family != AF_INET) { res->peer_name = strdup("unknown"); } else { @@ -248,7 +251,7 @@ gras_trp_tcp_socket_accept(gras_socket_t *sock, tmp = inet_ntoa(addrAsInAddr); if (tmp != NULL) { - res->peer_name = strdup(inet_ntoa(addrAsInAddr)); + res->peer_name = strdup(tmp); } else { res->peer_name = strdup("unknown"); } @@ -284,14 +287,14 @@ void gras_trp_tcp_socket_close(gras_socket_t *sock){ } } */ + /* forget about the socket */ + FD_CLR(sock->sd, &(tcp->incoming_socks)); + /* close the socket */ if(close(sock->sd) < 0) { - WARNING3("error while closing tcp socket %d: %d (%s)\n", sock->sd, errno, strerror(errno)); + WARNING3("error while closing tcp socket %d: %d (%s)\n", + sock->sd, errno, strerror(errno)); } - - /* forget about it */ - FD_CLR(sock->sd, &(tcp->incoming_socks)); - } /** @@ -304,8 +307,7 @@ gras_trp_tcp_chunk_send(gras_socket_t *sock, char *data, size_t size) { - /* gras_assert0(sock && !sock->incoming, - "Asked to send stuff on an incomming socket");*/ + /* TCP sockets are in duplex mode, don't check direction */ gras_assert0(size >= 0, "Cannot send a negative amount of data"); while (size) { @@ -339,8 +341,9 @@ gras_error_t gras_trp_tcp_chunk_recv(gras_socket_t *sock, char *data, size_t size) { - gras_assert0(sock && !sock->incoming, - "Ascked to receive stuff on an outcomming socket"); + + /* TCP sockets are in duplex mode, don't check direction */ + gras_assert0(sock, "Cannot recv on an NULL socket"); gras_assert0(size >= 0, "Cannot receive a negative amount of data"); while (size) { diff --git a/src/gras/Transport/transport_private.h b/src/gras/Transport/transport_private.h index f94b58b238..543f6bec63 100644 --- a/src/gras/Transport/transport_private.h +++ b/src/gras/Transport/transport_private.h @@ -27,11 +27,12 @@ extern gras_dynar_t *_gras_trp_sockets; /* all existing sockets */ struct s_gras_socket { gras_trp_plugin_t *plugin; + + int incoming :1; /* true if we can read from this sock */ + int outgoing :1; /* true if we can write on this sock */ + int accepting :1; /* true if master incoming sock in tcp */ - int incoming; /* true if incoming (server) sock, false if client sock */ - int accepting; /* true if master incoming sock in tcp */ - - int sd; + int sd; int port; /* port on this side */ int peer_port; /* port on the other side */ char *peer_name; /* hostname of the other side */ @@ -39,11 +40,12 @@ struct s_gras_socket { void *specific; /* plugin specific data */ }; +gras_error_t gras_trp_socket_new(int incomming, + gras_socket_t **dst); -/* TCP driver */ +/* The drivers */ gras_error_t gras_trp_tcp_init(gras_trp_plugin_t **dst); - -/* SG driver */ +gras_error_t gras_trp_file_init(gras_trp_plugin_t **dst); gras_error_t gras_trp_sg_init (gras_trp_plugin_t **dst); diff --git a/src/gras/Virtu/rl_conditional.c b/src/gras/Virtu/rl_conditional.c new file mode 100644 index 0000000000..c364faf8f5 --- /dev/null +++ b/src/gras/Virtu/rl_conditional.c @@ -0,0 +1,19 @@ +/* $Id$ */ + +/* rl_conditional - conditional execution (real life) */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003,2004 da GRAS posse. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "Virtu/virtu_rl.h" + +int gras_if_RL(void) { + return 1; +} + +int gras_if_SG(void) { + return 0; +} diff --git a/src/gras/Virtu/sg_conditional.c b/src/gras/Virtu/sg_conditional.c new file mode 100644 index 0000000000..7ae9d76f8d --- /dev/null +++ b/src/gras/Virtu/sg_conditional.c @@ -0,0 +1,19 @@ +/* $Id$ */ + +/* rl_conditional - conditional execution (simulation) */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003,2004 da GRAS posse. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "Virtu/virtu_rl.h" + +int gras_if_RL(void) { + return 0; +} + +int gras_if_SG(void) { + return 1; +} diff --git a/src/gras/gras_private.h b/src/gras/gras_private.h index d4031e267b..23b88e1989 100644 --- a/src/gras/gras_private.h +++ b/src/gras/gras_private.h @@ -34,6 +34,8 @@ #include "gras/core.h" #include "gras/process.h" +#include "gras/virtu.h" +#include "gras/cond.h" #include "gras/transport.h" #include "Transport/transport_interface.h" diff --git a/src/xbt/core_interface.h b/src/xbt/core_interface.h new file mode 100644 index 0000000000..4fedcd20f1 --- /dev/null +++ b/src/xbt/core_interface.h @@ -0,0 +1,19 @@ +/* $Id$ */ + +/* core - very basic functionnalities of GRAS (logs, data container, ...) */ + +/* module's public interface exported within GRAS, but not to end user. */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2004 Martin Quinson. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef GRAS_CORE_INTERFACE_H +#define GRAS_CORE_INTERFACE_H + +/* Modules definitions */ +void gras_log_exit(void); + +#endif /* GRAS_CORE_INTERFACE_H */ diff --git a/src/xbt/log.c b/src/xbt/log.c index a9c834aa94..cb07747b23 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -8,6 +8,7 @@ /* This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU LGPL) which comes with this package. */ +#include "Core/core_interface.h" #include "gras_private.h" #include #include @@ -366,7 +367,6 @@ void gras_log_appender_set(gras_log_category_t* cat, gras_log_appender_t* app) { cat->appender = app; } -void gras_log_finalize(void); -void gras_log_finalize(void) { +void gras_log_exit(void) { gras_dynar_free(gras_log_settings); } diff --git a/src/xbt/module.c b/src/xbt/module.c index f21cd23fde..65638c8629 100644 --- a/src/xbt/module.c +++ b/src/xbt/module.c @@ -12,7 +12,7 @@ GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(module,GRAS); -extern void gras_log_finalize(void); +extern void gras_log_exit(void); struct gras_module_ { gras_dynar_t *deps; @@ -22,38 +22,53 @@ struct gras_module_ { gras_module_finalize_fct_t finalize; }; +void +gras_init(int argc, char **argv) { + gras_init_defaultlog(argc, argv, NULL); +} /** - * gras_init: + * gras_init_defaultlog: * @argc: * @argv: * * Initialize the gras mecanisms. */ void -gras_init(int argc,char **argv) { +gras_init_defaultlog(int argc,char **argv, const char *defaultlog) { int i; char *opt; gras_error_t errcode; + int found=0; INFO0("Initialize GRAS"); + + /** Set logs and init log submodule */ for (i=1; i +#include +#include "../Transport/transport_interface.h" + +//GRAS_LOG_NEW_DEFAULT_CATEGORY(test); + +int main(int argc,char *argv[]) { + gras_socket_t *sock, *conn; + gras_error_t errcode; + char data_recv[256]; + + gras_init_defaultlog(argc,argv,"trp.thresh=debug"); + + fprintf(stderr,"===[SERVER]=== Create the socket\n"); + TRYFAIL(gras_socket_server_from_file("-",&sock)); + + fprintf(stderr,"===[SERVER]=== Waiting for incomming connexions\n"); + TRYFAIL(gras_trp_select(60,&conn)); + + fprintf(stderr,"===[SERVER]=== Contacted ! Waiting for the data\n"); + TRYFAIL(gras_trp_chunk_recv(conn,data_recv, sizeof(data_recv))); + fprintf(stderr,"===[SERVER]=== Got '%s'.\n", data_recv); + + fprintf(stderr,"===[SERVER]=== Exiting successfully\n"); + gras_socket_close(&sock); + + return 0; +} diff --git a/testsuite/gras/trp_file_usage.in b/testsuite/gras/trp_file_usage.in new file mode 100644 index 0000000000..4d17f50cd1 --- /dev/null +++ b/testsuite/gras/trp_file_usage.in @@ -0,0 +1,4 @@ +#! @BASH@ -e + +./trp_file_client $@ | ./trp_file_server $@ + diff --git a/testsuite/gras/trp_tcp_client.c b/testsuite/gras/trp_tcp_client.c new file mode 100644 index 0000000000..671e283fcd --- /dev/null +++ b/testsuite/gras/trp_tcp_client.c @@ -0,0 +1,43 @@ +/* $Id$ */ + +/* trp_tcp_client: Client of a test case for the tcp transport. */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003 the OURAGAN project. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include +#include +#include "../Transport/transport_interface.h" + +//GRAS_LOG_NEW_DEFAULT_CATEGORY(test); + +int main(int argc,char *argv[]) { + gras_socket_t * sock; + gras_error_t errcode; + char data_send[256]; + char data_recv[256]; + + gras_init_defaultlog(argc,argv,"trp.thresh=debug"); + + fprintf(stderr,"===[CLIENT]=== Contact the server\n"); + TRYFAIL(gras_socket_client(NULL,55555,&sock)); + + sprintf(data_send,"Hello, I am a little test data to send."); + fprintf(stderr,"===[CLIENT]=== Send data\n"); + TRYFAIL(gras_trp_chunk_send(sock,data_send, sizeof(data_send))); + fprintf(stderr,"===[CLIENT]=== Waiting for the ACK\n"); + TRYFAIL(gras_trp_chunk_recv(sock,data_recv, sizeof(data_recv))); + + if (strcmp(data_send, data_recv)) { + fprintf(stderr, "===[CLIENT]=== String sent != string received\n"); + exit(1); + } + fprintf(stderr,"===[CLIENT]=== Got a valid ACK\n"); + + fprintf(stderr,"===[CLIENT]=== Exiting successfully\n"); + gras_socket_close(&sock); + return 0; +} diff --git a/testsuite/gras/trp_tcp_server.c b/testsuite/gras/trp_tcp_server.c new file mode 100644 index 0000000000..7c33b4723f --- /dev/null +++ b/testsuite/gras/trp_tcp_server.c @@ -0,0 +1,40 @@ +/* $Id$ */ + +/* trp_tcp_server: Server of a test case for the tcp transport. */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003 the OURAGAN project. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include +#include +#include "../Transport/transport_interface.h" + +//GRAS_LOG_NEW_DEFAULT_CATEGORY(test); + +int main(int argc,char *argv[]) { + gras_socket_t *sock, *conn; + gras_error_t errcode; + char data_recv[256]; + + gras_init_defaultlog(argc,argv,"trp.thresh=debug"); + + fprintf(stderr,"===[SERVER]=== Create the socket\n"); + TRYFAIL(gras_socket_server(55555,&sock)); + + fprintf(stderr,"===[SERVER]=== Waiting for incomming connexions\n"); + TRYFAIL(gras_trp_select(60,&conn)); + + fprintf(stderr,"===[SERVER]=== Contacted ! Waiting for the data\n"); + TRYFAIL(gras_trp_chunk_recv(conn,data_recv, sizeof(data_recv))); + fprintf(stderr,"===[SERVER]=== Got '%s'. Send it back.\n", data_recv); + TRYFAIL(gras_trp_chunk_send(conn,data_recv, sizeof(data_recv))); + gras_socket_close(&conn); + + fprintf(stderr,"===[SERVER]=== Exiting successfully\n"); + gras_socket_close(&sock); + + return 0; +} diff --git a/testsuite/gras/trp_tcp_usage.in b/testsuite/gras/trp_tcp_usage.in new file mode 100644 index 0000000000..af417ae6b2 --- /dev/null +++ b/testsuite/gras/trp_tcp_usage.in @@ -0,0 +1,6 @@ +#! @BASH@ -e + +./trp_tcp_server $@ & +sleep 1 +./trp_tcp_client $@ + diff --git a/testsuite/xbt/config_usage.c b/testsuite/xbt/config_usage.c index e47e2a16d7..ab6f278074 100644 --- a/testsuite/xbt/config_usage.c +++ b/testsuite/xbt/config_usage.c @@ -48,14 +48,12 @@ int test5() return 1; } -void parse_log_opt(int argc, char **argv,const char *deft); - int main(int argc, char **argv) { gras_error_t errcode; gras_cfg_t *set; int ival; - parse_log_opt(argc,argv,"config.thresh=debug root.thresh=info"); + gras_init_defaultlog(argc,argv,"config.thresh=debug root.thresh=info"); fprintf(stderr,"==== Alloc and free a config set.\n"); set=make_set(); diff --git a/testsuite/xbt/dict_crash.c b/testsuite/xbt/dict_crash.c index cf7c23b488..0139085c44 100644 --- a/testsuite/xbt/dict_crash.c +++ b/testsuite/xbt/dict_crash.c @@ -48,8 +48,6 @@ static gras_error_t countelems(gras_dict_t *head,int*count) { return no_error; } -void parse_log_opt(int argc, char **argv, const char *deft); - int main(int argc,char **argv) { gras_error_t errcode; gras_dict_t *head=NULL; @@ -57,7 +55,7 @@ int main(int argc,char **argv) { char *key; void *data; - parse_log_opt(argc,argv,"dict.thresh=verbose"); + gras_init_defaultlog(argc,argv,"dict.thresh=verbose"); srand((unsigned int)time(NULL)); printf("Dictionnary: CRASH test:\n"); diff --git a/testsuite/xbt/dict_usage.c b/testsuite/xbt/dict_usage.c index ef3755f95e..72542d6f3c 100644 --- a/testsuite/xbt/dict_usage.c +++ b/testsuite/xbt/dict_usage.c @@ -96,14 +96,12 @@ static gras_error_t traverse(gras_dict_t *head) { return no_error; } -void parse_log_opt(int argc, char **argv,const char *deft); - int main(int argc,char **argv) { gras_error_t errcode; gras_dict_t *head=NULL; char *data; - parse_log_opt(argc,argv,"dict.thresh=verbose"); + gras_init_defaultlog(argc,argv,"dict.thresh=verbose"); printf("\nGeneric dictionnary: USAGE test:\n"); @@ -167,8 +165,6 @@ int main(int argc,char **argv) { TRYFAIL(traverse(head)); gras_dict_free(&head); - gras_finalize(); - return 0; TRYCATCH(debuged_remove(head,"12345"),mismatch_error); TRYFAIL(traverse(head)); @@ -186,5 +182,6 @@ int main(int argc,char **argv) { printf(" - Free the dictionnary twice\n"); gras_dict_free(&head); gras_dict_free(&head); + gras_exit(); return 0; } diff --git a/testsuite/xbt/dynar_double.c b/testsuite/xbt/dynar_double.c index d85025e0c4..1acaeb0328 100644 --- a/testsuite/xbt/dynar_double.c +++ b/testsuite/xbt/dynar_double.c @@ -11,15 +11,13 @@ #include #include -void parse_log_opt(int argc, char **argv,const char *deft); - int main(int argc,char *argv[]) { gras_dynar_t *d; gras_error_t errcode; int cpt,cursor; double d1,d2; - parse_log_opt(argc,argv,"dynar.thresh=debug"); + gras_init_defaultlog(argc,argv,"dynar.thresh=debug"); fprintf(stderr,"==== Traverse the empty dynar\n"); TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); @@ -141,6 +139,6 @@ int main(int argc,char *argv[]) { } gras_dynar_free(d); - gras_finalize(); + gras_exit(); return 0; } diff --git a/testsuite/xbt/dynar_int.c b/testsuite/xbt/dynar_int.c index 0dc8641709..70d3529ae4 100644 --- a/testsuite/xbt/dynar_int.c +++ b/testsuite/xbt/dynar_int.c @@ -14,14 +14,12 @@ #define NB_ELEM 5000 GRAS_LOG_NEW_DEFAULT_CATEGORY(test); -void parse_log_opt(int argc, char **argv, const char *def); - int main(int argc,char *argv[]) { gras_dynar_t *d; gras_error_t errcode; int i,cpt,cursor; - parse_log_opt(argc,argv,"dynar.thresh=debug"); + gras_init_defaultlog(argc,argv,"dynar.thresh=debug"); fprintf(stderr,"==== Traverse the empty dynar\n"); TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); diff --git a/testsuite/xbt/dynar_string.c b/testsuite/xbt/dynar_string.c index 7c8bc408c7..7c755d95ee 100644 --- a/testsuite/xbt/dynar_string.c +++ b/testsuite/xbt/dynar_string.c @@ -20,8 +20,6 @@ void free_string(void *d){ free(*(void**)d); } -void parse_log_opt(int argc, char **argv,const char *deft); - int main(int argc,char *argv[]) { gras_dynar_t *d; gras_error_t errcode; @@ -29,7 +27,7 @@ int main(int argc,char *argv[]) { char buf[1024]; char *s1,*s2; - parse_log_opt(argc,argv,"dynar.thresh=debug"); + gras_init_defaultlog(argc,argv,"dynar.thresh=debug"); fprintf(stderr,"==== Traverse the empty dynar\n"); TRYFAIL(gras_dynar_new(&d,sizeof(char *),&free_string)); diff --git a/testsuite/xbt/log_usage.c b/testsuite/xbt/log_usage.c index c86c44b704..e2a277ab36 100644 --- a/testsuite/xbt/log_usage.c +++ b/testsuite/xbt/log_usage.c @@ -40,16 +40,14 @@ GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(Test, Top); GRAS_LOG_NEW_CATEGORY(Top); -void parse_log_opt(int argc, char **argv,const char *deft); - int main(int argc, char **argv) { - parse_log_opt(argc,argv,"root.thresh=debug log.thresh=debug"); + gras_init_defaultlog(argc,argv,"root.thresh=debug log.thresh=debug"); DEBUG1("val=%d", 1); WARNING1("val=%d", 2); CDEBUG2(Top, "val=%d%s", 3, "!"); CRITICAL6("false alarm%s%s%s%s%s%s", "","","","","","!"); - gras_finalize(); + gras_exit(); return 0; } diff --git a/testsuite/xbt/set_usage.c b/testsuite/xbt/set_usage.c index 6db7d21324..e9eecddd86 100644 --- a/testsuite/xbt/set_usage.c +++ b/testsuite/xbt/set_usage.c @@ -161,14 +161,12 @@ static gras_error_t traverse(gras_set_t *set) { return no_error; } -void parse_log_opt(int argc, char **argv,const char *deft); - int main(int argc,char **argv) { gras_error_t errcode; gras_set_t *set=NULL; my_elem_t *elm; - parse_log_opt(argc,argv,"set.thresh=verbose"); + gras_init_defaultlog(argc,argv,"set.thresh=verbose"); printf("\nData set: USAGE test:\n"); -- 2.20.1