<commit_before>package client

import (
	"bufio"
	// "encoding/json"
	"fmt"
	"github.com/trendrr/goshire/cheshire"
	// "github.com/trendrr/goshire/dynmap"
	"io"
	"log"
	"net"
	"sync"
	"sync/atomic"
	"time"
)

// A single connection to a cheshire server.
// The connection is considered fail fast
// should be disconnected and reaped

// This is not threadsafe and should only be used in one routine at a time.
type cheshireConn struct {
	net.Conn
	addr         string
	connected    int32
	readTimeout  time.Duration
	writeTimeout time.Duration
	incomingChan chan *cheshire.Response
	outgoingChan chan *cheshireRequest
	exitChan     chan int
	//every new request will push a bool into this chan,
	//it will block once full
	inflightChan chan bool

	//map of txnId to request
	requests     map[string]*cheshireRequest
	requestsLock sync.RWMutex

	connectedAt time.Time
	maxInFlight int
	protocol cheshire.Protocol
}

//wrap a request so we dont lose track of the result channels
type cheshireRequest struct {
	req        *cheshire.Request
	resultChan chan *cheshire.Response
	errorChan  chan error
}

func newCheshireConn(protocol cheshire.Protocol, addr string, writeTimeout time.Duration, maxInFlight int) (*cheshireConn, error) {
	conn, err := net.DialTimeout("tcp", addr, time.Second)
	if err != nil {
		return nil, err
	}

	err = protocol.WriteHello(conn)
	if err != nil {
		return nil, err
	}

	nc := &cheshireConn{
		Conn:         conn,
		connected:    1,
		addr:         addr,
		writeTimeout: writeTimeout,
		exitChan:     make(chan int),
		incomingChan: make(chan *cheshire.Response, 25),
		outgoingChan: make(chan *cheshireRequest, 25),

		inflightChan:  make(chan bool, maxInFlight),
		requests:    make(map[string]*cheshireRequest),
		connectedAt: time.Now(),
		protocol: protocol,
		maxInFlight : maxInFlight,
	}
	return nc, nil
}

func (this *cheshireConn) setConnected(v bool) {
	if v {
		atomic.StoreInt32(&this.connected, 1)
	} else {
		atomic.StoreInt32(&this.connected, 0)
	}
}<commit_msg>fix client for dynmap hello<commit_after>package client

import (
	"bufio"
	// "encoding/json"
	"fmt"
	"github.com/trendrr/goshire/cheshire"
	"github.com/trendrr/goshire/dynmap"
	"io"
	"log"
	"net"
	"sync"
	"sync/atomic"
	"time"
)

// A single connection to a cheshire server.
// The connection is considered fail fast
// should be disconnected and reaped

// This is not threadsafe and should only be used in one routine at a time.
type cheshireConn struct {
	net.Conn
	addr         string
	connected    int32
	readTimeout  time.Duration
	writeTimeout time.Duration
	incomingChan chan *cheshire.Response
	outgoingChan chan *cheshireRequest
	exitChan     chan int
	//every new request will push a bool into this chan,
	//it will block once full
	inflightChan chan bool

	//map of txnId to request
	requests     map[string]*cheshireRequest
	requestsLock sync.RWMutex

	connectedAt time.Time
	maxInFlight int
	protocol cheshire.Protocol
}

//wrap a request so we dont lose track of the result channels
type cheshireRequest struct {
	req        *cheshire.Request
	resultChan chan *cheshire.Response
	errorChan  chan error
}

func newCheshireConn(protocol cheshire.Protocol, addr string, writeTimeout time.Duration, maxInFlight int) (*cheshireConn, error) {
	conn, err := net.DialTimeout("tcp", addr, time.Second)
	if err != nil {
		return nil, err
	}

	err = protocol.WriteHello(conn, dynmap.New())
	if err != nil {
		return nil, err
	}

	nc := &cheshireConn{
		Conn:         conn,
		connected:    1,
		addr:         addr,
		writeTimeout: writeTimeout,
		exitChan:     make(chan int),
		incomingChan: make(chan *cheshire.Response, 25),
		outgoingChan: make(chan *cheshireRequest, 25),

		inflightChan:  make(chan bool, maxInFlight),
		requests:    make(map[string]*cheshireRequest),
		connectedAt: time.Now(),
		protocol: protocol,
		maxInFlight : maxInFlight,
	}
	return nc, nil
}

func (this *cheshireConn) setConnected(v bool) {
	if v {
		atomic.StoreInt32(&this.connected, 1)
	} else {
		atomic.StoreInt32(&this.connected, 0)
	}
}
{'fraction_non_alphanumeric': 0.09611097349516969, 'fraction_numerical': 0.006440426058954669, 'mean_word_length': 3.728337236533958, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2316428', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1350, 'n_words': 409}