<commit_before>package libct

import "net"
import "fmt"
import "syscall"
import "sync/atomic"
import prot "code.google.com/p/goprotobuf/proto"

type Session struct {
	sk *net.UnixConn
	resp_map map[uint64]chan *RpcResponse
}

type Container struct {
	s   *Session
	Rid uint64
	pid int32
}

type LibctError struct {
	Code int32
}

func (e LibctError) Error() string {
	return fmt.Sprintf("LibctError: %x", e.Code)
}

func OpenSession() (*Session, error) {
	addr, err := net.ResolveUnixAddr("unixpacket", "/var/run/libct.sock")
	if err != nil {
		return nil, err
	}
	sk, err := net.DialUnix("unixpacket", nil, addr)
	if err != nil {
		return nil, err
	}

	s := &Session{sk, map[uint64]chan *RpcResponse{}}

	// each request has a channel for response. All this channels are
	// collect in a map, where a key value is a request ID.
	go func() {
		for {
			resp, err := s.__recvRes()
			if err != nil {
				return
			}
			s.resp_map[*resp.ReqId] <- resp
			close(s.resp_map[*resp.ReqId])
			delete(s.resp_map, *resp.ReqId)
		}
	}()

	return s, nil
}

var curReqID uint64 = 100;

func getRpcReq() (*RpcRequest) {
	req := &RpcRequest{}
	id := atomic.AddUint64(&curReqID, 1)
	req.ReqId = &id
	return req
}

// Send request to the server<commit_msg>go: handle interrupted connections<commit_after>package libct

import "net"
import "fmt"
import "syscall"
import "sync/atomic"
import prot "code.google.com/p/goprotobuf/proto"

type Session struct {
	sk *net.UnixConn
	resp_map map[uint64]chan *RpcResponse
}

type Container struct {
	s   *Session
	Rid uint64
	pid int32
}

type LibctError struct {
	Code int32
}

func (e LibctError) Error() string {
	return fmt.Sprintf("LibctError: %x", e.Code)
}

func OpenSession() (*Session, error) {
	addr, err := net.ResolveUnixAddr("unixpacket", "/var/run/libct.sock")
	if err != nil {
		return nil, err
	}
	sk, err := net.DialUnix("unixpacket", nil, addr)
	if err != nil {
		return nil, err
	}

	s := &Session{sk, map[uint64]chan *RpcResponse{}}

	// each request has a channel for response. All this channels are
	// collect in a map, where a key value is a request ID.
	go func() {
		for {
			resp, err := s.__recvRes()
			if err != nil {
				for _, c := range(s.resp_map) {
					close(c)
				}
				s.sk.Close()
				return
			}
			s.resp_map[*resp.ReqId] <- resp
			close(s.resp_map[*resp.ReqId])
			delete(s.resp_map, *resp.ReqId)
		}
	}()

	return s, nil
}

var curReqID uint64 = 100;

func getRpcReq() (*RpcRequest) {
	req := &RpcRequest{}
	id := atomic.AddUint64(&curReqID, 1)
	req.ReqId = &id
	return req
}

// Send request to the server
{'fraction_non_alphanumeric': 0.13936335403726707, 'fraction_numerical': 0.013975155279503106, 'mean_word_length': 3.4817391304347827, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2296917', 'n_tokens_mistral': 1070, 'n_tokens_neox': 980, 'n_words': 277}