inet

package
v0.0.0-...-27f5e65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 6 Imported by: 2

Documentation

Overview

Package inet handles connecting to an irc server and reading and writing to the connection

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientError

type ClientError struct {
	Socket error
	Pump   error
	Siphon error
}

ClientError is returned from Close() to give the status of all the moving parts within the client.

func (ClientError) CheckNeeded

func (c ClientError) CheckNeeded() (err error)

CheckNeeded allows the ClientError to dissappear into a nil value if all of it's contained errors are nil.

func (ClientError) Error

func (c ClientError) Error() string

Error returns a concatenated error string of all the strings.

type IrcClient

type IrcClient struct {
	// contains filtered or unexported fields
}

IrcClient represents a connection to an irc server. It uses a queueing system to throttle writes to the server. And it implements ReadWriteCloser interface

func NewIrcClient

func NewIrcClient(conn net.Conn, logger log15.Logger, lenPenaltyFactor int,
	timeout, basestep, keepalive, scale time.Duration) *IrcClient

NewIrcClient creates an irc client with optional flood protection and keep alive. scale is used to round the final sleeping values as well as scale the penalties incurred by lenPenaltyFactor, if 0 it is time.Second.

func (*IrcClient) Close

func (c *IrcClient) Close() error

Close closes the socket, sets an all-consuming dequeuer routine to eat all the waiting-to-write goroutines, and then waits to acquire a mutex that will allow it to safely close the writer channel and set a shutdown var.

func (*IrcClient) IsClosed

func (c *IrcClient) IsClosed() bool

IsClosed returns true if the IrcClient has been closed.

func (*IrcClient) Read

func (c *IrcClient) Read(buf []byte) (int, error)

Read implements the io.Reader interface, but this method is just here for convenience. It is not efficient and should probably not even be used. Instead use ReadMessage as it it has already allocated a buffer and copied the contents into it. Using this method requires an extra buffer allocation and extra copying.

func (*IrcClient) ReadChannel

func (c *IrcClient) ReadChannel() <-chan []byte

ReadChannel retrieves the channel that's used to read.

func (*IrcClient) ReadMessage

func (c *IrcClient) ReadMessage() ([]byte, bool)

ReadMessage gets message from the read channel in it's entirety. More efficient than read because read requires you to allocate your own buffer, but since we're dealing in routines and splitting the buffer the reality is another buffer has been already allocated to copy the bytes recieved anyways.

func (*IrcClient) SpawnWorkers

func (c *IrcClient) SpawnWorkers(pump, siphon bool)

SpawnWorkers creates two goroutines, one that is constantly reading using Siphon, and one that is constantly working on eliminating the write queue by writing. Also sets up the instances kill channels.

func (*IrcClient) Write

func (c *IrcClient) Write(buf []byte) (int, error)

Write implements the io.Writer interface and is the preferred way to write to the socket. Returns EOF if the client has been closed. Removes from the buffer all \r\n\0 characters and appends \r\n, then the Pump is signaled through the channel.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue implements a singly-linked queue data structure for byte slices.

func (*Queue) Dequeue

func (q *Queue) Dequeue() []byte

Dequeue dequeues from the front of the queue.

func (*Queue) Enqueue

func (q *Queue) Enqueue(bytes []byte)

Enqueue adds the byte slice to the queue

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL