diff --git a/source/bforce/io_tcpip.c b/source/bforce/io_tcpip.c index 06758ae..7d600fc 100644 --- a/source/bforce/io_tcpip.c +++ b/source/bforce/io_tcpip.c @@ -55,14 +55,25 @@ static int tcpip_connect2(struct addrinfo *ai) { DEB((D_INFO, "tcpip_connect2: socket error")); } - else break; - + else + { + DEB((D_INFO, "tcpip_connect2: socket opened - breaking")); + if( connect(fd, rai->ai_addr, rai->ai_addrlen) == -1 ) + { + DEB((D_INFO, "tcpip_connect2: can't connect %s", hbuf)); + logerr("can't connect to %s", hbuf); + close(fd); + } else + break; + } + DEB((D_INFO, "tcpip_connect2: socket not opened - returning")); hbuf[0]='\0'; sbuf[0]='\0'; } DEB((D_INFO, "tcpip_connect2: socket success: %d", fd)); if (fd < 0 ) { + DEB((D_INFO, "tcpip_connect2: can't create socket")); logerr("can't create socket"); return(1); } @@ -73,6 +84,7 @@ static int tcpip_connect2(struct addrinfo *ai) (void)close(0); if( dup(fd) != 0 ) { + DEB((D_INFO, "tcpip_connect2: can't dup socket to stdin")); logerr("cannot dup socket to stdin"); return(1); } @@ -92,7 +104,7 @@ static int tcpip_connect2(struct addrinfo *ai) logerr("cannot dup stdin to stderr"); return(1); } - + DEB((D_INFO, "tcpip_connect2: stdin|out|err are connected")); if( fd > 2 ) (void)close(fd); /* switch off stdio buffering */ @@ -103,22 +115,24 @@ static int tcpip_connect2(struct addrinfo *ai) clearerr(stdin); clearerr(stdout); clearerr(stderr); - - if( connect(0, rai->ai_addr, rai->ai_addrlen) == -1 ) - { - logerr("can't connect to %s", hbuf); - close(0); - close(1); - close(2); - return 1; - } + DEB((D_INFO, "tcpip_connect2: start connecting")); + //if( connect(0, rai->ai_addr, rai->ai_addrlen) == -1 ) + //{ + // DEB((D_INFO, "tcpip_connect2: can't connect %s", hbuf)); + // logerr("can't connect to %s", hbuf); + // + // close(0); + // close(1); + // close(2); + // return 1; + //} if( tcpip_init() ) { tcpip_shutdown(); return 1; } - + DEB((D_INFO, "tcpip_connect2: TCP/IP connect success to %s on service %s", hbuf, sbuf)); (void)log("TCP/IP connect success to %s on service %s", hbuf, sbuf); return(0); diff --git a/tests/mktests.sh b/tests/mktests.sh index c2a2095..533c3a2 100755 --- a/tests/mktests.sh +++ b/tests/mktests.sh @@ -56,17 +56,17 @@ function testcomm() { # Variant 3 works with sockets and pipes - not pty case ${1} in "PSTN") - socat -ly -Wlock EXEC:"${CURDIR}/runbfB.sh ${BFBIN} ${BFCFGB}" EXEC:"${CURDIR}/runbfA.sh ${BFBIN} ${BFCFGA}" + socat -T5 -ly -Wlock EXEC:"${CURDIR}/runbfB.sh ${BFBIN} ${BFCFGB}" EXEC:"${CURDIR}/runbfA.sh ${BFBIN} ${BFCFGA}" sleep 2 ;; "IFC") ${CURDIR}/runbfC.sh ${BFBIN} ${BFCFGA} & - socat -ly -Wlock TCP4-LISTEN:59999 EXEC:"${CURDIR}/runbfD.sh ${BFBIN} ${BFCFGB}" + socat -ly -Wlock TCP4-LISTEN:59999,accept-timeout=3 EXEC:"${CURDIR}/runbfD.sh ${BFBIN} ${BFCFGB}" sleep 2 ;; "BKP") ${CURDIR}/runbfE.sh ${BFBIN} ${BFCFGA} & - socat -ly -Wlock TCP4-LISTEN:59999 EXEC:"${CURDIR}/runbfF.sh ${BFBIN} ${BFCFGB}" + socat -ly -Wlock TCP4-LISTEN:59999,accept-timeout=3 EXEC:"${CURDIR}/runbfF.sh ${BFBIN} ${BFCFGB}" sleep 2 ;; esac