Esempio n. 1
0
func listener(ctx context.Context, frameSize int, numStreams int, addr string) error {
	ln, err := net.Listen("tcp", addr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "net.Listen(%q): %s\n", addr, err.Error())
		return err
	}
	go func() {
		<-ctx.Done()
		ln.Close()
	}()

	rr := fnet.NewRoundRobin(frameSize)
	go func() {
		<-ctx.Done()
		rr.Close()
	}()

	for i := 0; i < numStreams; i++ {
		c, err := ln.Accept()
		if err != nil {
			fmt.Fprintf(os.Stderr, "ln.Accept(): %s\n", err.Error())
			return err
		}
		fs := fnet.FromOrderedStream(c, frameSize)
		rr.AddConn(fs)
	}
	fc := fnet.FrameConn(rr)

	if err = clockstation.Run(ctx, fc, time.Tick(50*time.Millisecond)); err != nil {
		return fmt.Errorf("clockstation.Run: %s\n", err.Error())
	}
	return nil
}
Esempio n. 2
0
func dialer(ctx context.Context, frameSize int, numStreams int, addr string) error {
	rr := fnet.NewRoundRobin(frameSize)
	go func() {
		<-ctx.Done()
		rr.Close()
	}()

	for i := 0; i < numStreams; i++ {

		c, err := net.Dial("tcp", addr)
		if err != nil {
			fmt.Fprintf(os.Stderr, "net.Dial(%q): %s\n", addr, err.Error())
			return err
		}
		fs := fnet.FromOrderedStream(c, frameSize)
		rr.AddConn(fs)
	}
	fc := fnet.FrameConn(rr)

	if err := clockprinter.Run(ctx, fc); err != nil {
		fmt.Errorf("clockprinter.Run: %s\n", err.Error())
	}
	return nil
}