<commit_before>package ssgo

import (
	"net"
	"runtime"
	"time"
)

type ConPool struct {
	ctype    string
	clink    string
	ctimeout time.Duration
	conns    chan *Client
}

func NewConPool(hostAddr string, maxConn int) *ConPool {

	if maxConn < 1 {
		maxConn = runtime.NumCPU() * 2
	}

	cr := &ConPool{
		ctype:    "tcp",
		clink:    hostAddr,
		ctimeout: time.Duration(10) * time.Second,
		conns:    make(chan *Client, maxConn),
	}

	//	if cr.ctimeout < 1*time.Second {
	//		cr.ctimeout = 10 * time.Second
	//	}

	return cr
}

func dialTimeout(network, addr string) (*Client, error) {

	raddr, err := net.ResolveTCPAddr(network, addr)
	if err != nil {
		return nil, err
	}
	sock, err := net.DialTCP(network, nil, raddr)
	if err != nil {
		return nil, err
	}

	return &Client{sock: sock}, nil
}

func (cr *ConPool) dialNew() (*Client, error) {
	cn, err := dialTimeout(cr.ctype, cr.clink)
	if err != nil {
		return nil, err
	}
	cn.pool = cr
	return cn, nil
}

//func (cr *ConPool) Cmd(args ...interface{}) *Reply {
//
//	cn, _ := cr.GetClient()
//	defer cn.Release()
//
//	cn.sock.SetReadDeadline(time.Now().Add(cr.ctimeout))
//	cn.sock.SetWriteDeadline(time.Now().Add(cr.ctimeout))
//
//	return cn.Cmd(args...)
//}

func (cr *ConPool) Close() {
	var conn *Client
	for {
		select {
		case conn = <-cr.conns:
			conn.close()
		default:
			return
		}
	}
}

func (cr *ConPool) push(cn *Client) {
	select {
	case cr.conns <- cn:<commit_msg>no message<commit_after>package ssgo

import (
	"net"
	"runtime"
	"time"
)

type ConPool struct {
	ctype    string
	clink    string
	ctimeout time.Duration
	conns    chan *Client
}

func NewConPool(hostAddr string, maxConn int) *ConPool {

	if maxConn < 1 {
		maxConn = runtime.NumCPU() * 2
	}

	cr := &ConPool{
		ctype:    "tcp",
		clink:    hostAddr,
		ctimeout: time.Duration(10) * time.Second,
		conns:    make(chan *Client, maxConn),
	}

	//	if cr.ctimeout < 1*time.Second {
	//		cr.ctimeout = 10 * time.Second
	//	}

	return cr
}

func dialTimeout(network, addr string) (*Client, error) {

	raddr, err := net.ResolveTCPAddr(network, addr)
	if err != nil {
		return nil, err
	}
	sock, err := net.DialTCP(network, nil, raddr)
	if err != nil {
		return nil, err
	}

	return &Client{sock: sock}, nil
}

func (cr *ConPool) dialNew() (*Client, error) {
	cn, err := dialTimeout(cr.ctype, cr.clink)
	if err != nil {
		return nil, err
	}
	cn.pool = cr
	return cn, nil
}

func (cr *ConPool) Do(args ...interface{}) (Reply, error) {

	cn, e := cr.GetClient()
	if e != nil {
		return nil, e
	}
	defer cn.Release()

	cn.sock.SetReadDeadline(time.Now().Add(cr.ctimeout))
	cn.sock.SetWriteDeadline(time.Now().Add(cr.ctimeout))

	return cn.Do(args...)
}

func (cr *ConPool) Close() {
	var conn *Client
	for {
		select {
		case conn = <-cr.conns:
			conn.close()
		default:
			return
		}
	}
}

func (cr *ConPool) push(cn *Client) {
	select {
	case cr.conns <- cn:
{'fraction_non_alphanumeric': 0.1603740907516453, 'fraction_numerical': 0.0048493245583650845, 'mean_word_length': 3.044817927170868, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4676968', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1164, 'n_words': 290}