Skip to content

Commit aa5ed01

Browse files
committed
Improve control message handling documentation
Closes #299
1 parent 7ca4275 commit aa5ed01

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

doc.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,26 @@
8686
// and pong. Call the connection WriteControl, WriteMessage or NextWriter
8787
// methods to send a control message to the peer.
8888
//
89-
// Connections handle received close messages by sending a close message to the
90-
// peer and returning a *CloseError from the the NextReader, ReadMessage or the
91-
// message Read method.
92-
//
93-
// Connections handle received ping and pong messages by invoking callback
94-
// functions set with SetPingHandler and SetPongHandler methods. The callback
95-
// functions are called from the NextReader, ReadMessage and the message Read
96-
// methods.
97-
//
98-
// The default ping handler sends a pong to the peer. The application's reading
99-
// goroutine can block for a short time while the handler writes the pong data
100-
// to the connection.
101-
//
102-
// The application must read the connection to process ping, pong and close
89+
// Connections handle received close messages by calling the handler function
90+
// set with the SetCloseHandler method and by returning a *CloseError from the
91+
// NextReader, ReadMessage or the message Read method. The default close
92+
// handler sends a close message to the peer.
93+
//
94+
// Connections handle received ping messages by calling the handler function
95+
// set with the SetPingHandler method. The default ping handler sends a pong
96+
// message to the peer.
97+
//
98+
// Connections handle received pong messages by calling the handler function
99+
// set with the SetPongHandler method. The default pong handler does nothing.
100+
// If an application sends ping messages, then the application should set a
101+
// pong handler to receive the corresponding pong.
102+
//
103+
// The control message handler functions are called from the NextReader,
104+
// ReadMessage and message reader Read methods. The default close and ping
105+
// handlers can block these methods for a short time when the handler writes to
106+
// the connection.
107+
//
108+
// The application must read the connection to process close, ping and pong
103109
// messages sent from the peer. If the application is not otherwise interested
104110
// in messages from the peer, then the application should start a goroutine to
105111
// read and discard messages from the peer. A simple example is:

0 commit comments

Comments
 (0)