Пример #1
0
func (s *WardenServer) handleStreamOut(conn net.Conn, request *protocol.StreamOutRequest) (proto.Message, error) {
	handle := request.GetHandle()
	srcPath := request.GetSrcPath()

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

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

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

	writer := transport.NewProtobufStreamWriter(conn)

	reader, err := container.StreamOut(srcPath)
	if err != nil {
		return nil, err
	}

	_, err = io.Copy(writer, reader)
	if err != nil {
		return nil, err
	}

	return nil, writer.Close()
}
Пример #2
0
func (c *connection) StreamIn(handle string, dstPath string) (io.WriteCloser, error) {
	err := c.roundTrip(
		&protocol.StreamInRequest{
			Handle:  proto.String(handle),
			DstPath: proto.String(dstPath),
		},
		&protocol.StreamInResponse{},
	)

	if err != nil {
		return nil, err
	}

	c.writeLock.Lock()

	return releasenotifier.ReleaseNotifier{
		WriteCloser: transport.NewProtobufStreamWriter(c.conn),
		Callback:    c.writeLock.Unlock,
	}, nil
}