Exemple #1
0
func main() {
	parser := argparse.NewParser()
	parser.Register(&args)
	parser.Parse(nil)

	if args.Ssize < 64 || args.Ssize > 32768 {
		args.Ssize = 1024
	}

	if args.Rsize < 1024 || args.Rsize > 65535 {
		args.Rsize = 8192
	}

	if args.Rate != 0 {
		rate := args.Rate * 1024 / 8                   // Convert MBit/s to KByte/s
		args.TB = tbucket.NewTokenBucket(uint64(rate)) // 1 token stands for 1KB/s
		args.TB.Start()
	}

	args.Addr = net.JoinHostPort(args.Ip, args.Port)

	fmt.Printf("%+v\n", args)
	server.Debug = true
	//argparse.Debug = true

	tcp := TCPHandler{}
	tcp.Start()
}
Exemple #2
0
func ExampleTokenBucket() {
	// Get a token from the bucket per second.
	tb := tbucket.NewTokenBucket(1)
	//tb.SetMinTick(time.Millisecond).SetRate(150)
	tb.Start()
	go func(tb *tbucket.TokenBucket) {
		for {
			tb.Get()
			fmt.Println("Get a token") // You can see it prints once per second.
		}
	}(tb)

	for {
	}
}
Exemple #3
0
func main() {
	parser := argparse.NewParser()
	parser.Register(&args)
	parser.Parse(nil)

	if args.Ssize < 64 || args.Ssize > 32768 {
		args.Ssize = 1024
	}

	if args.Rsize < 1024 || args.Rsize > 65535 {
		args.Rsize = 8192
	}

	if args.Rate != 0 {
		rate := args.Rate * 1024 / 8                   // Convert MBit/s to KByte/s
		args.TB = tbucket.NewTokenBucket(uint64(rate)) // 1 token stands for 1KB/s
		args.TB.Start()
	}

	args.Addr = net.JoinHostPort(args.Ip, args.Port)
	info()
	h := TcpClient{}
	h.Start()
}