From fd94747c9b4c9775debffb0da42bc50f7e5c01c9 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Sat, 24 Aug 2013 20:58:38 +0100 Subject: [PATCH] Created signalCode and replyCode types --- client.go | 10 +++++----- rosella.go | 14 +++++++++----- server.go | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/client.go b/client.go index a9c6059..ac76dd3 100644 --- a/client.go +++ b/client.go @@ -100,7 +100,7 @@ func (c *Client) disconnect() { } //Send a reply to a user with the code specified -func (c *Client) reply(code int, args ...string) { +func (c *Client) reply(code replyCode, args ...string) { if c.connected == false { return } @@ -158,8 +158,8 @@ func (c *Client) reply(code int, args ...string) { } func (c *Client) clientThread() { - readSignalChan := make(chan int, 3) - writeSignalChan := make(chan int, 3) + readSignalChan := make(chan signalCode, 3) + writeSignalChan := make(chan signalCode, 3) writeChan := make(chan string, 100) go c.readThread(readSignalChan) @@ -196,7 +196,7 @@ func (c *Client) clientThread() { } -func (c *Client) readThread(signalChan chan int) { +func (c *Client) readThread(signalChan chan signalCode) { for { select { case signal := <-signalChan: @@ -226,7 +226,7 @@ func (c *Client) readThread(signalChan chan int) { } } -func (c *Client) writeThread(signalChan chan int, outputChan chan string) { +func (c *Client) writeThread(signalChan chan signalCode, outputChan chan string) { for { select { case signal := <-signalChan: diff --git a/rosella.go b/rosella.go index 215f067..1d008e0 100644 --- a/rosella.go +++ b/rosella.go @@ -14,7 +14,7 @@ type Server struct { type Client struct { server *Server connection net.Conn - signalChan chan int + signalChan chan signalCode outputChan chan string nick string registered bool @@ -34,12 +34,16 @@ type Channel struct { clientMap map[string]*Client } -const ( - signalStop int = iota -) +type signalCode int const ( - rplWelcome int = iota + signalStop signalCode = iota +) + +type replyCode int + +const ( + rplWelcome replyCode = iota rplJoin rplPart rplTopic diff --git a/server.go b/server.go index 0da1cf6..9f02b8a 100644 --- a/server.go +++ b/server.go @@ -32,7 +32,7 @@ func (s *Server) HandleConnection(conn net.Conn) { client := &Client{server: s, connection: conn, outputChan: make(chan string), - signalChan: make(chan int, 3), + signalChan: make(chan signalCode, 3), channelMap: make(map[string]*Channel), connected: true}