| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | package doorimport (	"fmt"	"net"	"testing"	"time")// helper routines - to help with testing.// Using pipes causes failures.func Possible_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 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 {		// DeadlineExceedError		t.Logf("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])}// Unicode detection response with given screen width/height.func UnicodeWidthHeight(width, height int) string {	return CursorReply(CursorPos{1, 1}) +		CursorReply(CursorPos{3, 1}) +		CursorReply(CursorPos{width, height})}// CP437 response with screen width/height. (80x25)func CP437WidthHeight(width, height int) string {	return CursorReply(CursorPos{3, 1}) +		CursorReply(CursorPos{4, 1}) +		CursorReply(CursorPos{width, height})}// Cursor Position Replyfunc CursorReply(c CursorPos) string {	return fmt.Sprintf("\x1b[%d;%dR", c.Y, c.X)}// Mouse Button X,Y Replyfunc MouseReply(m Mouse) string {	return fmt.Sprintf("\x1b[M%c%c%c", m.Button+' '-1, m.X+'!'-1, m.Y+'!'-1)}
 |