mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-18 08:26:45 +02:00
37 lines
531 B
Go
37 lines
531 B
Go
package channel
|
|
|
|
import (
|
|
"code.google.com/p/go.net/websocket"
|
|
)
|
|
|
|
type connection struct {
|
|
// The websocket connection.
|
|
ws *websocket.Conn
|
|
|
|
// Buffered channel of outbound messages.
|
|
send chan string
|
|
}
|
|
|
|
func (c *connection) reader() {
|
|
for {
|
|
var message string
|
|
err := websocket.Message.Receive(c.ws, &message)
|
|
if err != nil {
|
|
break
|
|
}
|
|
}
|
|
|
|
c.ws.Close()
|
|
}
|
|
|
|
func (c *connection) writer() {
|
|
for message := range c.send {
|
|
err := websocket.Message.Send(c.ws, message)
|
|
if err != nil {
|
|
break
|
|
}
|
|
}
|
|
|
|
c.ws.Close()
|
|
}
|