Last active
August 29, 2015 14:00
-
-
Save jdiez17/11093791 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func(c *Connection) manage() { | |
buffer := make([]byte, 1000) | |
for { | |
select { | |
case out := <-c.outgoing: | |
c.socket.Write(out) | |
default: | |
n, err := c.socket.Read(buffer) | |
if err != nil { | |
panic(err) // do this later | |
} | |
if n > 0 { | |
for _, listener := range c.listeners { | |
// nonblocking send | |
select { | |
case listener <- buffer[:n]: | |
default: | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment