<commit_before>// irc descibes the basic client functionalities of irken
package irc

import (
	"bufio"
	"net"
	"time"
)

const DEFAULT_PORT = "6667"

type Conn struct {
	// sockection info
	user string

	// network utils
	io   *bufio.ReadWriter
	sock *net.TCPConn

	// server properties
	pingFreq time.Duration
}

// NewConn takes a remote network address and a default nick.
// It then tries to connect to the supplied address with the
// properties of the supplied session
func NewConn(addr string, nick string) (*Conn, error) {

	//TODO: check if addr already contains another port then the default port.

	addr += ":" + DEFAULT_PORT
	tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
	if err != nil {
		return nil, err
	}
	sock, err := net.DialTCP("tcp", nil, tcpAddr)
	if err != nil {
		return nil, err
	}

	io := bufio.NewReadWriter(bufio.NewReader(sock), bufio.NewWriter(sock))

	return &Conn{nick, io, sock, time.Minute}, nil
}

func (c *Conn) Read() {
	//TODO
}

func (c *Conn) Write() {
	//TODO
}

func (c *Conn) Close() {
	//TODO
}<commit_msg>basic functionality in irc package<commit_after>// irc descibes the basic client functionalities of irken
package irc

import (
	"bufio"
	"net"
	"time"
)

const DEFAULT_PORT = "6667"

type Conn struct {
	// user info
	nick string

	// network utils
	io   *bufio.ReadWriter
	sock *net.TCPConn

	// server properties
	pingFreq time.Duration
}

// NewConn takes a remote network address and a default nick.
// It then tries to connect to the supplied address with the
// properties of the supplied session
func NewConn(addr string, nick string) (*Conn, error) {

	//TODO: check if addr already contains another port then the default port.

	addr += ":" + DEFAULT_PORT
	tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
	if err != nil {
		return nil, err
	}
	sock, err := net.DialTCP("tcp", nil, tcpAddr)
	if err != nil {
		return nil, err
	}

	io := bufio.NewReadWriter(bufio.NewReader(sock), bufio.NewWriter(sock))

	return &Conn{nick, io, sock, time.Minute}, nil
}

// Read attempts to read from the connected server and puts the data into io buffer.
// It will wait until it gets one line of a string.
func (c *Conn) Read() (string, error){
	data, err := c.io.ReadString('\n')
	return data, err
}

// Write attempts to write a string into the io buffer and
// flushes it, sending the data to the connected server
func (c *Conn) Write(s string) error{
	_, err := c.io.WriteString(s + "\r\n")
	if err != nil {
		return err
	}
	err = c.io.Flush()
	if err != nil {
		return err
	}

	return nil
}

// Close attempts to close the connection to the server
func (c *Conn) Close() {
	c.sock.Close()
}
{'fraction_non_alphanumeric': 0.11809235427706283, 'fraction_numerical': 0.003028009084027252, 'mean_word_length': 3.464527027027027, 'pattern_counts': {'":': 2, '<': 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': '4761742', 'n_tokens_mistral': 908, 'n_tokens_neox': 886, 'n_words': 338}