<commit_before>// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package servenv

import (
	"net"
	"time"
)

// ThrottledListener throttles the number connections
// accepted to the specified rate.
type ThrottledListener struct {
	net.Listener
	minDelay time.Duration
}

// NewThrottledListener creates a ThrottledListener. maxRate
// specifies the maximum rate of accepts per second.
func NewThrottledListener(l net.Listener, maxRate int64) net.Listener {
	return &ThrottledListener{l, time.Duration(1e9 / maxRate)}
}

// Accept accepts a new connection, but ensures that te
// rate does not exceed the specified maxRate.
func (tln *ThrottledListener) Accept() (c net.Conn, err error) {
	// We assume Accept is called in a tight loop.
	// So we can just sleep for minDelay
	time.Sleep(tln.minDelay)
	return tln.Listener.Accept()
}<commit_msg>te -> the<commit_after>// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package servenv

import (
	"net"
	"time"
)

// ThrottledListener throttles the number connections
// accepted to the specified rate.
type ThrottledListener struct {
	net.Listener
	minDelay time.Duration
}

// NewThrottledListener creates a ThrottledListener. maxRate
// specifies the maximum rate of accepts per second.
func NewThrottledListener(l net.Listener, maxRate int64) net.Listener {
	return &ThrottledListener{l, time.Duration(1e9 / maxRate)}
}

// Accept accepts a new connection, but ensures that the
// rate does not exceed the specified maxRate.
func (tln *ThrottledListener) Accept() (c net.Conn, err error) {
	// We assume Accept is called in a tight loop.
	// So we can just sleep for minDelay
	time.Sleep(tln.minDelay)
	return tln.Listener.Accept()
}
{'fraction_non_alphanumeric': 0.08539799683711123, 'fraction_numerical': 0.008434370057986295, 'mean_word_length': 3.9947368421052634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5090071', 'n_tokens_mistral': 573, 'n_tokens_neox': 569, 'n_words': 229}