Skip to content

Commit

Permalink
cleanup: remove package bicopy
Browse files Browse the repository at this point in the history
This has a single caller that doesn't even use the full interface.

This changes behavior in that errors are no longer ignored.

While I'm here: remove nonsensical handling of `io.EOF` returned from
`io.Copy` which can never happen per the latter's documentation.

Signed-off-by: Tamir Duberstein <[email protected]>
  • Loading branch information
tamird committed Nov 27, 2024
1 parent ca778e3 commit 6a612d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 90 deletions.
81 changes: 0 additions & 81 deletions pkg/bicopy/bicopy.go

This file was deleted.

19 changes: 16 additions & 3 deletions pkg/hostagent/port_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package hostagent

import (
"context"
"errors"
"fmt"
"io"
"net"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/lima-vm/lima/pkg/bicopy"
"github.com/lima-vm/lima/pkg/portfwd"
"github.com/lima-vm/sshocker/pkg/ssh"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)

// forwardTCP is not thread-safe.
Expand Down Expand Up @@ -149,8 +151,19 @@ func (plf *pseudoLoopbackForwarder) forward(ac *net.TCPConn) error {
return err
}
defer unixConn.Close()
bicopy.Bicopy(ac, unixConn, nil)
return nil

g, _ := errgroup.WithContext(context.Background())

g.Go(func() error {
_, err := io.Copy(unixConn, ac)
return errors.Join(err, unixConn.CloseRead(), ac.CloseWrite())
})
g.Go(func() error {
_, err := io.Copy(ac, unixConn)
return errors.Join(err, ac.CloseRead(), unixConn.CloseWrite())
})

return g.Wait()
}

func (plf *pseudoLoopbackForwarder) Close() error {
Expand Down
6 changes: 0 additions & 6 deletions pkg/portfwd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@ func HandleTCPConnection(ctx context.Context, client *guestagentclient.GuestAgen
rw := &GrpcClientRW{stream: stream, id: id, addr: guestAddr}
g.Go(func() error {
_, err := io.Copy(rw, conn)
if errors.Is(err, io.EOF) {
return nil
}
return err
})
g.Go(func() error {
_, err := io.Copy(conn, rw)
if errors.Is(err, io.EOF) {
return nil
}
return err
})

Expand Down

0 comments on commit 6a612d9

Please sign in to comment.