From 558d9133a6c266f298d270aa2c681c41f4be6edf Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Wed, 26 Sep 2018 10:03:13 -0700 Subject: [PATCH] try fix --- src/comm/comm.go | 9 ++++----- src/tcp/tcp.go | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/comm/comm.go b/src/comm/comm.go index 33ded473..ad181b10 100644 --- a/src/comm/comm.go +++ b/src/comm/comm.go @@ -12,23 +12,22 @@ import ( // Comm is some basic TCP communication type Comm struct { - connection net.Conn + connection *net.TCPConn writer *bufio.Writer } // New returns a new comm -func New(n net.Conn) *Comm { +func New(n *net.TCPConn) *Comm { c := new(Comm) c.connection = n c.connection.SetReadDeadline(time.Now().Add(3 * time.Hour)) c.connection.SetDeadline(time.Now().Add(3 * time.Hour)) c.connection.SetWriteDeadline(time.Now().Add(3 * time.Hour)) - c.writer = bufio.NewWriter(n) return c } -// Connection returns the net.Conn connection -func (c *Comm) Connection() net.Conn { +// Connection returns the net.TCPConn connection +func (c *Comm) Connection() *net.TCPConn { return c.connection } diff --git a/src/tcp/tcp.go b/src/tcp/tcp.go index 3e63c054..98ebf6db 100644 --- a/src/tcp/tcp.go +++ b/src/tcp/tcp.go @@ -52,12 +52,12 @@ func run(port string) (err error) { defer server.Close() // spawn a new goroutine whenever a client connects for { - connection, err := server.Accept() + connection, err := server.AcceptTCP() if err != nil { return errors.Wrap(err, "problem accepting connection") } log.Debugf("client %s connected", connection.RemoteAddr().String()) - go func(port string, connection net.Conn) { + go func(port string, connection *net.TCPConn) { errCommunication := clientCommuncation(port, comm.New(connection)) if errCommunication != nil { log.Warnf("relay-%s: %s", connection.RemoteAddr().String(), errCommunication.Error()) @@ -126,7 +126,7 @@ func clientCommuncation(port string, c *comm.Comm) (err error) { // chanFromConn creates a channel from a Conn object, and sends everything it // Read()s from the socket to the channel. -func chanFromConn(conn net.Conn) chan []byte { +func chanFromConn(conn *net.TCPConn) chan []byte { c := make(chan []byte) // reader := bufio.NewReader(conn) @@ -153,7 +153,7 @@ func chanFromConn(conn net.Conn) chan []byte { // pipe creates a full-duplex pipe between the two sockets and // transfers data from one to the other. -func pipe(conn1 net.Conn, conn2 net.Conn) { +func pipe(conn1 *net.TCPConn, conn2 *net.TCPConn) { chan1 := chanFromConn(conn1) // chan2 := chanFromConn(conn2) // writer1 := bufio.NewWriter(conn1)