Created signalCode and replyCode types

This commit is contained in:
Harry Jeffery 2013-08-24 20:58:38 +01:00
parent b75bb0dacd
commit fd94747c9b
3 changed files with 15 additions and 11 deletions

View File

@ -100,7 +100,7 @@ func (c *Client) disconnect() {
} }
//Send a reply to a user with the code specified //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 { if c.connected == false {
return return
} }
@ -158,8 +158,8 @@ func (c *Client) reply(code int, args ...string) {
} }
func (c *Client) clientThread() { func (c *Client) clientThread() {
readSignalChan := make(chan int, 3) readSignalChan := make(chan signalCode, 3)
writeSignalChan := make(chan int, 3) writeSignalChan := make(chan signalCode, 3)
writeChan := make(chan string, 100) writeChan := make(chan string, 100)
go c.readThread(readSignalChan) 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 { for {
select { select {
case signal := <-signalChan: 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 { for {
select { select {
case signal := <-signalChan: case signal := <-signalChan:

View File

@ -14,7 +14,7 @@ type Server struct {
type Client struct { type Client struct {
server *Server server *Server
connection net.Conn connection net.Conn
signalChan chan int signalChan chan signalCode
outputChan chan string outputChan chan string
nick string nick string
registered bool registered bool
@ -34,12 +34,16 @@ type Channel struct {
clientMap map[string]*Client clientMap map[string]*Client
} }
const ( type signalCode int
signalStop int = iota
)
const ( const (
rplWelcome int = iota signalStop signalCode = iota
)
type replyCode int
const (
rplWelcome replyCode = iota
rplJoin rplJoin
rplPart rplPart
rplTopic rplTopic

View File

@ -32,7 +32,7 @@ func (s *Server) HandleConnection(conn net.Conn) {
client := &Client{server: s, client := &Client{server: s,
connection: conn, connection: conn,
outputChan: make(chan string), outputChan: make(chan string),
signalChan: make(chan int, 3), signalChan: make(chan signalCode, 3),
channelMap: make(map[string]*Channel), channelMap: make(map[string]*Channel),
connected: true} connected: true}