@@ -68,7 +68,7 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn {
68
68
defer nc .writeMu .unlock ()
69
69
70
70
// Prevents future writes from writing until the deadline is reset.
71
- atomic . StoreInt64 ( & nc .writeExpired , 1 )
71
+ nc .writeExpired . Store ( 1 )
72
72
})
73
73
if ! nc .writeTimer .Stop () {
74
74
<- nc .writeTimer .C
@@ -84,7 +84,7 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn {
84
84
defer nc .readMu .unlock ()
85
85
86
86
// Prevents future reads from reading until the deadline is reset.
87
- atomic . StoreInt64 ( & nc .readExpired , 1 )
87
+ nc .readExpired . Store ( 1 )
88
88
})
89
89
if ! nc .readTimer .Stop () {
90
90
<- nc .readTimer .C
@@ -94,25 +94,22 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn {
94
94
}
95
95
96
96
type netConn struct {
97
- // These must be first to be aligned on 32 bit platforms.
98
- // https://github.com/nhooyr/websocket/pull/438
99
- readExpired int64
100
- writeExpired int64
101
-
102
97
c * Conn
103
98
msgType MessageType
104
99
105
- writeTimer * time.Timer
106
- writeMu * mu
107
- writeCtx context.Context
108
- writeCancel context.CancelFunc
109
-
110
- readTimer * time.Timer
111
- readMu * mu
112
- readCtx context.Context
113
- readCancel context.CancelFunc
114
- readEOFed bool
115
- reader io.Reader
100
+ writeTimer * time.Timer
101
+ writeMu * mu
102
+ writeExpired atomic.Int64
103
+ writeCtx context.Context
104
+ writeCancel context.CancelFunc
105
+
106
+ readTimer * time.Timer
107
+ readMu * mu
108
+ readExpired atomic.Int64
109
+ readCtx context.Context
110
+ readCancel context.CancelFunc
111
+ readEOFed bool
112
+ reader io.Reader
116
113
}
117
114
118
115
var _ net.Conn = & netConn {}
@@ -129,7 +126,7 @@ func (nc *netConn) Write(p []byte) (int, error) {
129
126
nc .writeMu .forceLock ()
130
127
defer nc .writeMu .unlock ()
131
128
132
- if atomic . LoadInt64 ( & nc .writeExpired ) == 1 {
129
+ if nc .writeExpired . Load ( ) == 1 {
133
130
return 0 , fmt .Errorf ("failed to write: %w" , context .DeadlineExceeded )
134
131
}
135
132
@@ -157,7 +154,7 @@ func (nc *netConn) Read(p []byte) (int, error) {
157
154
}
158
155
159
156
func (nc * netConn ) read (p []byte ) (int , error ) {
160
- if atomic . LoadInt64 ( & nc .readExpired ) == 1 {
157
+ if nc .readExpired . Load ( ) == 1 {
161
158
return 0 , fmt .Errorf ("failed to read: %w" , context .DeadlineExceeded )
162
159
}
163
160
@@ -209,7 +206,7 @@ func (nc *netConn) SetDeadline(t time.Time) error {
209
206
}
210
207
211
208
func (nc * netConn ) SetWriteDeadline (t time.Time ) error {
212
- atomic . StoreInt64 ( & nc .writeExpired , 0 )
209
+ nc .writeExpired . Store ( 0 )
213
210
if t .IsZero () {
214
211
nc .writeTimer .Stop ()
215
212
} else {
@@ -223,7 +220,7 @@ func (nc *netConn) SetWriteDeadline(t time.Time) error {
223
220
}
224
221
225
222
func (nc * netConn ) SetReadDeadline (t time.Time ) error {
226
- atomic . StoreInt64 ( & nc .readExpired , 0 )
223
+ nc .readExpired . Store ( 0 )
227
224
if t .IsZero () {
228
225
nc .readTimer .Stop ()
229
226
} else {
0 commit comments