From 95f267ea4f72086e5052e5160b77e08af847c754 Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Wed, 19 Feb 2014 17:47:46 -0800 Subject: [PATCH] buffer all channels --- irc/client.go | 15 ++++++++++++++- irc/reply.go | 1 + irc/server.go | 6 +++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/irc/client.go b/irc/client.go index 180e495e..f47c9834 100644 --- a/irc/client.go +++ b/irc/client.go @@ -27,6 +27,7 @@ type Client struct { phase Phase quitTimer *time.Timer realname string + replies chan Reply server *Server socket *Socket username string @@ -43,10 +44,12 @@ func NewClient(server *Server, conn net.Conn) *Client { phase: server.InitPhase(), server: server, socket: NewSocket(conn), + replies: make(chan Reply, 16), } client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout) go client.readCommands() + go client.writeReplies() return client } @@ -82,6 +85,16 @@ func (client *Client) connectionClosed() { client.server.commands <- msg } +// +// reply writing goroutine +// + +func (client *Client) writeReplies() { + for reply := range client.replies { + client.socket.Write(reply.Format(client)...) + } +} + // // idle timer goroutine // @@ -167,7 +180,7 @@ func (client *Client) Destroy() { } func (client *Client) Reply(reply Reply) { - client.socket.Write(reply.Format(client)...) + client.replies <- reply } func (client *Client) IdleTime() time.Duration { diff --git a/irc/reply.go b/irc/reply.go index 3b5456a0..c52cb5d6 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -213,6 +213,7 @@ func RplPart(client *Client, channel *Channel, message string) Reply { return NewStringReply(client, PART, "%s :%s", channel, message) } +// TODO separate source and target func RplMode(client *Client, changes ModeChanges) Reply { return NewStringReply(client, MODE, "%s :%s", client.Nick(), changes) } diff --git a/irc/server.go b/irc/server.go index c99f87cf..9de056a2 100644 --- a/irc/server.go +++ b/irc/server.go @@ -30,10 +30,10 @@ func NewServer(config *Config) *Server { server := &Server{ channels: make(ChannelNameMap), clients: make(ClientNameMap), - commands: make(chan Command), - conns: make(chan net.Conn), + commands: make(chan Command, 16), + conns: make(chan net.Conn, 16), ctime: time.Now(), - idle: make(chan *Client), + idle: make(chan *Client, 16), motdFile: config.MOTD, name: config.Name, operators: make(map[string]string),