<commit_before>package proxy

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"io"
	"net"
	"runtime"
	"strings"
	"sync"

	"github.com/juju/errors"
	"github.com/ngaut/arena"
	log "github.com/ngaut/logging"
	"github.com/wandoulabs/cm/hack"
	. "github.com/wandoulabs/cm/mysql"
)

var DEFAULT_CAPABILITY uint32 = CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG |
	CLIENT_CONNECT_WITH_DB | CLIENT_PROTOCOL_41 |
	CLIENT_TRANSACTIONS | CLIENT_SECURE_CONNECTION

//client <-> proxy
type Conn struct {
	sync.Mutex
	pkg          *PacketIO
	c            net.Conn
	server       IServer
	capability   uint32
	connectionId uint32
	status       uint16
	collation    CollationId
	charset      string
	user         string
	db           string
	salt         []byte
	closed       bool
	lastInsertId int64
	affectedRows int64
	alloc        arena.ArenaAllocator
	txConns      map[string]*SqlConn
}

func (c *Conn) schema() *Schema {
	return c.server.GetSchema(c.db)
}

func (c *Conn) Handshake() error {
	if err := c.writeInitialHandshake(); err != nil {
		return errors.Trace(err)
	}

	c.flush()

	if err := c.readHandshakeResponse(); err != nil {
		c.writeError(err)
		return errors.Trace(err)
	}

	if err := c.writeOK(nil); err != nil {
		return errors.Trace(err)
	}

	c.pkg.Sequence = 0

	return c.flush()
}

func (c *Conn) Close() error {
	if c.closed {
		return nil
	}

	c.c.Close()
	c.closed = true<commit_msg>clean up when client closed<commit_after>package proxy

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"io"
	"net"
	"runtime"
	"strings"
	"sync"

	"github.com/juju/errors"
	"github.com/ngaut/arena"
	log "github.com/ngaut/logging"
	"github.com/wandoulabs/cm/hack"
	. "github.com/wandoulabs/cm/mysql"
)

var DEFAULT_CAPABILITY uint32 = CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG |
	CLIENT_CONNECT_WITH_DB | CLIENT_PROTOCOL_41 |
	CLIENT_TRANSACTIONS | CLIENT_SECURE_CONNECTION

//client <-> proxy
type Conn struct {
	sync.Mutex
	pkg          *PacketIO
	c            net.Conn
	server       IServer
	capability   uint32
	connectionId uint32
	status       uint16
	collation    CollationId
	charset      string
	user         string
	db           string
	salt         []byte
	closed       bool
	lastInsertId int64
	affectedRows int64
	alloc        arena.ArenaAllocator
	txConns      map[string]*SqlConn
}

func (c *Conn) schema() *Schema {
	return c.server.GetSchema(c.db)
}

func (c *Conn) Handshake() error {
	if err := c.writeInitialHandshake(); err != nil {
		return errors.Trace(err)
	}

	c.flush()

	if err := c.readHandshakeResponse(); err != nil {
		c.writeError(err)
		return errors.Trace(err)
	}

	if err := c.writeOK(nil); err != nil {
		return errors.Trace(err)
	}

	c.pkg.Sequence = 0

	return c.flush()
}

func (c *Conn) Close() error {
	if c.closed {
		return nil
	}

	for _, txConn := range c.txConns {
		txConn.Close()
	}

	c.c.Close()
	c.closed = true
{'fraction_non_alphanumeric': 0.11439633931714185, 'fraction_numerical': 0.010559662090813094, 'mean_word_length': 2.9971870604781996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4174162', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1072, 'n_words': 238}