Skip to content

Commit ff63b19

Browse files
committed
Fix unaligned 64 bit atomic loads on 32 bit platforms
Closes #153
1 parent 0e00760 commit ff63b19

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

conn.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ type Conn struct {
7070
activeReader *messageReader
7171
// readFrameLock is acquired to read from bw.
7272
readFrameLock chan struct{}
73-
readClosed int64
73+
// Not int32 because of https://github.com/nhooyr/websocket/issues/153
74+
readClosed int32
7475
readHeaderBuf []byte
7576
controlPayloadBuf []byte
7677

@@ -341,7 +342,7 @@ func (c *Conn) handleControl(ctx context.Context, h header) error {
341342
// See https://github.com/nhooyr/websocket/issues/87#issue-451703332
342343
// Most users should not need this.
343344
func (c *Conn) Reader(ctx context.Context) (MessageType, io.Reader, error) {
344-
if atomic.LoadInt64(&c.readClosed) == 1 {
345+
if atomic.LoadInt32(&c.readClosed) == 1 {
345346
return 0, nil, fmt.Errorf("websocket connection read closed")
346347
}
347348

conn_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (c *netConn) SetReadDeadline(t time.Time) error {
178178
// Use this when you do not want to read data messages from the connection anymore but will
179179
// want to write messages to it.
180180
func (c *Conn) CloseRead(ctx context.Context) context.Context {
181-
atomic.StoreInt64(&c.readClosed, 1)
181+
atomic.StoreInt32(&c.readClosed, 1)
182182

183183
ctx, cancel := context.WithCancel(ctx)
184184
go func() {

websocket_js.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (c *Conn) closeWithInternal() {
8989
// Read attempts to read a message from the connection.
9090
// The maximum time spent waiting is bounded by the context.
9191
func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) {
92-
if atomic.LoadInt64(&c.readClosed) == 1 {
92+
if atomic.LoadInt32(&c.readClosed) == 1 {
9393
return 0, nil, fmt.Errorf("websocket connection read closed")
9494
}
9595

0 commit comments

Comments
 (0)