MCPcopy Create free account
hub / github.com/dadgar/onecache / getClient

Method getClient

onecache/pool.go:299–322  ·  view source on GitHub ↗

getClient is used to get a usable client for an address.

(addr net.Addr)

Source from the content-addressed store, hash-verified

297
298// getClient is used to get a usable client for an address.
299func (p *connPool) getClient(addr net.Addr) (*conn, *streamClient, error) {
300 retries := 0
301START:
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
325func (p *connPool) RPC(addr net.Addr, method string, args interface{}, reply interface{}) error {

Callers 1

RPCMethod · 0.95

Calls 4

acquireMethod · 0.95
clearConnMethod · 0.95
releaseConnMethod · 0.95
getClientMethod · 0.45

Tested by

no test coverage detected