Documentation ¶
Overview ¶
Package inet handles connecting to an irc server and reading and writing to the connection
Index ¶
- type ClientError
- type IrcClient
- func (c *IrcClient) Close() error
- func (c *IrcClient) IsClosed() bool
- func (c *IrcClient) Read(buf []byte) (int, error)
- func (c *IrcClient) ReadChannel() <-chan []byte
- func (c *IrcClient) ReadMessage() ([]byte, bool)
- func (c *IrcClient) SpawnWorkers(pump, siphon bool)
- func (c *IrcClient) Write(buf []byte) (int, error)
- type Queue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientError ¶
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 ¶
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) Read ¶
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 ¶
ReadChannel retrieves the channel that's used to read.
func (*IrcClient) ReadMessage ¶
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 ¶
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.