package door import ( "net" "testing" "time" ) // helper routines - to help with testing. func setupSockets() (server net.Conn, client net.Conn) { // the better way to set up connections. return net.Pipe() } // setupSockets: return server and client (that's connected to server) func Old_setupSockets() (server net.Conn, client net.Conn) { // establish network socket connection to set Comm_handle var err error var sock net.Listener sock, err = net.Listen("tcp", "127.0.0.1:0") if err != nil { panic(err) } // I only need address for making the connection. // Get address of listening socket address := sock.Addr().String() client, err = net.Dial("tcp", address) if err != nil { panic(err) } server, err = sock.Accept() if err != nil { panic(err) } sock.Close() return server, client } func clear_socket(socket net.Conn, t *testing.T) string { // Clear out the data that's pending in the socket. buffer := make([]byte, 1204) var r int var err error err = socket.SetReadDeadline(time.Now().Add(time.Millisecond * 20)) if err != nil { t.Error("socket.SetReadDeadLine:", err) } r, err = socket.Read(buffer) if err != nil { t.Errorf("socket.Read: %#v", err) } // t.Errorf("Buffer : %#v\n", buffer[:r]) err = socket.SetReadDeadline(time.Time{}) if err != nil { t.Error("socket.SetReadDeadLine:", err) } return string(buffer[:r]) }