func (c *Conn) SetReadDeadline(t time.Time) error {
	c.rdeadmu.Lock()
	c.rdead = t
	c.rdeadmu.Unlock()
	return nil
}
SetReadDeadline implements the net.Conn interface.
package ionet
import (
	"fmt"
	"io"
	"io/ioutil"
	"net"
	"sync"
	"time"
)
type Conn struct {
	R   io.Reader
	W   io.Writer
	rmu sync.Mutex  
	wmu sync.Mutex  
	closing   chan struct{}  
	closingmu sync.Mutex     
	rdead   time.Time     
	rdeadmu sync.RWMutex  
	wdead   time.Time     
	wdeadmu sync.RWMutex  
}
type nerr struct {
	n   int
	err error
}
func (c *Conn) Read(b []byte) (int, error) {
	if c.R == nil {
		return 0, c.readErr(false, io.EOF)
	}
	c.initClosing()
	select {
	case <-c.closing:
		return 0, c.readErr(false, connClosed)
	default:
	}
	c.rdeadmu.RLock()
	defer c.rdeadmu.RUnlock()
	if !c.rdead.IsZero() && c.rdead.Before(time.Now()) {
		return 0, c.readErr(true, timedOut)
	}
	readc := make(chan nerr, 1)
	go func() {
		c.rmu.Lock()
		n, err := c.R.Read(b)
		c.rmu.Unlock()
		readc <- nerr{n, err}
	}()
	var timeout <-chan time.Time
	timer := deadlineTimer(c.rdead)  
	if timer != nil {
		timeout = timer.C
		defer timer.Stop()
	}
	select {
	case <-c.closing:
		return 0, c.readErr(false, connClosed)
	case <-timeout:
		return 0, c.readErr(true, timedOut)
	case nerr := <-readc:
		if nerr.err != nil {
			return nerr.n, c.readErr(false, nerr.err)
		}
		return nerr.n, nil
	}
}
func (c *Conn) Write(b []byte) (int, error) {
	if c.W == nil {
		return ioutil.Discard.Write(b)
	}
	c.initClosing()
	select {
	case <-c.closing:
		return 0, c.writeErr(false, connClosed)
	default:
	}
	c.wdeadmu.RLock()
	defer c.wdeadmu.RUnlock()
	if !c.wdead.IsZero() && c.wdead.Before(time.Now()) {
		return 0, c.writeErr(true, timedOut)
	}
	writec := make(chan nerr, 1)
	go func() {
		c.wmu.Lock()
		n, err := c.W.Write(b)
		c.wmu.Unlock()
		writec <- nerr{n, err}
	}()
	var timeout <-chan time.Time
	c.wdeadmu.RLock()
	timer := deadlineTimer(c.wdead)  
	if timer != nil {
		timeout = timer.C
		defer timer.Stop()
	}
	select {
	case <-c.closing:
		return 0, c.writeErr(false, connClosed)
	case <-timeout:
		return 0, c.writeErr(true, timedOut)
	case nerr := <-writec:
		if nerr.err != nil {
			return nerr.n, c.writeErr(false, nerr.err)  
		}
		return nerr.n, nil
	}
}
func (c *Conn) Close() error {
	c.initClosing()
	c.closingmu.Lock()
	defer c.closingmu.Unlock()
	select {
	case <-c.closing:
		return &net.OpError{
			Op:   "close",
			Net:  network,
			Addr: c.LocalAddr(),
			Err:  neterr{timeout: false, err: connClosed},
		}
	default:
		close(c.closing)
	}
	return nil
}
func (c *Conn) Wait() {
	c.initClosing()
	<-c.closing
}
func (c *Conn) SetDeadline(t time.Time) error {
	c.SetReadDeadline(t)
	c.SetWriteDeadline(t)
	return nil
}