Connect connects the client to the tunnel.
(ctx context.Context)
| 87 | |
| 88 | // Connect connects the client to the tunnel. |
| 89 | func (c *CodespaceConnection) Connect(ctx context.Context) error { |
| 90 | // Lock the mutex to prevent race conditions with the underlying SSH connection |
| 91 | c.TunnelClient.mu.Lock() |
| 92 | defer c.TunnelClient.mu.Unlock() |
| 93 | |
| 94 | // If already connected, return |
| 95 | if c.TunnelClient.connected { |
| 96 | return nil |
| 97 | } |
| 98 | |
| 99 | // Connect to the tunnel |
| 100 | if err := c.TunnelClient.Client.Connect(ctx, ""); err != nil { |
| 101 | return fmt.Errorf("error connecting to tunnel: %w", err) |
| 102 | } |
| 103 | |
| 104 | // Set the connected flag so we know we're connected |
| 105 | c.TunnelClient.connected = true |
| 106 | |
| 107 | return nil |
| 108 | } |
| 109 | |
| 110 | // Close closes the underlying tunnel client SSH connection. |
| 111 | func (c *CodespaceConnection) Close() error { |
no test coverage detected