forward dials the remote host specific in req, upgrades the request, starts listeners for each port specified in ports, and forwards local connections to the remote host via streams.
()
| 202 | // listeners for each port specified in ports, and forwards local connections |
| 203 | // to the remote host via streams. |
| 204 | func (pf *PortForwarder) forward() error { |
| 205 | var err error |
| 206 | |
| 207 | listenSuccess := false |
| 208 | for i := range pf.ports { |
| 209 | port := &pf.ports[i] |
| 210 | err = pf.listenOnPort(port) |
| 211 | switch { |
| 212 | case err == nil: |
| 213 | listenSuccess = true |
| 214 | default: |
| 215 | if pf.errOut != nil { |
| 216 | fmt.Fprintf(pf.errOut, "Unable to listen on port %d: %v\n", port.Local, err) |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if !listenSuccess { |
| 222 | return fmt.Errorf("Unable to listen on any of the requested ports: %v", pf.ports) |
| 223 | } |
| 224 | |
| 225 | if pf.Ready != nil { |
| 226 | close(pf.Ready) |
| 227 | } |
| 228 | |
| 229 | // wait for interrupt or conn closure |
| 230 | select { |
| 231 | case <-pf.stopChan: |
| 232 | case <-pf.streamConn.CloseChan(): |
| 233 | runtime.HandleError(errors.New("lost connection to pod")) |
| 234 | } |
| 235 | |
| 236 | return nil |
| 237 | } |
| 238 | |
| 239 | // listenOnPort delegates listener creation and waits for connections on requested bind addresses. |
| 240 | // An error is raised based on address groups (default and localhost) and their failure modes |
no test coverage detected