@@ -82,32 +82,9 @@ type impl struct {
82
82
receivers []Receiver
83
83
}
84
84
85
- // interfaceWrapper is concrete type that wraps an interface. Necessary because
86
- // atomic.Value needs the same type and can not Store(nil). This indirection
87
- // allows us to store nil.
88
- type interfaceWrapper [T any ] struct {
89
- t T
90
- }
91
- type atomicInterface [T any ] struct {
92
- iface atomic.Value
93
- }
94
-
95
- func (a * atomicInterface [T ]) Load () T {
96
- var v T
97
- x := a .iface .Load ()
98
- if x != nil {
99
- return x .(interfaceWrapper [T ]).t
100
- }
101
- return v
102
- }
103
-
104
- func (a * atomicInterface [T ]) Store (v T ) {
105
- a .iface .Store (interfaceWrapper [T ]{v })
106
- }
107
-
108
85
type streamMessageSender struct {
109
86
to peer.ID
110
- stream atomicInterface [ network.Stream ]
87
+ stream network.Stream
111
88
bsnet * impl
112
89
opts * MessageSenderOpts
113
90
}
@@ -118,7 +95,7 @@ type HasContext interface {
118
95
119
96
// Open a stream to the remote peer
120
97
func (s * streamMessageSender ) Connect (ctx context.Context ) (network.Stream , error ) {
121
- stream := s .stream . Load ()
98
+ stream := s .stream
122
99
if stream != nil {
123
100
return stream , nil
124
101
}
@@ -135,35 +112,35 @@ func (s *streamMessageSender) Connect(ctx context.Context) (network.Stream, erro
135
112
return nil , err
136
113
}
137
114
138
- s .stream . Store ( stream )
115
+ s .stream = stream
139
116
return stream , nil
140
117
}
141
118
142
119
// Reset the stream
143
120
func (s * streamMessageSender ) Reset () error {
144
- stream := s .stream . Load ()
121
+ stream := s .stream
145
122
if stream != nil {
146
123
err := stream .Reset ()
147
- s .stream . Store ( nil )
124
+ s .stream = nil
148
125
return err
149
126
}
150
127
return nil
151
128
}
152
129
153
130
// Close the stream
154
131
func (s * streamMessageSender ) Close () error {
155
- stream := s .stream . Load ()
132
+ stream := s .stream
156
133
if stream != nil {
157
134
err := stream .Close ()
158
- s .stream . Store ( nil )
135
+ s .stream = nil
159
136
return err
160
137
}
161
138
return nil
162
139
}
163
140
164
141
// Indicates whether the peer supports HAVE / DONT_HAVE messages
165
142
func (s * streamMessageSender ) SupportsHave () bool {
166
- stream := s .stream . Load ()
143
+ stream := s .stream
167
144
if stream == nil {
168
145
return false
169
146
}
0 commit comments