// DoStream executes streaming request.
433237
func (c *Client) DoStream(ctx context.Context, req *http.Request) (*http.Response, error) {
	resp, err := c.do(ctx, req)
	if err != nil {
		return nil, err
	}

	if resp.StatusCode != http.StatusOK {
		resp.Body.Close()
		return nil, getErrorFromResponse(resp)
	}

	return resp, nil
}
141934
func (f StreamInboundFunc) HandleStream(s *transport.ServerStream, h transport.StreamHandler) error {
	return f(s, h)
}
556803
func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (inet.Stream, error) {
	log.Debugf("[%s] opening stream to peer [%s]", s.local, p)

	// Algorithm:
	// 1. Find the best connection, otherwise, dial.
	// 2. Try opening a stream.
	// 3. If the underlying connection is, in fact, closed, close the outer
	//    connection and try again. We do this in case we have a closed
	//    connection but don't notice it until we actually try to open a
	//    stream.
	//
	// Note: We only dial once.
	//
	// TODO: Try all connections even if we get an error opening a stream on
	// a non-closed connection.
	dials := 0
	for {
		c := s.bestConnToPeer(p)
		if c == nil {
			if nodial, _ := inet.GetNoDial(ctx); nodial {
				return nil, inet.ErrNoConn
			}

			if dials >= DialAttempts {
				return nil, errors.New("max dial attempts exceeded")
			}
			dials++

			var err error
			c, err = s.dialPeer(ctx, p)
			if err != nil {
				return nil, err
			}
		}
		s, err := c.NewStream()
		if err != nil {
			if c.conn.IsClosed() {
				continue
			}
			return nil, err
		}
		return s, nil
	}
}
20621
func (c *Client) DoStruct(opts interface{}, in interface{}) (interface{}, error) {
	if _, ok := opts.(*RpbGetReq); ok {
		return c.fetchStruct(opts.(*RpbGetReq), string(opts.(*RpbGetReq).GetBucket()), string(opts.(*RpbGetReq).GetKey()), in)
	}
	if _, ok := opts.(*RpbPutReq); ok {
		return c.storeStruct(opts.(*RpbPutReq), string(opts.(*RpbPutReq).GetBucket()), string(opts.(*RpbPutReq).GetKey()), in)
	}

	return nil, nil
}
1018793
func (l *bunyanLog) writeStream(stream Stream, data []byte) error {
	stream.Stream.Write(data)
	return nil
}
663888
func (c *Client) CreateStream(request CreateStream) error {
	err := c.kinesisReqNoResponse("CreateStream", request)
	return err
}
596558
func (conn *VTGateConn) UpdateStream(ctx context.Context, keyspace, shard string, keyRange *topodatapb.KeyRange, tabletType topodatapb.TabletType, timestamp int64, event *querypb.EventToken) (UpdateStreamReader, error) {
	return conn.impl.UpdateStream(ctx, keyspace, shard, keyRange, tabletType, timestamp, event)
}
694194
func (sf StreamerFunc) Stream(samples [][2]float64) (n int, ok bool) {
	return sf(samples)
}
341583
func (c *Client) Stream(method, path string, in, out interface{}) (stream.Stream, error) {
	return c.StreamWithHeader(method, path, make(http.Header), in, out)
}
1319171
func (ctx *Context) Stream(code int, contentType string, r io.Reader) (err error) {
	if ctx.Res.ended.swapTrue() {
		ctx.Status(code)
		ctx.Type(contentType)
		_, err = io.Copy(ctx.Res, r)
	} else {
		err = ErrInternalServerError.WithMsg("request ended before ctx.Stream")
	}
	return
}
449796
func (this *engine) DirectHttpStream(w http.ResponseWriter, r *http.Request) (chan<- interface{}, error) {

	// Make sure that the writer supports flushing.
	f, ok := w.(http.Flusher)
	if !ok {
		return nil, errors.New("streaming-unsupported")
	}

	// Create a new channel, over which the broker can
	// send this client messages.
	messageChan := make(chan interface{})

	// Set the headers related to event streaming.
	w.Header().Set("Content-Type", "text/event-stream")
	w.Header().Set("Cache-Control", "no-cache")
	w.Header().Set("Connection", "keep-alive")

	go func() {
		for {
			// Read from our messageChan.
			msg, open := <-messageChan

			if !open || msg == nil {
				// If our messageChan was closed, this means that the client has
				// disconnected.
				glog.V(100).Infoln("Messages stopped.. Closing http connection")
				break
			}

			// by type switch
			switch t := msg.(type) {
			default:
				fmt.Fprintf(w, "event: %s\n", t)
				fmt.Fprint(w, "data: ")
				json_marshaler("application/json", w, &msg, no_header)
				fmt.Fprint(w, "\n\n")
			case string:
				fmt.Fprintf(w, "%s\n", msg.(string))
			case []byte:
				fmt.Fprintf(w, "%s\n", string(msg.([]byte)))
			}

			// Flush the response.  This is only possible if
			// the repsonse supports streaming.
			f.Flush()
		}
		// Done.
		glog.V(100).Infoln("Finished HTTP request at ", r.URL.Path)
	}()

	return messageChan, nil
}
323644
func NewStream(w io.Writer) *Stream {
	return &Stream{
		Writer: w,
		enc:    json.NewEncoder(w),
	}
}
413600
func newStream(r io.Reader) *stream {
	return &stream{r, make([]byte, buffer), buffer}
}
1233177
func (c *conn) AcceptStream() (smux.Stream, error) {
	s, err := c.yamuxSession().AcceptStream()
	return s, err
}
1171653
func (s *Session) OpenStream() (*Stream, error) {
	if s.IsClosed() {
		return nil, ErrSessionShutdown
	}
	if atomic.LoadInt32(&s.remoteGoAway) == 1 {
		return nil, ErrRemoteGoAway
	}

	// Block if we have too many inflight SYNs
	select {
	case s.synCh <- struct{}{}:
	case <-s.shutdownCh:
		return nil, ErrSessionShutdown
	}

GET_ID:
	// Get an ID, and check for stream exhaustion
	id := atomic.LoadUint32(&s.nextStreamID)
	if id >= math.MaxUint32-1 {
		return nil, ErrStreamsExhausted
	}
	if !atomic.CompareAndSwapUint32(&s.nextStreamID, id, id+2) {
		goto GET_ID
	}

	// Register the stream
	stream := newStream(s, id, streamInit)
	s.streamLock.Lock()
	s.streams[id] = stream
	s.inflight[id] = struct{}{}
	s.streamLock.Unlock()

	// Send the window update to create
	if err := stream.sendWindowUpdate(); err != nil {
		select {
		case <-s.synCh:
		default:
			s.logger.Printf("[ERR] yamux: aborted stream open without inflight syn semaphore")
		}
		return nil, err
	}
	return stream, nil
}
729570
func (a *Adapter) Stream(logstream chan *router.Message) {
	for message := range logstream {
		m := &Message{message}
		buf, err := m.Render(a.tmpl)
		if err != nil {
			log.Println("syslog:", err)
			return
		}
		if _, err = a.conn.Write(buf); err != nil {
			log.Println("syslog:", err)
			switch a.conn.(type) {
			case *net.UDPConn:
				continue
			default:
				if err = a.retry(buf, err); err != nil {
					log.Panicf("syslog retry err: %+v", err)
					return
				}
			}
		}
	}
}
379081
func (c *Client) DescribeStream(request DescribeStreamRequest) (*DescribeStreamResponse, error) {
	resp := &DescribeStreamResponse{}
	err := c.kinesisReqWithResponse("DescribeStream", request, resp)
	return resp, err
}