Esempio n. 1
0
func (s *streamSession) createPipe() (Receiver, Sender) {
	r, w := io.Pipe()
	s.pipeLock.Lock()
	pipeID := s.pipeCount + 1
	s.pipeCount = pipeID
	s.pipeReaders[pipeID] = r
	s.pipeWriters[pipeID] = w
	s.pipeLock.Unlock()

	recv := &pipeReceiver{pipeID, s, r, codec.NewDecoder(r, s.handler)}
	send := &pipeSender{pipeID, s, w, codec.NewEncoder(w, s.handler)}
	return recv, send
}
Esempio n. 2
0
func (s *streamSession) decodeSender(v reflect.Value, b []byte) error {
	pipeID, readN := binary.Uvarint(b)
	if readN == 0 {
		return errors.New("bad reference id")
	}

	w, ok := s.pipeWriters[pipeID]
	if !ok {
		return errors.New("receiver does not exist")
	}

	v.Set(reflect.ValueOf(pipeSender{pipeID, s, w, codec.NewEncoder(w, s.handler)}))

	return nil
}