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


Golang net.IsProbableEOF函數代碼示例

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


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

示例1: receive

// receive reads result from the decoder in a loop and sends down the result channel.
func (sw *StreamWatcher) receive() {
    defer close(sw.result)
    defer sw.Stop()
    defer utilruntime.HandleCrash()
    for {
        action, obj, err := sw.source.Decode()
        if err != nil {
            // Ignore expected error.
            if sw.stopping() {
                return
            }
            switch err {
            case io.EOF:
                // watch closed normally
            case io.ErrUnexpectedEOF:
                glog.V(1).Infof("Unexpected EOF during watch stream event decoding: %v", err)
            default:
                msg := "Unable to decode an event from the watch stream: %v"
                if net.IsProbableEOF(err) {
                    glog.V(5).Infof(msg, err)
                } else {
                    glog.Errorf(msg, err)
                }
            }
            return
        }
        sw.result <- Event{
            Type:   action,
            Object: obj,
        }
    }
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:33,代碼來源:iowatcher.go

示例2: Watch

// Watch attempts to begin watching the requested location.
// Returns a watch.Interface, or an error.
func (r *Request) Watch() (watch.Interface, error) {
    // We specifically don't want to rate limit watches, so we
    // don't use r.throttle here.
    if r.err != nil {
        return nil, r.err
    }
    if r.serializers.Framer == nil {
        return nil, fmt.Errorf("watching resources is not possible with this client (content-type: %s)", r.content.ContentType)
    }

    url := r.URL().String()
    req, err := http.NewRequest(r.verb, url, r.body)
    if err != nil {
        return nil, err
    }
    req.Header = r.headers
    client := r.client
    if client == nil {
        client = http.DefaultClient
    }
    r.backoffMgr.Sleep(r.backoffMgr.CalculateBackoff(r.URL()))
    resp, err := client.Do(req)
    updateURLMetrics(r, resp, err)
    if r.baseURL != nil {
        if err != nil {
            r.backoffMgr.UpdateBackoff(r.baseURL, err, 0)
        } else {
            r.backoffMgr.UpdateBackoff(r.baseURL, err, resp.StatusCode)
        }
    }
    if err != nil {
        // The watch stream mechanism handles many common partial data errors, so closed
        // connections can be retried in many cases.
        if net.IsProbableEOF(err) {
            return watch.NewEmptyWatch(), nil
        }
        return nil, err
    }
    if resp.StatusCode != http.StatusOK {
        defer resp.Body.Close()
        if result := r.transformResponse(resp, req); result.err != nil {
            return nil, result.err
        }
        return nil, fmt.Errorf("for request '%+v', got status: %v", url, resp.StatusCode)
    }
    framer := r.serializers.Framer.NewFrameReader(resp.Body)
    decoder := streaming.NewDecoder(framer, r.serializers.StreamingSerializer)
    return watch.NewStreamWatcher(versioned.NewDecoder(decoder, r.serializers.Decoder)), nil
}
開發者ID:hyperhq,項目名稱:hypernetes,代碼行數:51,代碼來源:request.go

示例3: Watch

// Watch attempts to begin watching the requested location.
// Returns a watch.Interface, or an error.
func (r *Request) Watch() (watch.Interface, error) {
    // We specifically don't want to rate limit watches, so we
    // don't use r.throttle here.
    if r.err != nil {
        return nil, r.err
    }
    url := r.URL().String()
    req, err := http.NewRequest(r.verb, url, r.body)
    if err != nil {
        return nil, err
    }
    client := r.client
    if client == nil {
        client = http.DefaultClient
    }
    r.backoffMgr.Sleep(r.backoffMgr.CalculateBackoff(r.URL()))
    resp, err := client.Do(req)
    updateURLMetrics(r, resp, err)
    if r.baseURL != nil {
        if err != nil {
            r.backoffMgr.UpdateBackoff(r.baseURL, err, 0)
        } else {
            r.backoffMgr.UpdateBackoff(r.baseURL, err, resp.StatusCode)
        }
    }
    if err != nil {
        // The watch stream mechanism handles many common partial data errors, so closed
        // connections can be retried in many cases.
        if net.IsProbableEOF(err) {
            return watch.NewEmptyWatch(), nil
        }
        return nil, err
    }
    if resp.StatusCode != http.StatusOK {
        defer resp.Body.Close()
        if result := r.transformResponse(resp, req); result.err != nil {
            return nil, result.err
        }
        return nil, fmt.Errorf("for request '%+v', got status: %v", url, resp.StatusCode)
    }
    return watch.NewStreamWatcher(watchjson.NewDecoder(resp.Body, r.content.Codec)), nil
}
開發者ID:asiainfoLDP,項目名稱:datafactory,代碼行數:44,代碼來源:request.go


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