func()

in pkg/echo/echo.go [32:89]


func (e *EchoHandler) handle(str net.Conn) {
	d := make([]byte, 2048)

	//si := GetStreamInfo(str)
	//si.RemoteID=   RemoteID(str)
	//b1, _ := json.Marshal(si)

	if e.Debug {
		log.Println("Echo ", e.ServerFirst, str.RemoteAddr())
	}
	b := &bytes.Buffer{}
	b.WriteString("Hello world\n")
	//b.Write(b1)
	//b.Write([]byte{'\n'})

	time.Sleep(e.WaitFirst)

	if e.ServerFirst {
		n, err := str.Write(b.Bytes())
		if e.Debug {
			log.Println("ServerFirst write()", n, err)
		}
	}
	//ac.SetDeadline(time.Now().StartListener(5 * time.Second))

	writeClosed := false
	for {
		n, err := str.Read(d)
		e.Received += n
		if e.Debug {
			log.Println("Echo read()", n, err)
		}
		if err != nil {
			if e.Debug {
				log.Println("ECHO DONE")
			}
			str.Close()
			return
		}
		if d[0] == 0 {
			if wc, ok := str.(interface {
				CloseWrite() error
			}); ok {
				wc.CloseWrite()
				writeClosed = true
				// Continue to read ! The test can check the read byte counts
			}
		}

		if !writeClosed {
			// TODO: add delay (based on req)
			str.Write(d[0:n])
			if e.Debug {
				log.Println("ECHO write")
			}
		}
	}
}