@@ -71,10 +71,10 @@ func TestNewServerConnValidationErrors(t *testing.T) {
71
71
if err == nil {
72
72
t .Fatal ("NewServerConn with invalid public key auth algorithms succeeded" )
73
73
}
74
- if ! c .closed . Load () {
74
+ if ! c .isClosed () {
75
75
t .Fatal ("NewServerConn with invalid public key auth algorithms left connection open" )
76
76
}
77
- if c .used . Load () {
77
+ if c .isUsed () {
78
78
t .Fatal ("NewServerConn with invalid public key auth algorithms used connection" )
79
79
}
80
80
@@ -88,36 +88,44 @@ func TestNewServerConnValidationErrors(t *testing.T) {
88
88
if err == nil {
89
89
t .Fatal ("NewServerConn with unsupported key exchange succeeded" )
90
90
}
91
- if ! c .closed . Load () {
91
+ if ! c .isClosed () {
92
92
t .Fatal ("NewServerConn with unsupported key exchange left connection open" )
93
93
}
94
- if c .used . Load () {
94
+ if c .isUsed () {
95
95
t .Fatal ("NewServerConn with unsupported key exchange used connection" )
96
96
}
97
97
}
98
98
99
99
type markerConn struct {
100
- closed atomic.Bool
101
- used atomic.Bool
100
+ closed uint32
101
+ used uint32
102
+ }
103
+
104
+ func (c * markerConn ) isClosed () bool {
105
+ return atomic .LoadUint32 (& c .closed ) != 0
106
+ }
107
+
108
+ func (c * markerConn ) isUsed () bool {
109
+ return atomic .LoadUint32 (& c .used ) != 0
102
110
}
103
111
104
112
func (c * markerConn ) Close () error {
105
- c .closed . Store ( true )
113
+ atomic . StoreUint32 ( & c .closed , 1 )
106
114
return nil
107
115
}
108
116
109
117
func (c * markerConn ) Read (b []byte ) (n int , err error ) {
110
- c .used . Store ( true )
111
- if c .closed . Load () {
118
+ atomic . StoreUint32 ( & c .used , 1 )
119
+ if atomic . LoadUint32 ( & c .closed ) != 0 {
112
120
return 0 , net .ErrClosed
113
121
} else {
114
122
return 0 , io .EOF
115
123
}
116
124
}
117
125
118
126
func (c * markerConn ) Write (b []byte ) (n int , err error ) {
119
- c .used . Store ( true )
120
- if c .closed . Load () {
127
+ atomic . StoreUint32 ( & c .used , 1 )
128
+ if atomic . LoadUint32 ( & c .closed ) != 0 {
121
129
return 0 , net .ErrClosed
122
130
} else {
123
131
return 0 , io .ErrClosedPipe
0 commit comments