MCPcopy
hub / github.com/gotify/server / startWriteHandler

Method startWriteHandler

api/stream/client.go:81–108  ·  view source on GitHub ↗

startWriteHandler starts the write loop. The method has the following tasks: * ping the client in the interval provided as parameter * write messages send by the channel to the client * on errors exit the loop.

(pingPeriod time.Duration)

Source from the content-addressed store, hash-verified

79// * write messages send by the channel to the client
80// * on errors exit the loop.
81func (c *client) startWriteHandler(pingPeriod time.Duration) {
82 pingTicker := time.NewTicker(pingPeriod)
83 defer func() {
84 c.NotifyClose()
85 pingTicker.Stop()
86 }()
87
88 for {
89 select {
90 case message, ok := <-c.write:
91 if !ok {
92 return
93 }
94
95 c.conn.SetWriteDeadline(time.Now().Add(writeWait))
96 if err := writeJSON(c.conn, message); err != nil {
97 printWebSocketError("WriteError", err)
98 return
99 }
100 case <-pingTicker.C:
101 c.conn.SetWriteDeadline(time.Now().Add(writeWait))
102 if err := ping(c.conn); err != nil {
103 printWebSocketError("PingError", err)
104 return
105 }
106 }
107 }
108}
109
110func printWebSocketError(prefix string, err error) {
111 closeError, ok := err.(*websocket.CloseError)

Callers 1

HandleMethod · 0.80

Calls 2

NotifyCloseMethod · 0.95
printWebSocketErrorFunction · 0.85

Tested by

no test coverage detected