]> Cypherpunks.ru repositories - goircd.git/commitdiff
Make channels unidirectional.
authorThomas Habets <thomas@habets.se>
Sun, 8 Jun 2014 00:21:06 +0000 (02:21 +0200)
committerThomas Habets <thomas@habets.se>
Sun, 8 Jun 2014 00:21:06 +0000 (02:21 +0200)
client.go
daemon.go
events.go
goircd.go
room.go

index f9f79569c621d327269941e669ff3b2598b6f0bd..cc179c8ca1eaadca8796c5d144288ca3d2e0c359 100644 (file)
--- a/client.go
+++ b/client.go
@@ -52,7 +52,7 @@ func NewClient(hostname string, conn net.Conn) *Client {
 // Client processor blockingly reads everything remote client sends,
 // splits messages by CRLF and send them to Daemon gorouting for processing
 // it futher. Also it can signalize that client is unavailable (disconnected).
-func (client *Client) Processor(sink chan ClientEvent) {
+func (client *Client) Processor(sink chan<- ClientEvent) {
        var buf_net []byte
        buf := make([]byte, 0)
        log.Println("New client", client)
index a5b2d77dcd822d257132fe045cee53473bf89757..be9a84e51c33b8ee0e6f6878dceda35bdb7ec1f8 100644 (file)
--- a/daemon.go
+++ b/daemon.go
@@ -46,11 +46,11 @@ type Daemon struct {
        rooms                map[string]*Room
        room_sinks           map[*Room]chan ClientEvent
        last_aliveness_check time.Time
-       log_sink             chan LogEvent
-       state_sink           chan StateEvent
+       log_sink             chan<- LogEvent
+       state_sink           chan<- StateEvent
 }
 
-func NewDaemon(hostname, motd string, log_sink chan LogEvent, state_sink chan StateEvent) *Daemon {
+func NewDaemon(hostname, motd string, log_sink chan<- LogEvent, state_sink chan<- StateEvent) *Daemon {
        daemon := Daemon{hostname: hostname, motd: motd}
        daemon.clients = make(map[*Client]bool)
        daemon.rooms = make(map[string]*Room)
@@ -195,7 +195,7 @@ func (daemon *Daemon) ClientRegister(client *Client, command string, cols []stri
 
 // Register new room in Daemon. Create an object, events sink, save pointers
 // to corresponding daemon's places and start room's processor goroutine.
-func (daemon *Daemon) RoomRegister(name string) (*Room, chan ClientEvent) {
+func (daemon *Daemon) RoomRegister(name string) (*Room, chan<- ClientEvent) {
        room_new := NewRoom(daemon.hostname, name, daemon.log_sink, daemon.state_sink)
        room_sink := make(chan ClientEvent)
        daemon.rooms[name] = room_new
@@ -252,7 +252,7 @@ func (daemon *Daemon) HandlerJoin(client *Client, cmd string) {
        }
 }
 
-func (daemon *Daemon) Processor(events chan ClientEvent) {
+func (daemon *Daemon) Processor(events <-chan ClientEvent) {
        for event := range events {
 
                // Check for clients aliveness
index 6fdf1e79b3318052d319878457459d9ca22ccc55..95760e8a6ceeaf0efe139c5d3e8d295d685c7b13 100644 (file)
--- a/events.go
+++ b/events.go
@@ -60,7 +60,7 @@ type LogEvent struct {
 // Logging events logger itself
 // Each room's events are written to separate file in logdir
 // Events include messages, topic and keys changes, joining and leaving
-func Logger(logdir string, events chan LogEvent) {
+func Logger(logdir string, events <-chan LogEvent) {
        mode := os.O_CREATE | os.O_WRONLY | os.O_APPEND
        perm := os.FileMode(0660)
        var format string
@@ -93,7 +93,7 @@ type StateEvent struct {
 // Room state events saver
 // Room states shows that either topic or key has been changed
 // Each room's state is written to separate file in statedir
-func StateKeeper(statedir string, events chan StateEvent) {
+func StateKeeper(statedir string, events <-chan StateEvent) {
        mode := os.O_CREATE | os.O_TRUNC | os.O_WRONLY
        perm := os.FileMode(0660)
        for event := range events {
index 3d69545e1b633962ab3b95727d2dbd27dfb09b10..aeca83a73a19756058f3490ca7260a145729da44 100644 (file)
--- a/goircd.go
+++ b/goircd.go
@@ -50,8 +50,7 @@ func Run() {
        if *logdir == "" {
                // Dummy logger
                go func() {
-                       for {
-                               <-log_sink
+                       for _ = range log_sink {
                        }
                }()
        } else {
@@ -68,8 +67,7 @@ func Run() {
        if *statedir == "" {
                // Dummy statekeeper
                go func() {
-                       for {
-                               <-state_sink
+                       for _ = range state_sink {
                        }
                }()
        } else {
diff --git a/room.go b/room.go
index 87b35f60b18a69e1f785b4ace86cb693335a252e..08eb46da85a4e0c3149ddc3efc6dbf935ec63521 100644 (file)
--- a/room.go
+++ b/room.go
@@ -41,11 +41,11 @@ type Room struct {
        key        string
        members    map[*Client]bool
        hostname   string
-       log_sink   chan LogEvent
-       state_sink chan StateEvent
+       log_sink   chan<- LogEvent
+       state_sink chan<- StateEvent
 }
 
-func NewRoom(hostname, name string, log_sink chan LogEvent, state_sink chan StateEvent) *Room {
+func NewRoom(hostname, name string, log_sink chan<- LogEvent, state_sink chan<- StateEvent) *Room {
        room := Room{name: name}
        room.members = make(map[*Client]bool)
        room.topic = ""
@@ -78,7 +78,7 @@ func (room *Room) StateSave() {
        room.state_sink <- StateEvent{room.name, room.topic, room.key}
 }
 
-func (room *Room) Processor(events chan ClientEvent) {
+func (room *Room) Processor(events <-chan ClientEvent) {
        var client *Client
        for event := range events {
                client = event.client