buffer all channels

This commit is contained in:
Jeremy Latt 2014-02-19 17:47:46 -08:00
parent f090c616b3
commit 95f267ea4f
3 changed files with 18 additions and 4 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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),