Some tweaking

This commit is contained in:
Harry Jeffery 2013-08-24 08:36:57 +01:00
parent a2f8d79c75
commit e4261d73b8
3 changed files with 17 additions and 30 deletions

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"log"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -159,8 +158,6 @@ func (c *Client) reply(code int, args ...string) {
} }
func (c *Client) clientThread() { func (c *Client) clientThread() {
defer c.connection.Close()
readSignalChan := make(chan int, 3) readSignalChan := make(chan int, 3)
writeSignalChan := make(chan int, 3) writeSignalChan := make(chan int, 3)
writeChan := make(chan string, 100) writeChan := make(chan string, 100)
@ -175,6 +172,8 @@ func (c *Client) clientThread() {
} }
delete(c.server.clientMap, c.nick) delete(c.server.clientMap, c.nick)
c.connection.Close()
}() }()
for { for {
@ -188,10 +187,9 @@ func (c *Client) clientThread() {
case line := <-c.outputChan: case line := <-c.outputChan:
select { select {
case writeChan <- line: case writeChan <- line:
//It worked continue
default: default:
log.Printf("Dropped a line for client: %q", c.nick) c.disconnect()
//Do nothing, dropping the line
} }
} }
} }

20
main.go
View File

@ -8,17 +8,16 @@ import (
"strings" "strings"
) )
var (
tlsKeyFile = flag.String("tls-key", "tls.key", "The private key file used for TLS")
tlsCertFile = flag.String("tls-cert", "tls.crt", "The certificate file used for TLS")
ircAddress = flag.String("irc-address", ":6697", "The address:port to bind to and listen for clients on")
serverName = flag.String("irc-servername", "rosella", "Server name displayed to clients")
authFile = flag.String("irc-authfile", "", "File containing usernames and passwords of operators.")
)
func main() { func main() {
tlsKeyFile := flag.String("tls-key", "tls.key", "The private key file used for TLS")
tlsCertFile := flag.String("tls-cert", "tls.crt", "The certificate file used for TLS")
ircAddress := flag.String("irc-address", ":6697", "The address:port to bind to and listen for clients on")
serverName := flag.String("irc-servername", "rosella", "Server name displayed to clients")
authFile := flag.String("irc-authfile", "", "File containing usernames and passwords of operators.")
flag.Parse() flag.Parse()
log.Printf("Rosella Initialising.") log.Printf("Rosella Initialising.")
@ -52,7 +51,8 @@ func main() {
} }
} }
} }
server.Run()
go server.Run()
tlsConfig := new(tls.Config) tlsConfig := new(tls.Config)

View File

@ -4,7 +4,6 @@ import (
"crypto/sha1" "crypto/sha1"
"fmt" "fmt"
"io" "io"
"log"
"net" "net"
"regexp" "regexp"
"strings" "strings"
@ -24,19 +23,9 @@ func NewServer() *Server {
} }
func (s *Server) Run() { func (s *Server) Run() {
go func() { for event := range s.eventChan {
for event := range s.eventChan { s.handleEvent(<-s.eventChan)
defer func() { }
if err := recover(); err != nil {
log.Printf("Recovered from panic()")
log.Printf("%s sent %q", event.client.nick, event.input)
log.Println(err)
}
}()
s.handleEvent(<-s.eventChan)
}
}()
} }
func (s *Server) HandleConnection(conn net.Conn) { func (s *Server) HandleConnection(conn net.Conn) {