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

Method getNewConn

onecache/pool.go:230–270  ·  view source on GitHub ↗

getNewConn is used to return a new connection

(addr net.Addr)

Source from the content-addressed store, hash-verified

228
229// getNewConn is used to return a new connection
230func (p *connPool) getNewConn(addr net.Addr) (*conn, error) {
231 // Try to dial the conn
232 con, err := net.DialTimeout("tcp", addr.String(), 10*time.Second)
233 if err != nil {
234 return nil, err
235 }
236
237 // Cast to TCPConn
238 if tcp, ok := con.(*net.TCPConn); ok {
239 tcp.SetKeepAlive(true)
240 tcp.SetNoDelay(true)
241 }
242
243 // Write the multiplex byte to set the mode
244 if _, err := con.Write([]byte{byte(rpcInternal)}); err != nil {
245 con.Close()
246 return nil, err
247 }
248
249 // Setup the logger
250 conf := yamux.DefaultConfig()
251 conf.LogOutput = p.logOutput
252
253 // Create a multiplexed session
254 session, err := yamux.Client(con, conf)
255 if err != nil {
256 con.Close()
257 return nil, err
258 }
259
260 // Wrap the connection
261 c := &conn{
262 refCount: 1,
263 addr: addr,
264 session: session,
265 clients: list.New(),
266 lastUsed: time.Now(),
267 pool: p,
268 }
269 return c, nil
270}
271
272// clearConn is used to clear any cached connection, potentially in response to an erro
273func (p *connPool) clearConn(conn *conn) {

Callers 1

acquireMethod · 0.95

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected