From be9fe37bcbfd766c9fcc3f471d34b0db1cf10931 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 29 Nov 2003 14:45:39 +0000 Subject: [PATCH] Added tests for Posix threads --- config.h.in | 3 + configure | 212 ++++++++++++++++++++++++++++++++++++++++++++++++ configure.in | 8 ++ lib/libs.h | 1 + mbcico/binkp.c | 41 ++++++++++ mbcico/mbcico.h | 10 ++- 6 files changed, 274 insertions(+), 1 deletion(-) diff --git a/config.h.in b/config.h.in index 6df3eadf..167c0c89 100644 --- a/config.h.in +++ b/config.h.in @@ -308,3 +308,6 @@ /* Define if you have the header file. */ #undef HAVE_ZLIB_H +/* Define if you have the header file. */ +#undef HAVE_PTHREAD_H + diff --git a/configure b/configure index 5988c180..dfb97327 100755 --- a/configure +++ b/configure @@ -4490,6 +4490,214 @@ done fi +echo "$as_me:$LINENO: checking for pthread_create in -lpthread" >&5 +echo $ECHO_N "checking for pthread_create in -lpthread... $ECHO_C" >&6 +if test "${ac_cv_lib_pthread_pthread_create+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthread $LIBS" +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char pthread_create (); +int +main () +{ +pthread_create (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_pthread_pthread_create=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_pthread_pthread_create=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_pthread_pthread_create" >&5 +echo "${ECHO_T}$ac_cv_lib_pthread_pthread_create" >&6 +if test $ac_cv_lib_pthread_pthread_create = yes; then + result=yes +else + result=no +fi + +if test "$result" = "yes"; then + LIBS="$LIBS -lpthread" + +for ac_header in pthread.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc in + yes:no ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------ ## +## Report this to bug-autoconf@gnu.org. ## +## ------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; + no:yes ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------ ## +## Report this to bug-autoconf@gnu.org. ## +## ------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=$ac_header_preproc" +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + PTHREADS=Yes +else + PTHREADS=No +fi + +done + +fi + echo "$as_me:$LINENO: checking for ANSI C header files" >&5 echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 if test "${ac_cv_header_stdc+set}" = set; then @@ -10121,6 +10329,8 @@ echo "$as_me:$LINENO: result: Version : ..................... ${VERSION} Hydra zlib compression : ...... ${ZLIBSUP} + Posix threads : ............... ${PTHREADS} + " >&5 echo "${ECHO_T} -=-=-=-=-=-=-=-=-=-= Configuration Complete =-=-=-=-=-=-=-=-=-=- @@ -10129,6 +10339,8 @@ echo "${ECHO_T} Version : ..................... ${VERSION} Hydra zlib compression : ...... ${ZLIBSUP} + Posix threads : ............... ${PTHREADS} + " >&6 if test x$ac_cv_c_compiler_gnu = xyes ; then diff --git a/configure.in b/configure.in index 071a6703..208ecf75 100644 --- a/configure.in +++ b/configure.in @@ -136,6 +136,12 @@ if test "$result" = "yes"; then AC_CHECK_HEADERS(zlib.h,ZLIBSUP=Yes,ZLIBSUP=No) fi +AC_CHECK_LIB(pthread,pthread_create,result=yes,result=no) +if test "$result" = "yes"; then + LIBS="$LIBS -lpthread" + AC_CHECK_HEADERS(pthread.h,PTHREADS=Yes,PTHREADS=No) +fi + dnl Checks for header files. AC_HEADER_STDC AC_HEADER_DIRENT @@ -293,6 +299,8 @@ AC_MSG_RESULT([ Version : ..................... ${VERSION} Hydra zlib compression : ...... ${ZLIBSUP} + Posix threads : ............... ${PTHREADS} + ]) if test x$ac_cv_c_compiler_gnu = xyes ; then diff --git a/lib/libs.h b/lib/libs.h index 9bfad028..f7d2d548 100644 --- a/lib/libs.h +++ b/lib/libs.h @@ -83,6 +83,7 @@ #include #include #include +#include #ifdef HAVE_ICONV_H #include #endif diff --git a/mbcico/binkp.c b/mbcico/binkp.c index ab50da43..3b882f32 100644 --- a/mbcico/binkp.c +++ b/mbcico/binkp.c @@ -54,6 +54,7 @@ #include "config.h" #include "md5b.h" #include "inbound.h" +#include "mbcico.h" /* @@ -77,6 +78,7 @@ static char *bstate[] = { */ void binkp_init(void); void binkp_deinit(void); +void *binkp_readbuf(void); char *unix2binkp(char *); char *binkp2unix(char *); int binkp_expired(void); @@ -130,6 +132,10 @@ int batchnr = 0, crc_errors = 0; unsigned char *MD_challenge = NULL; /* Received CRAM challenge data */ int ext_rand = 0; + +static int read_state; + + struct binkprec { int role; /* 1=orig, 0=answer */ int RxState; /* Receiver state */ @@ -160,6 +166,8 @@ struct binkprec bp; /* Global structure */ void binkp_init(void) { + int frk; + bp.rname = calloc(512, sizeof(char)); bp.lname = calloc(512, sizeof(char)); bp.gname = calloc(512, sizeof(char)); @@ -171,9 +179,17 @@ void binkp_init(void) bp.Major = 1; bp.Minor = 0; bp.DidSendGET = FALSE; + + read_state = 0; + + frk = pthread_create(&threads[0], NULL, binkp_readbuf, NULL); + Syslog('-', "pthread_create returnd %d", frk); + + Syslog('+', "Binkp: init complete"); } + void binkp_deinit(void) { if (bp.rname) @@ -185,6 +201,29 @@ void binkp_deinit(void) } + +/* + * Read buffer, executed in a second process + */ +void *binkp_readbuf(void) +{ + /* + * Just for testing + */ + Syslog('!', "Entering binkp_readbuf"); + + while (TRUE) { + read_state++; + if (read_state > 20) + read_state = 0; + usleep(100000); + Syslog('!', "readstate now %d", read_state); + } + Syslog('!', "SHOULD NOT BE HERE"); +} + + + int binkp(int role) { int rc = MBERR_OK; @@ -1240,6 +1279,8 @@ int binkp_batch(file_list *to_send) while ((bp.RxState != RxDone) || (bp.TxState != TxDone)) { Nopper(); + Syslog('-', "read state %d", read_state); + if (binkp_expired()) { Syslog('!', "Binkp: Transfer timeout"); Syslog('b', "Binkp: TxState=%s, RxState=%s, rxlen=%d", txstate[bp.TxState], rxstate[bp.RxState], rxlen); diff --git a/mbcico/mbcico.h b/mbcico/mbcico.h index caaaaf8a..68d9b68c 100644 --- a/mbcico/mbcico.h +++ b/mbcico/mbcico.h @@ -1,9 +1,17 @@ #ifndef _MBCICO_H #define _MBCICO_H +/* $Id$ */ + +/* + * Global threads for mbcico + */ +#define NUM_THREADS 4 +pthread_t threads[NUM_THREADS]; + + void usage(void); void free_mem(void); void die(int); #endif -