Пример #1
0
func (s *WardenServer) handleStreamIn(conn net.Conn, reader *bufio.Reader, request *protocol.StreamInRequest) (proto.Message, error) {
	handle := request.GetHandle()
	dstPath := request.GetDstPath()

	container, err := s.backend.Lookup(handle)
	if err != nil {
		return nil, err
	}

	s.bomberman.Pause(container.Handle())
	defer s.bomberman.Unpause(container.Handle())

	streamWriter, err := container.StreamIn(dstPath)
	if err != nil {
		return nil, err
	}

	_, err = protocol.Messages(&protocol.StreamInResponse{}).WriteTo(conn)
	if err != nil {
		return nil, err
	}

	streamReader := transport.NewProtobufStreamReader(reader)

	_, err = io.Copy(streamWriter, streamReader)
	if err != nil {
		return nil, err
	}

	return nil, streamWriter.Close()
}
Пример #2
0
func (c *connection) StreamOut(handle string, srcPath string) (io.Reader, error) {
	err := c.roundTrip(
		&protocol.StreamOutRequest{
			Handle:  proto.String(handle),
			SrcPath: proto.String(srcPath),
		},
		&protocol.StreamOutResponse{},
	)

	if err != nil {
		return nil, err
	}

	c.readLock.Lock()

	return releasenotifier.ReleaseNotifier{
		Reader:   transport.NewProtobufStreamReader(c.read),
		Callback: c.readLock.Unlock,
	}, nil
}