goConnectPool
1.0.0
Golang用のGo Net.Connプール。プール(FATIH/プール)に触発されて、アクティブな接続番号を制限するためにコードと関数を追加します。
go get github.com/dubin555/goConnectPoolマスターブランチコードを使用してください。
// a factory func to generate a net connection.
factory := func () (net. Conn , error ) { return net . Dial ( "tcp" , "127.0.0.1:9999" ) }
// create a new channel based pool with an initial capacity of 5, maximum capacity of 30,
// and maximum actives of 15.
pool , err := pool . NewChannelPool ( 5 , 30 , 15 , factory )
// get a connection from the pool, non blocking mode, if reach the limit, return nil instead.
// Block Mode
conn , err := pool . Get ()
// balabalabala
// close the conn, will release the conn to the pool by calling Close()
conn . Close ()
// Non Blocking Mode, will return nil when no permission
conn , err := pool . TryGet ()
// close the pool
pool . Close ()
// return the connections length
p . Len ()
// return the current active permissions
p . LenActives ()