當前位置: 首頁>>代碼示例>>Golang>>正文


Golang circuit.Conn類代碼示例

本文整理匯總了Golang中circuit/use/circuit.Conn的典型用法代碼示例。如果您正苦於以下問題:Golang Conn類的具體用法?Golang Conn怎麽用?Golang Conn使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Conn類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: writeReturn

func writeReturn(conn circuit.Conn, msg interface{}) ([]interface{}, error) {
	if err := conn.Write(msg); err != nil {
		return nil, err
	}
	reply, err := conn.Read()
	if err != nil {
		return nil, err
	}
	retrn, ok := reply.(*returnMsg)
	if !ok {
		return nil, NewError("foreign return type")
	}
	if retrn.Err != nil {
		return nil, err
	}
	return retrn.Out, nil
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:17,代碼來源:dial.go

示例2: readGotPtrPtr

func (r *Runtime) readGotPtrPtr(ptrPtr []*ptrPtrMsg, conn circuit.Conn) error {
	p := make(map[handleID]struct{})
	for _, pp := range ptrPtr {
		p[pp.ID] = struct{}{}
	}
	for len(p) > 0 {
		m_, err := conn.Read()
		if err != nil {
			return err
		}
		m, ok := m_.(*gotPtrMsg)
		if !ok {
			return NewError("gotPtrMsg expected")
		}
		_, present := p[m.ID]
		if !present {
			return NewError("ack'ing unsent ptrPtrMsg")
		}
		delete(p, m.ID)
	}
	return nil
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:22,代碼來源:ptrptr.go

示例3: 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.
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:8,代碼來源:dial.go

示例4: 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})
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:16,代碼來源:ptrptr.go

示例5: 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)
}
開發者ID:rrudduck,項目名稱:golang-stuff,代碼行數:48,代碼來源:value.go

示例6: 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())
}
開發者ID:rrudduck,項目名稱:golang-stuff,代碼行數:6,代碼來源:value.go

示例7: 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()
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:43,代碼來源:func.go


注:本文中的circuit/use/circuit.Conn類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。