(n int)
| 159 | } |
| 160 | |
| 161 | func (st *SSHTransfer) setConnectionCount(n int) error { |
| 162 | count := len(st.conn) |
| 163 | if n < count { |
| 164 | tn := n |
| 165 | if tn == 0 { |
| 166 | tn = 1 |
| 167 | } |
| 168 | for i, item := range st.conn[tn:count] { |
| 169 | if item == nil { |
| 170 | tracerx.Printf("skipping uninitialized lazy pure SSH connection (#%d) (resetting total from %d to %d)", i, count, n) |
| 171 | continue |
| 172 | } |
| 173 | tracerx.Printf("terminating pure SSH connection (#%d) (resetting total from %d to %d)", tn+i, count, n) |
| 174 | if err := item.End(); err != nil { |
| 175 | return err |
| 176 | } |
| 177 | } |
| 178 | st.conn = st.conn[0:tn] |
| 179 | } else if n > count { |
| 180 | for i := count; i < n; i++ { |
| 181 | if i == 0 { |
| 182 | conn, controlPath, err := st.spawnConnection(i) |
| 183 | if err != nil { |
| 184 | return err |
| 185 | } |
| 186 | st.conn = append(st.conn, conn) |
| 187 | st.controlPath = controlPath |
| 188 | } else { |
| 189 | st.conn = append(st.conn, nil) |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | if n == 0 && count > 0 { |
| 194 | tracerx.Printf("terminating pure SSH connection (#0) (resetting total from %d to %d)", count, n) |
| 195 | if err := st.conn[0].End(); err != nil { |
| 196 | return err |
| 197 | } |
| 198 | st.conn = nil |
| 199 | st.controlPath = "" |
| 200 | } |
| 201 | return nil |
| 202 | } |
| 203 | |
| 204 | func (st *SSHTransfer) Shutdown() error { |
| 205 | tracerx.Printf("shutting down pure SSH connections") |
no test coverage detected