本文整理匯總了Golang中circuit/use/circuit.Conn.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Close方法的具體用法?Golang Conn.Close怎麽用?Golang Conn.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類circuit/use/circuit.Conn
的用法示例。
在下文中一共展示了Conn.Close方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: serveDial
func (r *Runtime) serveDial(req *dialMsg, conn circuit.Conn) {
// Go guarantees the defer runs even if panic occurs
defer conn.Close()
expDial, _ := r.exportValues([]interface{}{PermRef(r.srv.Get(req.Service))}, conn.Addr())
conn.Write(&returnMsg{Out: expDial})
// Waiting for export acks not necessary since expDial is always a permptr.
}
示例2: serveCall
func (r *Runtime) serveCall(req *callMsg, conn circuit.Conn) {
// Go guarantees the defer runs even if panic occurs
defer conn.Close()
h := r.exp.Lookup(req.ReceiverID)
if h == nil {
if err := conn.Write(&returnMsg{Err: NewError("reply: no exp handle")}); err != nil {
// We need to distinguish between I/O errors and encoding errors.
// An encoding error implies bad code (e.g. forgot to register a
// type) and therefore is best handled by a panic. An I/O error is
// an expected runtime condition, and thus we ignore it (as we are
// on the server side).
//
// XXX: It should be Conn's responsibility to panic on encoding
// errors. For extra safety and convenience, we do something hacky
// here in trying to guess if we got an encoding error, in case
// Conn didn't throw a panic.
if strings.HasPrefix(err.Error(), "gob") {
panic(err)
}
}
return
}
fn := h.Type.Func[req.FuncID]
if fn == nil {
conn.Write(&returnMsg{Err: NewError("no func")})
return
}
in, err := r.importValues(req.In, fn.InTypes, conn.Addr(), true, nil)
if err != nil {
conn.Write(&returnMsg{Err: err})
return
}
reply, err := call(h.Value, h.Type, req.FuncID, in)
if err != nil {
conn.Write(&returnMsg{Err: err})
return
}
expReply, ptrPtr := r.exportValues(reply, conn.Addr())
if err = conn.Write(&returnMsg{Out: expReply}); err != nil {
// Gob encoding errors will often be the cause of this
log.Printf("write error (%s)", err)
}
r.readGotPtrPtr(ptrPtr, conn)
}
示例3: serveGetPtr
func (r *Runtime) serveGetPtr(req *getPtrMsg, conn circuit.Conn) {
defer conn.Close()
h := r.exp.Lookup(req.ID)
if h == nil {
if err := conn.Write(&returnMsg{Err: NewError("getPtr: no exp handle")}); err != nil {
// See comment in serveCall.
if strings.HasPrefix(err.Error(), "gob") {
panic(err)
}
}
return
}
expReply, _ := r.exportValues([]interface{}{r.Ref(h.Value.Interface())}, conn.Addr())
conn.Write(&returnMsg{Out: expReply})
}
示例4: serveGo
func (r *Runtime) serveGo(req *goMsg, conn circuit.Conn) {
// Go guarantees the defer runs even if panic occurs
defer conn.Close()
t := types.FuncTabl.TypeWithID(req.TypeID)
if t == nil {
conn.Write(&returnMsg{Err: NewError("reply: no func type")})
return
}
// No need to acknowledge acquisition of re-exported ptrs since,
// the caller is waiting for a return message anyway
mainID := t.MainID()
in, err := r.importValues(req.In, t.Func[mainID].InTypes, conn.Addr(), true, nil)
if err != nil {
conn.Write(&returnMsg{Err: err})
return
}
// Allow registration of a main goroutine. Kill runtime if none registered.
r.openDaemonizer()
defer func() {
if !r.closeDaemonizer() {
// Potentially unnecessary hack to ensure that last message sent to
// caller is received before we die
time.Sleep(time.Second)
os.Exit(0)
}
}()
reply, err := call(t.Zero(), t, mainID, in)
if err != nil {
conn.Write(&returnMsg{Err: err})
return
}
expReply, ptrPtr := r.exportValues(reply, conn.Addr())
err = conn.Write(&returnMsg{Out: expReply})
r.readGotPtrPtr(ptrPtr, conn)
conn.Close()
}
示例5: serveDropPtr
func (r *Runtime) serveDropPtr(q *dropPtrMsg, conn circuit.Conn) {
// Go guarantees the defer runs even if panic occurs
defer conn.Close()
r.exp.Remove(q.ID, conn.Addr())
}