本文整理匯總了Golang中github.com/NebulousLabs/Sia/modules.PeerConn.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang PeerConn.Close方法的具體用法?Golang PeerConn.Close怎麽用?Golang PeerConn.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/modules.PeerConn
的用法示例。
在下文中一共展示了PeerConn.Close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: threadedHandleConn
// threadedHandleConn reads header data from a connection, then routes it to the
// appropriate handler for further processing.
func (g *Gateway) threadedHandleConn(conn modules.PeerConn) {
defer conn.Close()
var id rpcID
if err := encoding.ReadObject(conn, &id, 8); err != nil {
return
}
// call registered handler for this ID
lockid := g.mu.RLock()
fn, ok := g.handlers[id]
g.mu.RUnlock(lockid)
if !ok {
g.log.Printf("WARN: incoming conn %v requested unknown RPC \"%v\"", conn.RemoteAddr(), id)
return
}
// call fn
err := fn(conn)
// don't log benign errors
if err == modules.ErrDuplicateTransactionSet || err == modules.ErrBlockKnown {
err = nil
}
if err != nil {
g.log.Printf("WARN: incoming RPC \"%v\" failed: %v", id, err)
}
}
示例2: threadedHandleConn
// threadedHandleConn reads header data from a connection, then routes it to the
// appropriate handler for further processing.
func (g *Gateway) threadedHandleConn(conn modules.PeerConn) {
defer conn.Close()
var id rpcID
if err := encoding.ReadObject(conn, &id, 8); err != nil {
g.log.Printf("WARN: could not read RPC identifier from incoming conn %v: %v", conn.RemoteAddr(), err)
return
}
// call registered handler for this ID
lockid := g.mu.RLock()
fn, ok := g.handlers[id]
g.mu.RUnlock(lockid)
if !ok {
g.log.Printf("WARN: incoming conn %v requested unknown RPC \"%v\"", conn.RemoteAddr(), id)
return
}
if err := fn(conn); err != nil {
g.log.Printf("WARN: incoming RPC \"%v\" failed: %v", id, err)
}
}