From 67fb669434e577b94c4dd1f7b31ec6b65215bd3b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 16 Mar 2021 09:17:31 +0100 Subject: [PATCH] Correctly set WebSocket read/write deadline The methods didn't have pointer receivers. Thus the deadline fields were only updated for the local variable. Closes: https://todo.sr.ht/~emersion/soju/106 --- conn.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/conn.go b/conn.go index c14f13e..d02cba2 100644 --- a/conn.go +++ b/conn.go @@ -41,10 +41,10 @@ type websocketIRCConn struct { } func newWebsocketIRCConn(c *websocket.Conn, remoteAddr string) ircConn { - return websocketIRCConn{conn: c, remoteAddr: remoteAddr} + return &websocketIRCConn{conn: c, remoteAddr: remoteAddr} } -func (wic websocketIRCConn) ReadMessage() (*irc.Message, error) { +func (wic *websocketIRCConn) ReadMessage() (*irc.Message, error) { ctx := context.Background() if !wic.readDeadline.IsZero() { var cancel context.CancelFunc @@ -63,7 +63,7 @@ func (wic websocketIRCConn) ReadMessage() (*irc.Message, error) { return irc.ParseMessage(string(b)) } -func (wic websocketIRCConn) WriteMessage(msg *irc.Message) error { +func (wic *websocketIRCConn) WriteMessage(msg *irc.Message) error { b := []byte(strings.ToValidUTF8(msg.String(), string(unicode.ReplacementChar))) ctx := context.Background() if !wic.writeDeadline.IsZero() { @@ -74,25 +74,25 @@ func (wic websocketIRCConn) WriteMessage(msg *irc.Message) error { return wic.conn.Write(ctx, websocket.MessageText, b) } -func (wic websocketIRCConn) Close() error { +func (wic *websocketIRCConn) Close() error { return wic.conn.Close(websocket.StatusNormalClosure, "") } -func (wic websocketIRCConn) SetReadDeadline(t time.Time) error { +func (wic *websocketIRCConn) SetReadDeadline(t time.Time) error { wic.readDeadline = t return nil } -func (wic websocketIRCConn) SetWriteDeadline(t time.Time) error { +func (wic *websocketIRCConn) SetWriteDeadline(t time.Time) error { wic.writeDeadline = t return nil } -func (wic websocketIRCConn) RemoteAddr() net.Addr { +func (wic *websocketIRCConn) RemoteAddr() net.Addr { return websocketAddr(wic.remoteAddr) } -func (wic websocketIRCConn) LocalAddr() net.Addr { +func (wic *websocketIRCConn) LocalAddr() net.Addr { // Behind a reverse HTTP proxy, we don't have access to the real listening // address return websocketAddr("")