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() }
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 }