Git Product home page Git Product logo

vconnpool's Introduction

vconnpool Build Status

golang vconnpool,可以TCP连接复用,使用方法和 net.Dialer 接口是相同。

列表:

type Dialer interface {                                                 // net.Dialer 接口
    Dial(network, address string) (net.Conn, error)                             // 拨号
    DialContext(ctx context.Context, network, address string) (net.Conn, error) // 拨号(支持上下文)
}
type Conn interface{                                                    // 连接接口
    net.Conn                                                                    // net连接接口
    Discard() error                                                             // 废弃(这条连接不再回收)
    IsReuseConn() bool                                                          // 判断这条连接是否是从池中读取出来的
}
type ConnPool struct {                                                  // 连接池
    *net.Dialer                                                                 // 拨号
    IdeConn     int                                                             // 空闲连接数,0为不复用连接
    MaxConn     int                                                             // 最大连接数,0为无限制连接
}
    func (cp *ConnPool) Dial(network, address string) (net.Conn, error)         // 拨号,如果 address 参数是host域名,.Get(...)将无法读取到连接。请再次使用 .Dial(...) 来读取。
    func (cp *ConnPool) DialContext(ctx context.Context, network, address string) (net.Conn, error) //拨号(支持上下文),如果 address 参数是host域名,.Get(...)将无法读取到连接。请再次使用 .Dial(...) 来读取。
    func (cp *ConnPool) Add(addr net.Addr, conn net.Conn) error                 // 增加连接
    func (cp *ConnPool) Get(addr net.Addr) (net.Conn, error)                    // 读取连接,读取出来的连接不会自动回收,需要调用 .Add(...) 收入
    func (cp *ConnPool) ConnNum() int                                           // 当前连接数量
    func (cp *ConnPool) ConnNumIde(network, address string) int                 // 当前连接数量(空闲)
    func (cp *ConnPool) CloseIdleConnections()                                  // 关闭空闲连接
    func (cp *ConnPool) Close() error                                           // 关闭连接池

vconnpool's People

Contributors

456vv avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.