Revision 237 (by dpavlin, 2004/03/08 17:43:12) initial import of openisis 0.9.0 vendor drop
#!/bin/bash
#/*
#	openisis - an open implementation of the CDS/ISIS database
#	Version 0.8.x (patchlevel see file Version)
#	Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
#
#	This library is free software; you can redistribute it and/or
#	modify it under the terms of the GNU Lesser General Public
#	License as published by the Free Software Foundation; either
#	version 2.1 of the License, or (at your option) any later version.
#
#	This library is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#	Lesser General Public License for more details.
#
#	You should have received a copy of the GNU Lesser General Public
#	License along with this library; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#	see README for more information
#EOH */

# $Id: oister,v 1.5 2003/04/08 00:20:53 kripke Exp $
#
# OpenIsis server tester -- test oyster
#
#	usage
#	./oister [port [host]] # talk to server
#	time ./oister -trash [requests [clients [port [host]]]]



trasher () {
	id=$1
	exec 3<>/dev/tcp/$host/$port
	local i # running in subshell anyway ...
	declare -i i
	i=$requests
	ses=ses$[id / 4]
	while [ 0 != $i ]; do
		if [ 0 -eq $[i % 7] ]; then # add to session
			echo "-2	$ses
$i	$id $i foo
$i	$id $i bar
" >&3
		else # fetch session info only
			echo "-2	$ses
" >&3
		fi
		while read line; do
			# echo $line
			[ -z "$line" ] && break;
		done <&3
		i=i-1
	done
	echo "$id: `date`"
}


if [ x-trash == "x$1" ]; then
	requests=${2:-500}
	clients=${3:-8}
	port=${4:-8080}
	host=${5:-localhost}
	declare -i j
	echo "starting $clients trashers for $requests requests at `date`"
	j=$clients; while [ 0 != $j ]; do time trasher $j & j=j-1; done
	echo "started $clients trashers on $host:$port at `date`"
	j=$clients; while [ 0 != $j ]; do wait; j=j-1; done
	echo "collected $clients trashers at `date`"
	exit
fi

# default: run manually
#

exec 3<>/dev/tcp/${2:-localhost}/${1:-8080}

cat <&3 &
cp=$!

cat >&3
kill $cp # copy kill ;/