func (cc *CancellableConnection) SetDeadline(t time.Time) error {
	return cc.conn.SetDeadline(t)
}
SetDeadline sets the read and write deadlines associated
with the connection.
package util
import (
	"context"
	"net"
	"time"
)
type CancellableConnection struct {
	ctx  context.Context
	conn net.Conn
}
type ioret struct {
	n   int
	err error
}
func MakeCancellable(ctx context.Context, conn net.Conn) *CancellableConnection {
	return &CancellableConnection{ctx, conn}
}
func (cc *CancellableConnection) Read(p []byte) (int, error) {
	c := make(chan ioret, 1)
	buf := make([]byte, len(p))
	performRead := func() {
		n, err := cc.conn.Read(buf)
		c <- ioret{n, err}
		close(c)
	}
	go performRead()
	select {
	case ret := <-c:
		copy(p, buf)
		return ret.n, ret.err
	case <-cc.ctx.Done():
		return 0, cc.ctx.Err()
	}
}
func (cc *CancellableConnection) Write(p []byte) (int, error) {
	c := make(chan ioret, 1)
	buf := make([]byte, len(p))
	copy(buf, p)
	go func() {
		n, err := cc.conn.Write(buf)
		c <- ioret{n, err}
		close(c)
	}()
	select {
	case r := <-c:
		return r.n, r.err
	case <-cc.ctx.Done():
		return 0, cc.ctx.Err()
	}
}
func (cc *CancellableConnection) Close() error {
	return cc.conn.Close()
}
func (cc *CancellableConnection) LocalAddr() net.Addr {
	return cc.conn.LocalAddr()
}
func (cc *CancellableConnection) RemoteAddr() net.Addr {
	return cc.conn.RemoteAddr()
}