本文整理汇总了Golang中github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-temp-err-catcher.TempErrCatcher.IsTemporary方法的典型用法代码示例。如果您正苦于以下问题:Golang TempErrCatcher.IsTemporary方法的具体用法?Golang TempErrCatcher.IsTemporary怎么用?Golang TempErrCatcher.IsTemporary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-temp-err-catcher.TempErrCatcher
的用法示例。
在下文中一共展示了TempErrCatcher.IsTemporary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: accept
// accept continously accepts incoming connections and
// adds them to the listener's Swarm. is is meant to be
// run in a goroutine.
// TODO: add rate limiting
func (l *Listener) accept() {
var wg sync.WaitGroup
defer func() {
wg.Wait() // must happen before teardown
l.teardown()
}()
// catching the error here is odd. doing what net/http does:
// http://golang.org/src/net/http/server.go?s=51504:51550#L1728
// Using the lib: https://godoc.org/github.com/jbenet/go-temp-err-catcher
var catcher tec.TempErrCatcher
// rate limit concurrency
limit := make(chan struct{}, AcceptConcurrency)
// loop forever accepting connections
for {
conn, err := l.netList.Accept()
if err != nil {
if catcher.IsTemporary(err) {
continue
}
l.acceptErr <- fmt.Errorf("peerstream listener failed: %s", err)
return // ok, problems. bail.
}
// add conn to swarm and listen for incoming streams
// do this in a goroutine to avoid blocking the Accept loop.
// note that this does not rate limit accepts.
limit <- struct{}{} // sema down
wg.Add(1)
go func(conn net.Conn) {
defer func() { <-limit }() // sema up
defer wg.Done()
conn2, err := l.swarm.addConn(conn, true)
if err != nil {
l.acceptErr <- err
return
}
conn2.groups.AddSet(&l.groups) // add out groups
}(conn)
}
}
示例2: tryTec
func tryTec(c tec.TempErrCatcher) {
errs := []error{
ErrTemp,
ErrSkip,
ErrOther,
ErrTemp,
ErrSkip,
ErrOther,
}
for _, e := range errs {
if c.IsTemporary(e) {
fmt.Printf("\tIsTemporary: true - skipped %s\n", e)
continue
}
fmt.Printf("\tIsTemporary: false - not skipped %s\n", e)
}
}
示例3: Accept
// Accept waits for and returns the next connection to the listener.
// Note that unfortunately this
func (l *listener) Accept() (net.Conn, error) {
// listeners dont have contexts. given changes dont make sense here anymore
// note that the parent of listener will Close, which will interrupt all io.
// Contexts and io don't mix.
ctx := context.Background()
var catcher tec.TempErrCatcher
catcher.IsTemp = func(e error) bool {
// ignore connection breakages up to this point. but log them
if e == io.EOF {
log.Debugf("listener ignoring conn with EOF: %s", e)
return true
}
te, ok := e.(tec.Temporary)
if ok {
log.Debugf("listener ignoring conn with temporary err: %s", e)
return te.Temporary()
}
return false
}
for {
maconn, err := l.Listener.Accept()
if err != nil {
if catcher.IsTemporary(err) {
continue
}
return nil, err
}
log.Debugf("listener %s got connection: %s <---> %s", l, maconn.LocalMultiaddr(), maconn.RemoteMultiaddr())
if l.filters != nil && l.filters.AddrBlocked(maconn.RemoteMultiaddr()) {
log.Debugf("blocked connection from %s", maconn.RemoteMultiaddr())
maconn.Close()
continue
}
// If we have a wrapper func, wrap this conn
if l.wrapper != nil {
maconn = l.wrapper(maconn)
}
c, err := newSingleConn(ctx, l.local, "", maconn)
if err != nil {
if catcher.IsTemporary(err) {
continue
}
return nil, err
}
if l.privk == nil || EncryptConnections == false {
log.Warning("listener %s listening INSECURELY!", l)
return c, nil
}
sc, err := newSecureConn(ctx, l.privk, c)
if err != nil {
log.Infof("ignoring conn we failed to secure: %s %s", err, c)
continue
}
return sc, nil
}
}