<commit_before>// Copyright 2015-2017 HenryLee. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tp

import (
	"crypto/tls"
	"os"
	"sync"
	"time"

	"github.com/henrylee2cn/goutil/pool"

	"github.com/henrylee2cn/teleport/socket"
)

var (
	maxGoroutinesAmount      int
	maxGoroutineIdleDuration time.Duration
	_gopool                  *pool.GoPool
	newGopoolOnce            sync.Once
)

func init() {
	Printf("The current process PID: %d", os.Getpid())
}

// GetSenderPacket returns a packet for sending.
//  func GetSenderPacket(typ int32, uri string, body interface{}, setting ...socket.PacketSetting) *socket.Packet
var GetSenderPacket = socket.GetSenderPacket

// GetReceiverPacket returns a packet for sending.
//  func GetReceiverPacket(bodyGetting func(*socket.Header) interface{}) *socket.Packet
var GetReceiverPacket = socket.GetReceiverPacket

// PutPacket puts a *socket.Packet to packet stack.
//  func PutPacket(p *socket.Packet)
var PutPacket = socket.PutPacket

// Go go func
func Go(fn func()) {
	newGopoolOnce.Do(func() {
		_gopool = pool.NewGoPool(maxGoroutinesAmount, maxGoroutineIdleDuration)
	})
	var err error
	for {<commit_msg>Add SetGopool()<commit_after>// Copyright 2015-2017 HenryLee. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tp

import (
	"crypto/tls"
	"os"
	"sync"
	"time"

	"github.com/henrylee2cn/goutil/pool"

	"github.com/henrylee2cn/teleport/socket"
)

// GetSenderPacket returns a packet for sending.
//  func GetSenderPacket(typ int32, uri string, body interface{}, setting ...socket.PacketSetting) *socket.Packet
var GetSenderPacket = socket.GetSenderPacket

// GetReceiverPacket returns a packet for sending.
//  func GetReceiverPacket(bodyGetting func(*socket.Header) interface{}) *socket.Packet
var GetReceiverPacket = socket.GetReceiverPacket

// PutPacket puts a *socket.Packet to packet stack.
//  func PutPacket(p *socket.Packet)
var PutPacket = socket.PutPacket

func init() {
	Printf("The current process PID: %d", os.Getpid())
}

var (
	_maxGoroutinesAmount      int
	_maxGoroutineIdleDuration time.Duration
	_gopool                   *pool.GoPool
	setGopoolOnce             sync.Once
)

// SetGopool set or reset go pool config.
// Note: Make sure to call it before calling NewPeer() and Go()
func SetGopool(maxGoroutinesAmount int, maxGoroutineIdleDuration time.Duration) {
	_maxGoroutinesAmount, _maxGoroutineIdleDuration := maxGoroutinesAmount, maxGoroutineIdleDuration
	_gopool = pool.NewGoPool(_maxGoroutinesAmount, _maxGoroutineIdleDuration)
}

// Go go func
func Go(fn func()) {
	setGopoolOnce.Do(func() {
		if _gopool == nil {
			SetGopool(_maxGoroutinesAmount, _maxGoroutineIdleDuration)
		}
	})
	var err error
	for {
{'fraction_non_alphanumeric': 0.0976063829787234, 'fraction_numerical': 0.00851063829787234, 'mean_word_length': 3.8844155844155845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5761813', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1145, 'n_words': 375}