MCPcopy
hub / github.com/probelabs/goreplay / startTCP

Function startTCP

output_tcp_test.go:38–63  ·  view source on GitHub ↗
(cb func([]byte))

Source from the content-addressed store, hash-verified

36}
37
38func startTCP(cb func([]byte)) net.Listener {
39 listener, err := net.Listen("tcp", "127.0.0.1:0")
40
41 if err != nil {
42 log.Fatal("Can't start:", err)
43 }
44
45 go func() {
46 for {
47 conn, _ := listener.Accept()
48
49 go func(conn net.Conn) {
50 defer conn.Close()
51 reader := bufio.NewReader(conn)
52 scanner := bufio.NewScanner(reader)
53 scanner.Split(payloadScanner)
54
55 for scanner.Scan() {
56 cb(scanner.Bytes())
57 }
58 }(conn)
59 }
60 }()
61
62 return listener
63}
64
65func BenchmarkTCPOutput(b *testing.B) {
66 wg := new(sync.WaitGroup)

Callers 2

TestTCPOutputFunction · 0.85
BenchmarkTCPOutputFunction · 0.85

Calls 2

ListenMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected