getClient is used to get a usable client for an address.
(addr net.Addr)
| 297 | |
| 298 | // getClient is used to get a usable client for an address. |
| 299 | func (p *connPool) getClient(addr net.Addr) (*conn, *streamClient, error) { |
| 300 | retries := 0 |
| 301 | START: |
| 302 | // Try to get a conn first |
| 303 | conn, err := p.acquire(addr) |
| 304 | if err != nil { |
| 305 | return nil, nil, fmt.Errorf("failed to get conn: %v", err) |
| 306 | } |
| 307 | |
| 308 | // Get a client |
| 309 | client, err := conn.getClient() |
| 310 | if err != nil { |
| 311 | p.clearConn(conn) |
| 312 | p.releaseConn(conn) |
| 313 | |
| 314 | // Try to redial, possible that the TCP session closed due to timeout |
| 315 | if retries == 0 { |
| 316 | retries++ |
| 317 | goto START |
| 318 | } |
| 319 | return nil, nil, fmt.Errorf("failed to start stream: %v", err) |
| 320 | } |
| 321 | return conn, client, nil |
| 322 | } |
| 323 | |
| 324 | // RPC is used to make an RPC call to a remote host |
| 325 | func (p *connPool) RPC(addr net.Addr, method string, args interface{}, reply interface{}) error { |
no test coverage detected