// OnClose sets the callback, that is called when the connection is closed.
// It accept function of the type func(*Connection) by default or functions
// taking extended connection types if previously registered.
509803
func (router *Router) OnClose(callback interface{}) error { //func(*Connection)) {
	if cb, ok := callback.(func(*Connection)); ok {
		router.closeFunc = cb
	} else {
		if router.connExtensionConstructor.IsValid() {
			callbackValue := reflect.ValueOf(callback)
			extType := router.connExtensionConstructor.Type().Out(0)
			if reflect.TypeOf(callback).In(0) == extType {
				router.closeFunc = func(conn *Connection) {
					callbackValue.Call([]reflect.Value{reflect.ValueOf(conn.extension)})
				}
			} else {
				return errors.New("OnClose cannot accept a callback of the type " + reflect.TypeOf(callback).String() + ".")
			}
		} else {
			return errors.New("OnClose can only accept functions of the type func(*Connection), if no extension is registered.")
		}
	}
	return nil
}
1040651
func (c *rawConnection) Close(err error) {
	c.sendCloseOnce.Do(func() {
		done := make(chan struct{})
		c.send(&Close{err.Error()}, done)
		select {
		case <-done:
		case <-c.closed:
		}
	})

	c.internalClose(err)
}
126332
func (ai *Amqp) NotifyClose(c chan *amqp.Error) chan *amqp.Error {
	return ai.conn.NotifyClose(c)
}
641883
func (c *Connect) RegisterCloseCallback(callback CloseCallback) error {
	c.UnregisterCloseCallback()
	goCallbackId := registerCallbackId(callback)
	var err C.virError
	res := C.virConnectRegisterCloseCallbackWrapper(c.ptr, C.long(goCallbackId), &err)
	if res != 0 {
		freeCallbackId(goCallbackId)
		return makeError(&err)
	}
	connData := getConnectionData(c)
	connData.closeCallbackId = &goCallbackId
	return nil
}
867709
func (c *VirConnection) RegisterCloseCallback(cb CloseCallback, opaque func()) error {
	c.UnregisterCloseCallback()
	context := &closeContext{
		cb: cb,
		f:  opaque,
	}
	goCallbackId := registerCallbackId(context)
	callbackPtr := unsafe.Pointer(C.closeCallback_cgo)
	res := C.virConnectRegisterCloseCallback_cgo(c.ptr, C.virConnectCloseFunc(callbackPtr), C.long(goCallbackId))
	if res != 0 {
		freeCallbackId(goCallbackId)
		return GetLastError()
	}
	connData := getConnectionData(c)
	connData.closeCallbackId = &goCallbackId
	return nil
}
1176491
func TryClose(r interface{}) error {
	if r, ok := r.(Closer); ok {
		return r.Close()
	}
	if r, ok := r.(SimpleCloser); ok {
		r.Close()
		return nil
	}
	return ErrNotCloseable
}
618367
func (r *FileRef) OnAfterClose(cb func()) {
	r.m.Lock()
	r.afterCloseCallbacks = append(r.afterCloseCallbacks, cb)
	r.m.Unlock()
}
107633
func (conn *Conn) Close() {
	conn.conn.Close()
	conn.closed = true
	if conn.dataConn != nil {
		conn.dataConn.Close()
		conn.dataConn = nil
	}
}
765204
func (c *Connection) isClosed() error {
	if c.conn == nil {
		return client.ErrConnectionClosed
	}
	return nil
}
282282
func (p *ConnectionPool) Close() chan bool {
	done := make(chan bool)
	go func() {
		for len(p.pool) > 0 {
			c := <-p.pool
			c.returnOnClose = false
			c.Close()
		}
		done <- true
	}()
	return done
}
242394
func (c *Client) Close() {
	_ = c.conn.Close()
	c.tomb.Kill(ErrClientClosed)
}
913961
func OnSessionClose(f func(s *Session)) {
	sf1 := reflect.ValueOf(f)
	for _, fun := range SessionCloseCallbacks {
		sf2 := reflect.ValueOf(fun)
		if sf1.Pointer() == sf2.Pointer() {
			return
		}
	}
	SessionCloseCallbacks = append(SessionCloseCallbacks, f)
}
1367583
func (e *EventListener) IsClosed() bool {
	e.closedMtx.RLock()
	defer e.closedMtx.RUnlock()
	return e.closed
}
590044
func (l *Listener) Close() error {
	l.init()

	l.Lock()
	defer l.Unlock()

	// short-circuit with an error if we are already closed
	select {
	case <-l.closing:
		return &net.OpError{
			Op:   "close",
			Net:  network,
			Addr: l.Addr(),
			Err:  neterr{timeout: false, err: listenerClosed},
		}
	default:
		l.connc = nil
		close(l.closing)
	}

	return nil
}
1000644
func (c *Conn) close(err error) error {
	c.cancel()

	c.mu.Lock()
	if c.closed {
		c.mu.Unlock()
		return ErrConnClosing
	}
	c.closed = true
	if err == nil {
		err = ErrConnClosing
	}
	for id, call := range c.pending {
		delete(c.pending, id)
		call.done(err)
	}
	c.mu.Unlock()

	// Stop sending on all streams.
	c.streamMu.Lock()
	c.streams = nil
	c.streamMu.Unlock()

	// Conn can be nil if DialContext did not complete.
	if c.conn != nil {
		err = c.conn.Close()
	}

	return err
}
862983
func (c *Connection) Close() {
	c.Lock()
	defer c.Unlock()
	if c.conn != nil {
		c.conn.Close()
		c.conn = nil
		if c.onClose != nil {
			c.onClose(c.id)
			c.onClose = nil
		}
	}
}
1350040
func (f deleteOnCloseFile) Close() error {
	f.File.Close()
	os.Remove(f.Name())
	return nil
}