Exemple #1
0
func (y *Conn) kill(newerr os.Error) (err os.Error) {
	//dbg.PrintStackTrace()
	if newerr == nil {
		panic("d,conn: nil kill err")
	}
	y.lk.Lock()
	if y.err == nil {
		y.err = newerr
		err = newerr
	} else {
		y.lk.Unlock()
		return os.EBADF
	}
	y.id = nil
	y.regime = regimeClosed
	tube := y.tube
	y.tube = nil
	close(y.dialch)
	y.dialch = nil
	y.lk.Unlock()

	if tube != nil {
		tube.Close()
	}
	if err == nil {
		panic("d,conn: err == nil")
	}
	return err
}
Exemple #2
0
// Atomically closes the connection if it is currently unused.
func (y *Conn) CloseIfReady() (err os.Error) {
	y.lk.Lock()
	if y.regime != regimeReady {
		y.lk.Unlock()
		return os.EAGAIN
	}
	if y.err != nil {
		y.lk.Unlock()
		return os.EBADF
	}
	y.err = os.EOF
	y.id = nil
	y.regime = regimeClosed
	tube := y.tube
	y.tube = nil
	close(y.dialch)
	y.dialch = nil
	y.lk.Unlock()

	if tube != nil {
		tube.Close()
	}
	return nil
}