func (s *Splicer) CopyBytes(in, out *net.TCPConn) { // Close the tcp connection given to us. defer func() { // TODO: Double close problems? out.Close() in.Close() }() // Invoking File() on the connection will duplicate the socket fd, setting // the original (socket fd) to block. inFile, err := in.File() if err != nil { log.Fatal(err) } inFD := int(inFile.Fd()) defer syscall.Close(inFD) outFile, err := out.File() if err != nil { log.Fatal(err) } outFD := int(outFile.Fd()) defer syscall.Close(outFD) var wg sync.WaitGroup wg.Add(2) go s.splice(fmt.Sprintf("from backend: %v -> %v", in.RemoteAddr(), out.RemoteAddr()), inFD, outFD, &wg) go s.splice(fmt.Sprintf("to backend: %v -> %v", out.RemoteAddr(), in.RemoteAddr()), outFD, inFD, &wg) wg.Wait() }
func (s *SimpleCopier) CopyBytes(in, out *net.TCPConn) { var wg sync.WaitGroup wg.Add(2) go s.copy(fmt.Sprintf("from backend: %v -> %v", in.RemoteAddr(), out.RemoteAddr()), in, out, &wg) go s.copy(fmt.Sprintf("to backend: %v -> %v", out.RemoteAddr(), in.RemoteAddr()), out, in, &wg) wg.Wait() }